@@ -26,20 +26,21 @@ using namespace llvm;
2626
2727// / Return a constant boolean vector that has true elements in all positions
2828// / where the input constant data vector has an element with the sign bit set.
29- static Constant *getNegativeIsTrueBoolVec (Constant *V) {
29+ static Constant *getNegativeIsTrueBoolVec (Constant *V, const DataLayout &DL ) {
3030 VectorType *IntTy = VectorType::getInteger (cast<VectorType>(V->getType ()));
3131 V = ConstantExpr::getBitCast (V, IntTy);
32- V = ConstantExpr::getICmp (CmpInst::ICMP_SGT, Constant::getNullValue (IntTy),
33- V);
32+ V = ConstantFoldCompareInstOperands (CmpInst::ICMP_SGT,
33+ Constant::getNullValue (IntTy), V, DL);
34+ assert (V && " Vector must be foldable" );
3435 return V;
3536}
3637
3738// / Convert the x86 XMM integer vector mask to a vector of bools based on
3839// / each element's most significant bit (the sign bit).
39- static Value *getBoolVecFromMask (Value *Mask) {
40+ static Value *getBoolVecFromMask (Value *Mask, const DataLayout &DL ) {
4041 // Fold Constant Mask.
4142 if (auto *ConstantMask = dyn_cast<ConstantDataVector>(Mask))
42- return getNegativeIsTrueBoolVec (ConstantMask);
43+ return getNegativeIsTrueBoolVec (ConstantMask, DL );
4344
4445 // Mask was extended from a boolean vector.
4546 Value *ExtMask;
@@ -65,7 +66,7 @@ static Instruction *simplifyX86MaskedLoad(IntrinsicInst &II, InstCombiner &IC) {
6566
6667 // The mask is constant or extended from a bool vector. Convert this x86
6768 // intrinsic to the LLVM intrinsic to allow target-independent optimizations.
68- if (Value *BoolMask = getBoolVecFromMask (Mask)) {
69+ if (Value *BoolMask = getBoolVecFromMask (Mask, IC. getDataLayout () )) {
6970 // First, cast the x86 intrinsic scalar pointer to a vector pointer to match
7071 // the LLVM intrinsic definition for the pointer argument.
7172 unsigned AddrSpace = cast<PointerType>(Ptr->getType ())->getAddressSpace ();
@@ -102,7 +103,7 @@ static bool simplifyX86MaskedStore(IntrinsicInst &II, InstCombiner &IC) {
102103
103104 // The mask is constant or extended from a bool vector. Convert this x86
104105 // intrinsic to the LLVM intrinsic to allow target-independent optimizations.
105- if (Value *BoolMask = getBoolVecFromMask (Mask)) {
106+ if (Value *BoolMask = getBoolVecFromMask (Mask, IC. getDataLayout () )) {
106107 unsigned AddrSpace = cast<PointerType>(Ptr->getType ())->getAddressSpace ();
107108 PointerType *VecPtrTy = PointerType::get (Vec->getType (), AddrSpace);
108109 Value *PtrCast = IC.Builder .CreateBitCast (Ptr, VecPtrTy, " castvec" );
@@ -2688,7 +2689,8 @@ X86TTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
26882689
26892690 // Constant Mask - select 1st/2nd argument lane based on top bit of mask.
26902691 if (auto *ConstantMask = dyn_cast<ConstantDataVector>(Mask)) {
2691- Constant *NewSelector = getNegativeIsTrueBoolVec (ConstantMask);
2692+ Constant *NewSelector =
2693+ getNegativeIsTrueBoolVec (ConstantMask, IC.getDataLayout ());
26922694 return SelectInst::Create (NewSelector, Op1, Op0, " blendv" );
26932695 }
26942696
0 commit comments