[PATCH] D74691: [Attributor] add some pattern to containsCycle

Stefanos Baziotis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 17 03:41:44 PST 2020


baziotis added a comment.

In D74691#1878483 <https://reviews.llvm.org/D74691#1878483>, @jdoerfert wrote:

> In D74691#1878472 <https://reviews.llvm.org/D74691#1878472>, @baziotis wrote:
>
> > In D74691#1878465 <https://reviews.llvm.org/D74691#1878465>, @jdoerfert wrote:
> >
> > > In D74691#1878449 <https://reviews.llvm.org/D74691#1878449>, @baziotis wrote:
> > >
> > > > Edit: Alternatively, we could loop through the SCCs and check if any of them is not a loop but I didn't find an easy way to do that.
> > >
> > >
> > > @omarahmed I think @baziotis has a really good point here. Let's do it this way :)
> >
> >
> > :)
> >  Here's something I hadn't thought when I wrote it. But before that, @omarahmed be sure to check the loop terminology (https://llvm.org/docs/LoopTerminology.html) and pay extra attention to the dominance ('cause you mind another way using it). And that not every SCC is a loop.
> >  Now, I hope that what I'll say below is correct. I'm not a loop guru, so take it with a grain of salt.
> >  To check if an SCC //is// a loop, take a random BB (e.g. the first) in the SCC and check if it's in a loop (as you did, with `getLoopFor()`). Then, compare the size (that is, the number of blocks) of the SCC (`.size()`) with the size of the loop (`.getNumBlocks()` IIRC). 3 cases:
> >
> > - They're equal: This SCC is a loop, continue to the next.
> > - The loop is bigger: The SCC is not a loop, return.
> > - The loop is smaller: Unfortunately, that is tricky. If the loop is smaller, we can't deduce that the SCC is not a loop because `getLoopFor()` gives you the //innermost// loop. Consider that the SCC has the blocks: A, B, C. The blocks A,B might make a loop. But the blocks A, B, C might also make a loop (I don't know if that can happen with 2 vs 3 blocks but you get the point). If the random node you picked happens to be A, then `getLoopFor()` will give you the A, B loop back. **But**, note that A, B is a //child loop// of A, B, C. How that could help us? :)
>
>
> In the last case you do `L = L->getParentLoop()` and go back as if this was the return of getLoopFor().


Yep.

> P.S. 2 vs 3 blocks can happen, since you have single block loops.

Right, also 2 latches I guess.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74691





More information about the llvm-commits mailing list