[PATCH] D40168: [IRCE][NFC] Add no wrap flags to no-wrapping SCEV calculation

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 17 00:49:29 PST 2017


mkazantsev created this revision.

In a lambda where we expect to have result within bounds, add respectice `nsw/nuw` flags to
help SCEV just in case if it fails to figure them out on its own.


https://reviews.llvm.org/D40168

Files:
  lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp


Index: lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
===================================================================
--- lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -1667,7 +1667,8 @@
       //   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 @@
       // 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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40168.123301.patch
Type: text/x-patch
Size: 1227 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171117/eca2e20e/attachment.bin>


More information about the llvm-commits mailing list