[PATCH] D108910: [IndVars] Break backedge and replace PHIs if loop exits on 1st iteration

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 12 20:23:17 PDT 2021


mkazantsev added a comment.

In D108910#2986030 <https://reviews.llvm.org/D108910#2986030>, @lebedev.ri wrote:

> I think there are two patches here - `ExitsOnFirstIter`, and `replaceLoopPHINodesWithPreheaderValues()` change.
> I think it may be nice to split the patch into two, with `replaceLoopPHINodesWithPreheaderValues()` being the first one.

Agreed. Dima, please split them up and I'll merge them.

In D108910#2986030 <https://reviews.llvm.org/D108910#2986030>, @lebedev.ri wrote:

> I think there's generality that may be missing here.
> We know which exit exits on the first iteration, which means that all the following exits are not reached.
> But does that tell us anything about the preceding exits?

AFAIK `getExitCount` returns exact exit count for a given block *under assumption that this exit will be taken*. It doesn't account for preceeding checks. In general case, we can do the following opt. Given 2 exits A and B, exact counts known for both, A dominates B and exact exit count of A is strictly greater than those for B. In this case we can remove exit A as never taken. Not sure if IndVars already does it, let me try to wright a simple example...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108910



More information about the llvm-commits mailing list