RFR: 8280126: C2: detect and remove dead irreducible loops [v2]

Emanuel Peter epeter at openjdk.org
Thu Jan 12 09:02:20 UTC 2023


On Wed, 11 Jan 2023 17:41:00 GMT, Vladimir Kozlov <kvn at openjdk.org> wrote:

>> src/hotspot/share/ci/ciTypeFlow.cpp line 1867:
>> 
>>> 1865:   // Head of infinite loop, no parent was attached because no exit found
>>> 1866:   // Since this infinite loop does not exit into another loop, it is not
>>> 1867:   // nested in any loop, hence also not in an irreducible loop.
>> 
>> Do we need `_infinite_loop_head` for easy check here?
>
> Also even if it do not have exit it may have entry from irreducible loop. I don't understand your statement that "it is not nested".

I guess we could use the two fields available directly to the block:
`_infinite_loop_head` and `_irreducible_loop_secondary_entry`.
I wonder if that is really worth it, when probably in most cases those flags are not set anyway?
Now we just have this happen:
`block->loop()->is_irreducible()`, which goes:
`Block::_loop -> Loop::_irreducible`

About `infinite loop`: I can improve the comment like this:

We have "lp->parent() == nullptr", which happens only for infinite loops, where no parent is attached to the loop.
We did not find any irreducible loop from this block out to lp.
Thus lp only has one entry, and no exit (it is infinite and reducible).
We can always rewrite an infinite loop that is nested inside other loops:
while(condition) { infinite_loop; }
with an equivalent program where the infinite loop is an outermost loop that is not nested in any loop:
while(condition) { break; } infinite_loop;
Thus, we can understand lp as an outermost loop, and can terminate and conclude:
this block is in no irreducible loop.

Would that be more helpful?

-------------

PR: https://git.openjdk.org/jdk/pull/11764


More information about the hotspot-compiler-dev mailing list