RFR: 8297724: Loop strip mining prevents some empty loops from being eliminated
Roland Westrelin
roland at openjdk.org
Thu Dec 15 17:59:17 UTC 2022
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..
-------------
Commit messages:
- whitespaces
- test & fix
Changes: https://git.openjdk.org/jdk/pull/11699/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11699&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8297724
Stats: 303 lines in 3 files changed: 295 ins; 4 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/11699.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/11699/head:pull/11699
PR: https://git.openjdk.org/jdk/pull/11699
More information about the hotspot-compiler-dev
mailing list