From 2d43600215098aca3031a7e7fe282a1901fa862f Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 17 May 2016 18:38:55 +0000 Subject: [PATCH] [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. llvm-svn: 269797 --- lib/Transforms/InstCombine/InstCombineCompares.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 447c43763f3..f51cf7321f2 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -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));