[PATCH] D70623: [SCEV] Compute trip counts w/frozen conditions

Nuno Lopes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 24 05:06:11 PST 2019


nlopes added a comment.

Interesting question :)

Let's focus on the first example, but with a ule instead:

  %iv.inc = add nsw i32 %iv, 1
  %becond = icmp ule i32 %iv, %n
  %freeze = freeze i1 %becond
  br i1 %freeze, label %loop, label %leave

If %n == UINT_MAX, then icmp is always true. If freeze is not there, eventually %iv.inv becomes poison and then we have UB at the branch. So without freeze we can safely bound the number of iterations by %n. With freeze, the loop potentially never terminates (once the IV becomes poison, frozen cond can be forever true).

With ult we don't have this particular problem of the IV becoming poison. But what if the IV initializer is non-constant and poison in the first place? Then the freeze gives a non-terminating loop again (non-deterministically).
Same goes if %n is poison: we can't bound the number of iterations. You would need to push the freeze to %n. Then it's ok.

Essentially we need to push freezes out of loops. A freeze evaluated in the loop body can give a non-deterministic value in each iteration so we can't rely on it for most (any?) analysis.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70623





More information about the llvm-commits mailing list