[InstCombine] fix constant to be signed for signed comparisons

This bug was introduced in r269728 and is the likely cause of many stage 2 ubsan bot failures.
I'll add a test in a follow-up commit assuming this fixes things properly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269797 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjay Patel 2016-05-17 18:38:55 +00:00
parent 8ae1501586
commit 0353bb1421

View File

@ -3150,7 +3150,7 @@ static ICmpInst *canonicalizeCmpWithConstant(ICmpInst &I) {
// Increment or decrement the constant and set the new comparison predicate:
// ULE -> ULT ; UGE -> UGT ; SLE -> SLT ; SGE -> SGT
Constant *OneOrNegOne = ConstantInt::get(Op1Type, IsLE ? 1 : -1);
Constant *OneOrNegOne = ConstantInt::get(Op1Type, IsLE ? 1 : -1, IsSigned);
CmpInst::Predicate NewPred = IsLE ? ICmpInst::ICMP_ULT: ICmpInst::ICMP_UGT;
NewPred = IsSigned ? ICmpInst::getSignedPredicate(NewPred) : NewPred;
return new ICmpInst(NewPred, Op0, ConstantExpr::getAdd(Op1C, OneOrNegOne));