]> granicus.if.org Git - llvm/commitdiff
[IRCE][NFC] Add no wrap flags to no-wrapping SCEV calculation
authorMax Kazantsev <max.kazantsev@azul.com>
Thu, 23 Nov 2017 06:14:39 +0000 (06:14 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Thu, 23 Nov 2017 06:14:39 +0000 (06:14 +0000)
In a lambda where we expect to have result within bounds, add respective `nsw/nuw` flags to
help SCEV just in case if it fails to figure them out on its own.

Differential Revision: https://reviews.llvm.org/D40168

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318898 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp

index 6e02e38a28f8c9dbeed08d27e10f52a65519e2a4..5c4d55bfbb2b2db24708e8a5cd2e65f87ee729f7 100644 (file)
@@ -1667,7 +1667,8 @@ InductiveRangeCheck::computeSafeIterationSpace(
       //   Rule 3: Y <s (X - SINT_MAX) ---> (X - SINT_MAX).
       // It gives us smax(Y, X - SINT_MAX) to substract in all cases.
       const SCEV *XMinusSIntMax = SE.getMinusSCEV(X, SIntMax);
-      return SE.getMinusSCEV(X, SE.getSMaxExpr(Y, XMinusSIntMax));
+      return SE.getMinusSCEV(X, SE.getSMaxExpr(Y, XMinusSIntMax),
+                             SCEV::FlagNSW);
     } else
       // X is a number from unsigned range, Y is interpreted as signed.
       // Even if Y is SINT_MIN, (X - Y) does not reach UINT_MAX. So the only
@@ -1679,7 +1680,7 @@ InductiveRangeCheck::computeSafeIterationSpace(
       // If 0 <= X < Y, we should stop at 0 and can only substract X.
       //   Rule 3: Y >s X ---> X.
       // It gives us smin(X, Y) to substract in all cases.
-      return SE.getMinusSCEV(X, SE.getSMinExpr(X, Y));
+      return SE.getMinusSCEV(X, SE.getSMinExpr(X, Y), SCEV::FlagNUW);
   };
   const SCEV *M = SE.getMinusSCEV(C, A);
   const SCEV *Zero = SE.getZero(M->getType());