[PATCH] D43610: [SCEV][NFC] Introduce utility functions that measure number of iterations before overflow

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 25 20:45:00 PST 2018


mkazantsev added inline comments.


================
Comment at: lib/Analysis/ScalarEvolution.cpp:6446
+  // within the loop. Make sure that we do not actually overflow.
+  const SCEV *NumIters = getBackedgeTakenCount(L);
+  if (isa<SCEVCouldNotCompute>(NumIters))
----------------
sanjoy wrote:
> I'm not sure this is sound -- the backedge taken count you compute here can itself be dependent on the nuw/nsw flags, i.e. something like (this exact example may not work):
> 
> ```
> i = 300;
> do {
>   guard(i u< 900);
> } while (++i u< 200);
> ```
> 
> In theory the add rec for `i` can be proved nuw based on the guard and that can be used to upper bound the `++i u< 200` trip count to `~0u - 300` since other `i` would have to unsigned overflow.
I gave it some thought on the weekends, and the possibility of such situation also bugs me. Let me think of the alternative solution that doesn't use monotonicity to prove the fact that we have here.


https://reviews.llvm.org/D43610





More information about the llvm-commits mailing list