Handle overflow of 64-bit loop conditions.
[oota-llvm.git] / lib / Transforms / Scalar / LoopStrengthReduce.cpp
index 4365adc629fcf671dccc48414efe51482750a8e4..23f75630b7658c8f6614693a502fff8a9f4f1e49 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);
+      Mul = Mul * APInt(BitWidth*2, Scale);
       // Check for overflow.
-      if (Mul.getSExtValue() != NewCmpVal)
+      if (!Mul.isSignedIntN(BitWidth))
         continue;
 
       // Watch out for overflow.