Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2445,9 +2445,31 @@ /// use this predicate to simplify operations downstream. bool SelectionDAG::MaskedElementsAreZero(SDValue Op, const APInt &DemandedElts, unsigned Depth) const { + APInt DemandedBits; + EVT VT = Op.getValueType(); unsigned BitWidth = Op.getScalarValueSizeInBits(); - APInt DemandedBits = APInt::getAllOnesValue(BitWidth); - return MaskedValueIsZero(Op, DemandedBits, DemandedElts, Depth); + + if (VT.isVector()) { + unsigned NumElts = VT.getVectorNumElements(); + assert(NumElts == DemandedElts.getBitWidth() && "Unexpected vector size"); + DemandedBits = APInt::getNullValue(BitWidth * NumElts); + for (int i = 0; i < NumElts; i++) { + if (!DemandedElts[i]) + continue; + DemandedBits.setBits(BitWidth * i, BitWidth * (i + 1)); + } + } else { + DemandedBits = APInt::getAllOnesValue(BitWidth); + } + + APInt Zero = computeKnownBits(Op, DemandedElts, Depth).Zero; + + if (DemandedBits.getBitWidth() > Zero.getBitWidth()) + Zero = Zero.zext(DemandedBits.getBitWidth()); + else + Zero = Zero.trunc(DemandedBits.getBitWidth()); + + return DemandedBits.isSubsetOf(Zero); } /// MaskedValueIsAllOnes - Return true if '(Op & Mask) == Mask'.