Skip to content

Conversation

@benoitmaillard
Copy link
Contributor

@benoitmaillard benoitmaillard commented Oct 20, 2025

This PR addresses a missed optimization opportunity in PhaseIterGVN. The missed optimization is the simplification of redundant conversion patterns of the shape ConvX2Y->ConvY2X->ConvX2Y.

This optimization pattern is implemented as an ideal optimization on ConvX2Y nodes. Because it depends on the input of the input of the node in question, we need to have an appropriate notification mechanism in PhaseIterGVN::add_users_of_use_to_worklist. The notification for this pattern was added in JDK-8359603.

However, that fix was based on the wrong assumption that in PhaseIterGVN::add_users_of_use_to_worklist, argument n is already the optimized node. However in some cases this argument is actually the node that is about to get replaced.

This happens for example in PhaseIterGVN::transform_old. If we find that node k returned by Ideal actually already exists by calling hash_find_insert(k), we call add_users_to_worklist(k).
As we replace node k with i, and i as a different opcode than k, then we cannot use the opcode of k to detect the redundant conversion pattern.

...
  // Global Value Numbering
  i = hash_find_insert(k);      // Check for pre-existing node
  if (i && (i != k)) {
    // Return the pre-existing node if it isn't dead
    NOT_PRODUCT(set_progress();)
    add_users_to_worklist(k);
    subsume_node(k, i);       // Everybody using k now uses i
    return i;
  }
...

The bug was quite intermittent and only showed up in some cases with -XX:+StressIGVN.

Proposed Fix

We make the detection of the pattern less specific by only looking at the opcode of the user of n, and not directly the opcode of n. This is consistent with the detection of other patterns in PhaseIterGVN::add_users_of_use_to_worklist.

Testing

  • GitHub Actions
  • tier1-3, plus some internal testing
  • Added a second run for the existing test with -XX:+StressIGVN and a fixed stress seed

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-8369646: Detection of redundant conversion patterns in add_users_of_use_to_worklist is too restrictive (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27900

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 20, 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 Oct 20, 2025

@benoitmaillard This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8369646: Detection of redundant conversion patterns in add_users_of_use_to_worklist is too restrictive

Reviewed-by: chagedorn, epeter

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 235 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title 8369646 8369646: Test compiler/c2/TestEliminateRedundantConversionSequences.java fails with "Missed optimization opportunity in PhaseIterGVN" Oct 20, 2025
@openjdk
Copy link

openjdk bot commented Oct 20, 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 changed the title 8369646: Test compiler/c2/TestEliminateRedundantConversionSequences.java fails with "Missed optimization opportunity in PhaseIterGVN" 8369646: Detection of redundant conversion patterns in add_users_of_use_to_worklist is too restrictive Oct 20, 2025
@benoitmaillard benoitmaillard marked this pull request as ready for review October 20, 2025 14:18
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 20, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 20, 2025

Webrevs

Copy link
Member

@chhagedorn chhagedorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, looks good, thanks!

* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions
* -XX:CompileCommand=compileonly,compiler.c2.TestEliminateRedundantConversionSequences::test*
* -XX:-TieredCompilation -Xbatch -XX:VerifyIterativeGVN=1110 compiler.c2.TestEliminateRedundantConversionSequences
* -XX:-TieredCompilation -Xbatch -XX:VerifyIterativeGVN=1110
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could either add a separate run with -XX:+StressIGVN without a fixed seed or just add -XX:+StressIGVN here. I guess the latter is good enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, and I just added -XX:+StressIGVN to the existing run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 27, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Oct 27, 2025
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions
* -XX:CompileCommand=compileonly,compiler.c2.TestEliminateRedundantConversionSequences::test*
* -XX:-TieredCompilation -Xbatch -XX:VerifyIterativeGVN=1110 compiler.c2.TestEliminateRedundantConversionSequences
* -XX:-TieredCompilation -Xbatch -XX:VerifyIterativeGVN=1110
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 27, 2025
Copy link
Contributor

@eme64 eme64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me :)

// ConvF2L->ConvL2F->ConvF2L
// ConvI2F->ConvF2I->ConvI2F
// Note: there may be other 3-nodes conversion chains that would require to be added here, but these
// are the only ones that are known to trigger missed optimizations otherwise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to update the description, and give a bit of extra information. Because you are saying n does not have to be a conversion, but it may be that n is about to be replaced with a conversion, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in some cases add_users_of_use_to_worklist is called with the node about to be replaced as argument n. The point is that we might replace n with a node that already has other uses, and we only want to notify the uses for which there is a potential change.
But this is in no way specific to this one optimization, so I think adding something here would cause more confusion than anything else. Perhaps we should update the description of add_users_of_use_to_worklist then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is not specific to this optimization here. Why not add something at the level of add_users_of_use_to_worklist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Development

Successfully merging this pull request may close these issues.

3 participants