Skip to content

Conversation

@benoitmaillard
Copy link
Contributor

@benoitmaillard benoitmaillard commented Nov 13, 2025

This PR addresses yet another missed optimization in PhaseIterGVN. The way this optimization is triggered is a bit different this time though, and the notification is missing in Node::has_special_unique_user.

Analysis

The affected optimization is the transformation of MoveX2Y (LoadX mem) into LoadY mem. This is implemented in MoveNode::Ideal. The optimization is as follows:

// Fold reinterpret cast into memory operation:
//    MoveX2Y (LoadX mem) => LoadY mem
LoadNode* ld = in(1)->isa_Load();
if (ld != nullptr && (ld->outcnt() == 1)) { // replace only
  const Type* rt = bottom_type();
  if (ld->has_reinterpret_variant(rt)) {
    if (phase->C->post_loop_opts_phase()) {
      return ld->convert_to_reinterpret_load(*phase, rt);
    } else {
      // attempt the transformation once loop opts are over
      phase->C->record_for_post_loop_opts_igvn(this);
    }
  }
}

The optimization is triggered only if the input is a LoadNode and the MoveNode is its only user. This is a relatively unusual pattern.

The bug was found by the fuzzer. At some point during IGVN, we have the following subgraph:

CountedLoop    LoadL
          \     /  \
            Phi    MoveL2D

In RegionNode::Ideal, we end up calling set_req_X on the Phi node to delete the edge from the Phi node to LoadL. As a result, the LoadL node only has one user left, and the MoveNode::Ideal gets triggered at the next verification pass.

Proposed Solution

Add this particular case to Node::has_special_unique_user, which gets called by Node::set_req_X.

Summary of changes

This PR brings the following changes:

  • Detect the optimization pattern in Node::has_special_unique_user.
  • Add new test TestMissingOptMoveX2YLoadX.java, initially obtained from the fuzzer and then heavily reduced, both with the usual tools and manually. I tried to get a reproducer for each of the Move nodes, but I was only able to get one for MoveL2D.

Testing

Thank you for reviewing!


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8371674: C2 fails with Missed optimization opportunity in PhaseIterGVN for MoveL2D (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28290/head:pull/28290
$ git checkout pull/28290

Update a local copy of the PR:
$ git checkout pull/28290
$ git pull https://git.openjdk.org/jdk.git pull/28290/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28290

View PR using the GUI difftool:
$ git pr show -t 28290

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28290.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 13, 2025

👋 Welcome back bmaillard! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 13, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title 8371674 8371674: C2 fails with Missed optimization opportunity in PhaseIterGVN for MoveL2D Nov 13, 2025
@openjdk
Copy link

openjdk bot commented Nov 13, 2025

@benoitmaillard The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@benoitmaillard benoitmaillard marked this pull request as ready for review November 13, 2025 13:21
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 13, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 13, 2025

Webrevs

@openjdk openjdk bot added rfr Pull request is ready for review and removed rfr Pull request is ready for review labels Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-compiler [email protected] rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant