[X86][SSE] Convert PTEST to MOVMSK for allsign bits vector results
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 27 May 2020 10:05:55 +0000 (11:05 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 27 May 2020 10:06:16 +0000 (11:06 +0100)
commit410667f1b74c614d9382f180d29f5aa1e42cc5c9
tree7c9c3ffaa3134a94741e60c3fc153bd0e798a1c2
parentf2fad3f703aa20cc7b452bdf1605cb46eb960653
[X86][SSE] Convert PTEST to MOVMSK for allsign bits vector results

If we are using PTEST to check 'allsign bits' vector elements we can use MOVMSK to extract the signbits directly and perform the comparison on the scalar value.

For vXi16 cases, as we don't have a MOVMSK for this type, we must mask each signbit out of a PMOVMSKB v2Xi8 result, which folds into the TEST comparison.

If this allows us to remove a vector op (via the SimplifyMultipleUseDemandedBits call) this is consistently faster than a PTEST (https://godbolt.org/z/ziJUst).

I'm investigating whether we ever get regressions without the SimplifyMultipleUseDemandedBits call, even if this means we don't remove a vector op, but that has exposed some other poor codegen issues that I'm still investigating and would have to wait for a later patch.

Suggested on PR42035 to avoid unnecessary ashr(x,bw-1)/pcmpgt(0,x) sign splat patterns feeding into ptest.

Differential Revision: https://reviews.llvm.org/D80563
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/combine-ptest.ll