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

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 23:38:38 PST 2018


sanjoy 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))
----------------
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.


https://reviews.llvm.org/D43610





More information about the llvm-commits mailing list