[llvm] 2a13bea - [X86] combineSetCCMOVMSK - don't fold MOVMSK(BITCAST(PCMPEQ(X,0))) -> PTESTZ(X,X) if we're not testing every element comparison
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 28 05:22:48 PST 2022
Author: Simon Pilgrim
Date: 2022-01-28T13:22:37Z
New Revision: 2a13beaa70beb91cc4ce2e804b36f21d0e760172
URL: https://github.com/llvm/llvm-project/commit/2a13beaa70beb91cc4ce2e804b36f21d0e760172
DIFF: https://github.com/llvm/llvm-project/commit/2a13beaa70beb91cc4ce2e804b36f21d0e760172.diff
LOG: [X86] combineSetCCMOVMSK - don't fold MOVMSK(BITCAST(PCMPEQ(X,0))) -> PTESTZ(X,X) if we're not testing every element comparison
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/combine-movmsk.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index ecd3831317f8..99ef69d551c3 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -44524,26 +44524,29 @@ static SDValue combineSetCCMOVMSK(SDValue EFLAGS, X86::CondCode &CC,
if (IsAllOf && Subtarget.hasSSE41()) {
MVT TestVT = VecVT.is128BitVector() ? MVT::v2i64 : MVT::v4i64;
SDValue BC = peekThroughBitcasts(Vec);
- if (BC.getOpcode() == X86ISD::PCMPEQ) {
- SDValue V = DAG.getNode(ISD::SUB, SDLoc(BC), BC.getValueType(),
- BC.getOperand(0), BC.getOperand(1));
- V = DAG.getBitcast(TestVT, V);
- return DAG.getNode(X86ISD::PTEST, SDLoc(EFLAGS), MVT::i32, V, V);
- }
- // Check for 256-bit split vector cases.
- if (BC.getOpcode() == ISD::AND &&
- BC.getOperand(0).getOpcode() == X86ISD::PCMPEQ &&
- BC.getOperand(1).getOpcode() == X86ISD::PCMPEQ) {
- SDValue LHS = BC.getOperand(0);
- SDValue RHS = BC.getOperand(1);
- LHS = DAG.getNode(ISD::SUB, SDLoc(LHS), LHS.getValueType(),
- LHS.getOperand(0), LHS.getOperand(1));
- RHS = DAG.getNode(ISD::SUB, SDLoc(RHS), RHS.getValueType(),
- RHS.getOperand(0), RHS.getOperand(1));
- LHS = DAG.getBitcast(TestVT, LHS);
- RHS = DAG.getBitcast(TestVT, RHS);
- SDValue V = DAG.getNode(ISD::OR, SDLoc(EFLAGS), TestVT, LHS, RHS);
- return DAG.getNode(X86ISD::PTEST, SDLoc(EFLAGS), MVT::i32, V, V);
+ // Ensure MOVMSK was testing every signbit of BC.
+ if (BC.getValueType().getVectorNumElements() <= NumElts) {
+ if (BC.getOpcode() == X86ISD::PCMPEQ) {
+ SDValue V = DAG.getNode(ISD::SUB, SDLoc(BC), BC.getValueType(),
+ BC.getOperand(0), BC.getOperand(1));
+ V = DAG.getBitcast(TestVT, V);
+ return DAG.getNode(X86ISD::PTEST, SDLoc(EFLAGS), MVT::i32, V, V);
+ }
+ // Check for 256-bit split vector cases.
+ if (BC.getOpcode() == ISD::AND &&
+ BC.getOperand(0).getOpcode() == X86ISD::PCMPEQ &&
+ BC.getOperand(1).getOpcode() == X86ISD::PCMPEQ) {
+ SDValue LHS = BC.getOperand(0);
+ SDValue RHS = BC.getOperand(1);
+ LHS = DAG.getNode(ISD::SUB, SDLoc(LHS), LHS.getValueType(),
+ LHS.getOperand(0), LHS.getOperand(1));
+ RHS = DAG.getNode(ISD::SUB, SDLoc(RHS), RHS.getValueType(),
+ RHS.getOperand(0), RHS.getOperand(1));
+ LHS = DAG.getBitcast(TestVT, LHS);
+ RHS = DAG.getBitcast(TestVT, RHS);
+ SDValue V = DAG.getNode(ISD::OR, SDLoc(EFLAGS), TestVT, LHS, RHS);
+ return DAG.getNode(X86ISD::PTEST, SDLoc(EFLAGS), MVT::i32, V, V);
+ }
}
}
@@ -44577,7 +44580,8 @@ static SDValue combineSetCCMOVMSK(SDValue EFLAGS, X86::CondCode &CC,
if (SDValue Src = getSplitVectorSrc(VecOp0, VecOp1, true)) {
SDLoc DL(EFLAGS);
SDValue Result = peekThroughBitcasts(Src);
- if (IsAllOf && Result.getOpcode() == X86ISD::PCMPEQ) {
+ if (IsAllOf && Result.getOpcode() == X86ISD::PCMPEQ &&
+ Result.getValueType().getVectorNumElements() <= NumElts) {
SDValue V = DAG.getNode(ISD::SUB, DL, Result.getValueType(),
Result.getOperand(0), Result.getOperand(1));
V = DAG.getBitcast(MVT::v4i64, V);
diff --git a/llvm/test/CodeGen/X86/combine-movmsk.ll b/llvm/test/CodeGen/X86/combine-movmsk.ll
index 1ef0ea1199f5..cc01fc1506c5 100644
--- a/llvm/test/CodeGen/X86/combine-movmsk.ll
+++ b/llvm/test/CodeGen/X86/combine-movmsk.ll
@@ -307,31 +307,26 @@ define i32 @or_pmovmskb_pmovmskb(<16 x i8> %a0, <8 x i16> %a1) {
ret i32 %7
}
-; TODO: We can't fold to ptest if we're not checking every pcmpeq result
+; We can't fold to ptest if we're not checking every pcmpeq result
define i32 @movmskps_ptest_numelts_mismatch(<16 x i8> %a0) {
-; SSE2-LABEL: movmskps_ptest_numelts_mismatch:
-; SSE2: # %bb.0:
-; SSE2-NEXT: pxor %xmm1, %xmm1
-; SSE2-NEXT: pcmpeqb %xmm0, %xmm1
-; SSE2-NEXT: movmskps %xmm1, %ecx
-; SSE2-NEXT: xorl %eax, %eax
-; SSE2-NEXT: cmpl $15, %ecx
-; SSE2-NEXT: sete %al
-; SSE2-NEXT: negl %eax
-; SSE2-NEXT: retq
-;
-; SSE42-LABEL: movmskps_ptest_numelts_mismatch:
-; SSE42: # %bb.0:
-; SSE42-NEXT: xorl %eax, %eax
-; SSE42-NEXT: ptest %xmm0, %xmm0
-; SSE42-NEXT: sete %al
-; SSE42-NEXT: negl %eax
-; SSE42-NEXT: retq
+; SSE-LABEL: movmskps_ptest_numelts_mismatch:
+; SSE: # %bb.0:
+; SSE-NEXT: pxor %xmm1, %xmm1
+; SSE-NEXT: pcmpeqb %xmm0, %xmm1
+; SSE-NEXT: movmskps %xmm1, %ecx
+; SSE-NEXT: xorl %eax, %eax
+; SSE-NEXT: cmpl $15, %ecx
+; SSE-NEXT: sete %al
+; SSE-NEXT: negl %eax
+; SSE-NEXT: retq
;
; AVX-LABEL: movmskps_ptest_numelts_mismatch:
; AVX: # %bb.0:
+; AVX-NEXT: vpxor %xmm1, %xmm1, %xmm1
+; AVX-NEXT: vpcmpeqb %xmm1, %xmm0, %xmm0
+; AVX-NEXT: vmovmskps %xmm0, %ecx
; AVX-NEXT: xorl %eax, %eax
-; AVX-NEXT: vptest %xmm0, %xmm0
+; AVX-NEXT: cmpl $15, %ecx
; AVX-NEXT: sete %al
; AVX-NEXT: negl %eax
; AVX-NEXT: retq
More information about the llvm-commits
mailing list