Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -279,8 +279,7 @@ Idx = Builder.CreateTrunc(Idx, IntPtrTy); unsigned ElementSize = - DL.getTypeAllocSize(Init->getType()->getArrayElementType()); - + DL.getTypeAllocSize(Init->getType()->getArrayElementType()); // If inbounds keyword is not present, Idx * ElementSize can overflow. // Let's assume that ElementSize is 2 and the wanted value is at offset 0. @@ -290,7 +289,7 @@ // comparison is false if Idx was 0x80..00. // We need to erase the highest countTrailingZeros(ElementSize) bits of Idx. if (countTrailingZeros(ElementSize) != 0) { - Value *Mask = ConstantInt::get(Idx->getType(), -1); + Value *Mask = ConstantInt::getSigned(Idx->getType(), -1); Mask = Builder.CreateLShr(Mask, countTrailingZeros(ElementSize)); Idx = Builder.CreateAnd(Idx, Mask); }