[llvm] r269797 - [InstCombine] fix constant to be signed for signed comparisons

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue May 17 11:38:55 PDT 2016


Author: spatel
Date: Tue May 17 13:38:55 2016
New Revision: 269797

URL: http://llvm.org/viewvc/llvm-project?rev=269797&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=269797&r1=269796&r2=269797&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Tue May 17 13:38:55 2016
@@ -3150,7 +3150,7 @@ static ICmpInst *canonicalizeCmpWithCons
 
   // 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));




More information about the llvm-commits mailing list