[PATCH] D139692: [IndVars] Use symbolic max block exit count to handle the last iter

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 9 02:19:08 PST 2022


mkazantsev added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1705
     if (SE->isLoopEntryGuardedByCond(L, CmpInst::ICMP_ULT, MaxBECount,
                                      ExactExitCount)) {
       foldExit(L, ExitingBB, false, DeadInsts);
----------------
mkazantsev wrote:
> nikic wrote:
> > As a followup, we should be able to use MaxExitCount here as well.
> Good catch, need to find a test on it.
Thinking more of it, I don't think it's right. Imagine case:
exit 1: exact (unknown) is `2`, symbolic max is `x`
exit 2: exact (unknown) is 0, symbolic max is `x + 1<nuw>`

Loop's symbolic max is `x`.

In this case we cannot eliminate the 2nd exit basing on fact that its maximum is more than some other maximum.

Unilke this, in my patch exit (in given block) earlier than proven max doesn't matter; logic with last iteration is only in the game when loop actually exits on max possible proven iteration (and therefore all subsequent exits don't execute).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139692



More information about the llvm-commits mailing list