diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 7d0442b35d436f..8394a69d609e38 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -51660,16 +51660,18 @@ static SDValue combineMOVMSK(SDNode *N, SelectionDAG &DAG, MVT VT = N->getSimpleValueType(0); unsigned NumBits = VT.getScalarSizeInBits(); unsigned NumElts = SrcVT.getVectorNumElements(); + unsigned NumBitsPerElt = SrcVT.getScalarSizeInBits(); + assert(VT == MVT::i32 && NumElts <= NumBits && "Unexpected MOVMSK types"); // Perform constant folding. - if (ISD::isBuildVectorOfConstantSDNodes(Src.getNode())) { - assert(VT == MVT::i32 && "Unexpected result type"); + APInt UndefElts; + SmallVector EltBits; + if (getTargetConstantBitsFromNode(Src, NumBitsPerElt, UndefElts, EltBits)) { APInt Imm(32, 0); - for (unsigned Idx = 0, e = Src.getNumOperands(); Idx < e; ++Idx) { - if (!Src.getOperand(Idx).isUndef() && - Src.getConstantOperandAPInt(Idx).isNegative()) + for (unsigned Idx = 0; Idx != NumElts; ++Idx) + if (!UndefElts[Idx] && EltBits[Idx].isNegative()) Imm.setBit(Idx); - } + return DAG.getConstant(Imm, SDLoc(N), VT); }