RFR: 8297724: Loop strip mining prevents some empty loops from being eliminated [v2]
Roland Westrelin
roland at openjdk.org
Fri Dec 16 14:07: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..
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>
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/11699/files
- new: https://git.openjdk.org/jdk/pull/11699/files/76fd3598..abcf9883
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=11699&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=11699&range=00-01
Stats: 2 lines in 2 files changed: 1 ins; 0 del; 1 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