[PATCH] D102982: [LoopUnroll] Use smallest exact trip count from any exit

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 26 09:27:28 PDT 2021


reames added a comment.

@nikic We're talking past each other here.

Let me work up from definitions.  I think this will make my point easier to follow.

An exact exit count for an loop exit is the iteration on which that loop exit *must* be taken.  We know that no previous iteration can exit via that exit.  A maximum exit count is any upper bound on an exact exit count.  The only requirement is that it be a valid upper bound.  In practice, we only consider constant upper bounds, but that's an implementation detail.  See getExitCount(BB) and computeExitLimit for details.  Note that we only compute exit counts for exits which dominate latch as we don't want to have to reason about exits being skipped on the potentially exiting iteration.

An exit count for a loop (either exact or max) is simply a umin of all the exit counts which dominate the latch.  See getBackedgeTakenCount and computeBackedgeTakenCount.

A trip count is simply an exit (e.g. backedge taken) count plus one.  The value 0 is used for "don't know".  (We really should have used an option there instead, because the resulting code is confusing.)

A "small" exit count is simply one which evaluates to a small constant.  A valid implementation of any of the "small constant trip count" methods is to compute the exact symbolic exit count, dyn_cast to a constant, and add one.

For historical reasons, the small constant trip count routines have never been updated to do that.  Instead, they're still specialized for the case of a single exiting block.  However, that simply means they produce "don't know" more than required.

My whole point has been - aside from the need to know which exit has the smallest trip count - that you could simply use the generic implementation which works for multiple exit loops.  There's no need for SCEV to continue to use the form restricted to single exit loops.


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

https://reviews.llvm.org/D102982



More information about the llvm-commits mailing list