Make sure to use signed arithmetic in APInt to fix a regression.
authorDavid Greene <greened@obbligato.org>
Wed, 6 May 2009 17:39:26 +0000 (17:39 +0000)
committerDavid Greene <greened@obbligato.org>
Wed, 6 May 2009 17:39:26 +0000 (17:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71090 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopStrengthReduce.cpp

index e2cbbc2d27052ed3cc4395eff196eba9d45b9353..9e6f2b02bc8cbd8842886d83bf3dbd5fa7ff13cc 100644 (file)
@@ -2027,9 +2027,10 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
 
       Scale = SSInt / CmpSSInt;
       int64_t NewCmpVal = CmpVal * Scale;
-      APInt Mul = APInt(BitWidth, NewCmpVal);
+      APInt Mul = APInt(BitWidth*2, CmpVal, true);
+      Mul = Mul * APInt(BitWidth*2, Scale, true);
       // Check for overflow.
-      if (Mul.getSExtValue() != NewCmpVal)
+      if (!Mul.isSignedIntN(BitWidth)) {
         continue;
 
       // Watch out for overflow.