When checking for signed multiplication overflow, watch out for INT_MIN and -1.
[oota-llvm.git] / lib / Transforms / Scalar / LoopStrengthReduce.cpp
index 204ce36b8a499a54f63de9d2ab1e912cda5c91ea..73ebd618a0cbe6fb5c8c2c8fa97234382d2ecd58 100644 (file)
@@ -2522,6 +2522,8 @@ void LSRInstance::GenerateICmpZeroScales(LSRUse &LU, unsigned LUIdx,
 
     // Check that multiplying with the unfolded offset doesn't overflow.
     if (F.UnfoldedOffset != 0) {
+      if (F.UnfoldedOffset == INT64_MIN && Factor == -1)
+        continue;
       F.UnfoldedOffset = (uint64_t)F.UnfoldedOffset * Factor;
       if (F.UnfoldedOffset / Factor != Base.UnfoldedOffset)
         continue;