RFR: 8297724: Loop strip mining prevents some empty loops from being eliminated [v2]
Tobias Hartmann
thartmann at openjdk.org
Mon Dec 19 06:13:49 UTC 2022
On Fri, 16 Dec 2022 14:07:17 GMT, Roland Westrelin <roland at openjdk.org> wrote:
>> When an empty loop is found, it's removed and as a consequence the
>> outer strip mine loop and the safepoint that it contains are also
>> removed. A counted loop is empty if it has the minimum number of nodes
>> that a well formed counted loop contains. In some cases, the loop has
>> extra nodes and the safepoint in the outer loop is the only node that
>> keeps those extra nodes alive. If the safepoint was to be removed,
>> then the counted loop would have the minimum number of nodes and be
>> considered empty. But the safepoint can't be removed until the loop is
>> considered empty which only happens if it has the minimum of nodes. As
>> a result, these loops are not removed. Note that now that the loop
>> strip mining loop nest is constructed even if UseCountedLoopSafepoints
>> is false, there's a regression where some loops used to be removed as
>> empty before but not anymore.
>>
>> The fix I propose is to extend IdealLoopTree::do_remove_empty_loop()
>> so it handles those cases. If it encounters a loop with no flow
>> control in the loop body but a number of nodes greater than the
>> minimum number of nodes, it starts from the extra nodes in the loop
>> body and follows uses until it finds a side effect, ignoring the
>> safepoint of the outer loop. If it finds none, then the extra nodes
>> can be removed and the loop is empty. This also works if the extra
>> nodes are kept alive by the safepoints of 2 different counted loops
>> and one can only be proven empty if the other one is as well (and the
>> other one proven empty if the first one is) and should work even if
>> there are more than 2 nodes involved..
>
> Roland Westrelin has updated the pull request incrementally with two additional commits since the last revision:
>
> - Update test/hotspot/jtreg/compiler/c2/irTests/TestLSMMissedEmptyLoop.java
>
> Co-authored-by: Tobias Hartmann <tobias.hartmann at oracle.com>
> - Update src/hotspot/share/opto/loopTransform.cpp
>
> Co-authored-by: Tobias Hartmann <tobias.hartmann at oracle.com>
All tests passed.
-------------
Marked as reviewed by thartmann (Reviewer).
PR: https://git.openjdk.org/jdk/pull/11699
More information about the hotspot-compiler-dev
mailing list