From: Simon Pilgrim Date: Fri, 25 Nov 2022 11:05:54 +0000 (+0000) Subject: [X86] combineScalarAndWithMaskSetcc - handle (concat_vectors (and (vYi1 setcc, vYi1... X-Git-Tag: upstream/17.0.6~26563 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6fd0ae39be79bdb686e4cc966e4cdee9950e2645;p=platform%2Fupstream%2Fllvm.git [X86] combineScalarAndWithMaskSetcc - handle (concat_vectors (and (vYi1 setcc, vYi1 x), undef)) patterns If one of the AND operands is a setcc then we're implicitly zeroing the upper mask bits Similar pattern to regressions identified in D127115 (masked comparisons) --- diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 53abc3d..f293058 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -48647,18 +48647,27 @@ static SDValue combineScalarAndWithMaskSetcc(SDNode *N, SelectionDAG &DAG, SDValue SubVec = Src.getOperand(0); EVT SubVecVT = SubVec.getValueType(); - // First subvector should be a setcc with a legal result type. The RHS of the - // AND should be a mask with this many bits. - if (SubVec.getOpcode() != ISD::SETCC || !TLI.isTypeLegal(SubVecVT) || + // The RHS of the AND should be a mask with as many bits as SubVec. + if (!TLI.isTypeLegal(SubVecVT) || !C1->getAPIntValue().isMask(SubVecVT.getVectorNumElements())) return SDValue(); - EVT SetccVT = SubVec.getOperand(0).getValueType(); - if (!TLI.isTypeLegal(SetccVT) || - !(Subtarget.hasVLX() || SetccVT.is512BitVector())) - return SDValue(); - - if (!(Subtarget.hasBWI() || SetccVT.getScalarSizeInBits() >= 32)) + // First subvector should be a setcc with a legal result type or a + // AND containing at least one setcc with a legal result type. + auto IsLegalSetCC = [&](SDValue V) { + if (V.getOpcode() != ISD::SETCC) + return false; + EVT SetccVT = V.getOperand(0).getValueType(); + if (!TLI.isTypeLegal(SetccVT) || + !(Subtarget.hasVLX() || SetccVT.is512BitVector())) + return false; + if (!(Subtarget.hasBWI() || SetccVT.getScalarSizeInBits() >= 32)) + return false; + return true; + }; + if (!(IsLegalSetCC(SubVec) || (SubVec.getOpcode() == ISD::AND && + (IsLegalSetCC(SubVec.getOperand(0)) || + IsLegalSetCC(SubVec.getOperand(1)))))) return SDValue(); // We passed all the checks. Rebuild the concat_vectors with zeroes diff --git a/llvm/test/CodeGen/X86/avx512vl-vec-masked-cmp.ll b/llvm/test/CodeGen/X86/avx512vl-vec-masked-cmp.ll index 5fa144c..42ea007 100644 --- a/llvm/test/CodeGen/X86/avx512vl-vec-masked-cmp.ll +++ b/llvm/test/CodeGen/X86/avx512vl-vec-masked-cmp.ll @@ -1615,8 +1615,7 @@ define i32 @test_masked_vpcmpeqd_v4i1_v32i1_mask_i32(i32 %__u, <2 x i64> %__a, < ; VLX: # %bb.0: # %entry ; VLX-NEXT: kmovd %edi, %k1 ; VLX-NEXT: vpcmpeqd %xmm1, %xmm0, %k0 {%k1} -; VLX-NEXT: kmovd %k0, %eax -; VLX-NEXT: andl $15, %eax +; VLX-NEXT: kmovb %k0, %eax ; VLX-NEXT: retq ; ; NoVLX-LABEL: test_masked_vpcmpeqd_v4i1_v32i1_mask_i32: