[PATCH] D45439: [IRCE] Use NUW flag for indvar

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 6 20:41:26 PDT 2018


mkazantsev added inline comments.


================
Comment at: lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp:894
+  auto HasNoWrap = [&](const SCEVAddRecExpr *AR) {
+    if (AR->hasNoSelfWrap())
       return true;
----------------
mkazantsev wrote:
> samparker wrote:
> > mkazantsev wrote:
> > > mkazantsev wrote:
> > > > This is incorrect. If counter value goes from `-1` to `(SINT_MAX + 1)` (both included), it has both signed and unsigned wrap and has no self-wrap.
> > > Just to clarify the example: we start with `i = -1` and go up with step of `1` and exit the loop when `i = SINT_MAX + 1`. In this case when we pass from `-1` to `0` we are making an unsigned wrap and when we pass from `SINT_MAX` to `SINT_MAX + 1` we are making a signed wrap. There is no self-wrap because this variable will never reach `-1` again.
> > From the SCEV header comments, I understand that NoSelfWrap can be used to query whether either nsw or nuw has been set.
> It is not quite right. If either of `nsw` or `nuw` is set then `nw` is also present automatically. But `nw` can also be present of none of those is set, like in my example of iterations from `-1` to `-2^31 + 1`. It crosses both signed and unsigned range borders but does not cross its initial value `-1`.
I mean, it iterates from -1 to min_int + 1 with step 1, through overflow.


https://reviews.llvm.org/D45439





More information about the llvm-commits mailing list