[PATCH] D88183: [LoopInfo] Clarify header-loop relationship

Stefanos Baziotis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 13:05:03 PDT 2020


baziotis added a comment.

In D88183#2293384 <https://reviews.llvm.org/D88183#2293384>, @Meinersbur wrote:

> There are different definitions of loops. In the literature, such as a Dragon Book, a loop is identified by a backedge, but LLVM does it with its header. But only natural loops have a header: that is, not all cyclic control flow is represented by LoopInfo. Cyclic control flow that is is not form a natural loop is called irreducible control flow.
>
> Anyway, using SCCs to stand for loops is bad as well since it ignores subloops. It should be a induced subgraph, not component. I think I raised this in the first review, but it was committed anyway. I'd be grateful if this could be cleaned up.

I agree in all that. Actually, this patch started when I was reading Muchnick's book <https://www.amazon.com/Advanced-Compiler-Design-Implementation-Muchnick/dp/1558603204>. It has a great paragraph on reducibility and this is where my example came from. Muchnick defines
a natural loop by a backedge, but it depends on how we define that: It's when the head of an edge dominates its tail. With this definition (AFAIU), a natural loop is always reducible (only one way to enter),
but multiple natural loops can have the same header. And then the book says "if that happens, it's a matter of convention then and our convention is to consider all of them one big loop".

So, then I was curious what LLVM does: LLVM's definition of a natural loop makes it clear that in such a scenario, the loops should be considered as one big natural loop since the header dominates all the latches (and intermediate blocks).
That's also what seems to happen in the code and when I ran a couple of examples in godbolt (like the one above). But the doc at this part did not agree with this.

> Would you be ok if I made another patch trying to fix all these things?

Yes of course. TBH though, although I thank you for this comment, I didn't understand if I was wrong / correct, the doc was wrong / correct or any combination of those :) It would help if you clarified, as I'm trying to understand more about loops.


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

https://reviews.llvm.org/D88183



More information about the llvm-commits mailing list