[llvm] r318898 - [IRCE][NFC] Add no wrap flags to no-wrapping SCEV calculation

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 22 22:14:40 PST 2017


Author: mkazantsev
Date: Wed Nov 22 22:14:39 2017
New Revision: 318898

URL: http://llvm.org/viewvc/llvm-project?rev=318898&view=rev
Log:
[IRCE][NFC] Add no wrap flags to no-wrapping SCEV calculation

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

Modified:
    llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp?rev=318898&r1=318897&r2=318898&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp Wed Nov 22 22:14:39 2017
@@ -1667,7 +1667,8 @@ InductiveRangeCheck::computeSafeIteratio
       //   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::computeSafeIteratio
       // 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());




More information about the llvm-commits mailing list