[X86] combineSetCCMOVMSK - don't fold MOVMSK(BITCAST(PCMPEQ(X,0))) -> PTESTZ(X,X) if we're not testing every element comparison

This commit is contained in:
Simon Pilgrim 2022-01-28 13:22:25 +00:00
parent 835a737887
commit 2a13beaa70
2 changed files with 40 additions and 41 deletions

View File

@ -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);

View File

@ -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