RFR: 8252372: Check if cloning is required to move loads out of loops in PhaseIdealLoop::split_if_with_blocks_post()

Roland Westrelin roland at openjdk.java.net
Mon Apr 26 09:53:50 UTC 2021

Sinking data nodes out of a loop when all uses are out of a loop has
several issues that this attempts to fix.

1- Only non control uses are considered which makes little sense (why
  not sink if the data node is an argument to a call or a returned

2- Sinking of Loads is broken because of the handling of
  anti-dependence: the get_late_ctrl(n, n_ctrl) call returns a control
  in the loop because it takes all uses into account.

3- For data nodes for which a control edge can't be set, commoning of
  clones back in the loop is prevented with:
  which gives no guarantee

This patch tries to address all issues:

1- it looks at all uses, not only non control uses

2- anti-dependences are computed for each use independently

3- Cast nodes are used to pin clones out of loop

2- requires refactoring of the PhaseIdealLoop::get_late_ctrl()
logic. While working on this, I noticed a bug in anti-dependence
analysis: when the use is a cfg node, the code sometimes looks at uses
of the memory state of the cfg. The logic uses the use of the cfg
which is a projection of adr_type identical to the cfg. It should
instead look at the use of the memory projection.

The existing logic for sinking loads calls clear_dom_lca_tags() for
every load which seems like quite a waste. I added a
_dom_lca_tags_round variable that's or'ed with the tag_node's _idx. By
incrementing _dom_lca_tags_round, new tags that don't conflict with
existing ones are produced and there's no need for

For anti-dependence analysis to return a correct result, early control
of the load is needed. The only way to get it at this stage, AFAICT,
is to compute it by following the load's input until a pinned node is

The existing logic pins cloned nodes next to their use. The logic I
propose pins them right out of the loop. This could possibly avoid
some redundant clones. It also makes some special handling for corner
cases with loop strip mining useless.

For 3-, I added extra Cast nodes for float types. If a chain of data
nodes are sunk, the new logic tries to keep a single Cast for the
entire chain rather than one Cast per node.


Commit messages:
 - extra comments
 - fix

Changes: https://git.openjdk.java.net/jdk/pull/3689/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=3689&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8252372
  Stats: 494 lines in 12 files changed: 286 ins; 76 del; 132 mod
  Patch: https://git.openjdk.java.net/jdk/pull/3689.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/3689/head:pull/3689

PR: https://git.openjdk.java.net/jdk/pull/3689

More information about the hotspot-compiler-dev mailing list