[PATCH] D145510: [SCEV] Fix finite loop non-strict predicate simplification (PR60944)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 13 01:02:24 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:9172
+      break;
+    RHS = getAddExpr(getOne(RHS->getType()), RHS);
+    [[fallthrough]];
----------------
mkazantsev wrote:
> StephenFan wrote:
> > mkazantsev wrote:
> > > Can this overflow?
> > Yes, it can. Although it can't overflow in loop `L`, it still may overflow somewhere out of the loop. See test file `pr60944.ll` below.
> > In `loop2`, `%iv + 1` can not overflow as a result of `mustprogress` attribute, but `%iv + 1` can still overflow in `loop`.
> I don't quite get the logic here. Imagine that the loops has two exits, one exit is `iv <= MAX_INT` (so it is never taken) and another exit is guaranteed to exit in 100 iterations (so the loop is finite). Then you just turn this first exit condition into `iv < MIN_INT` which is trivially false and immediately exit on the 1st iteration. To me it doesn't matter if the loop is finite or not, you cannot add one here.
`ControllingFiniteLoop` is `ControlsExit && loopHasNoAbnormalExits(L) && loopIsFiniteByAssumption(L)`. This means that the lopo is finite *and* only has one exit.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145510/new/

https://reviews.llvm.org/D145510



More information about the llvm-commits mailing list