Skip to content

8361140: Missing OptimizePtrCompare check in ConnectionGraph::reduce_phi_on_cmp #26125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from

Conversation

hgqxjj
Copy link
Member

@hgqxjj hgqxjj commented Jul 4, 2025

When running with -XX:-OptimizePtrCompare (which disables pointer comparison optimization), the compiler may hit an assertion failure in debug builds because optimize_ptr_compare is still being called. This violates the intended usage of the flag and leads to unexpected crashes.

This patch adds an early return to reduce_phi_on_cmp when OptimizePtrCompare is false. Since the optimization relies on optimize_ptr_compare for static reasoning about comparisons, there's no benefit in proceeding with reduce_phi_on_cmp when this flag is disabled.


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-8361140: Missing OptimizePtrCompare check in ConnectionGraph::reduce_phi_on_cmp (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26125

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

Using diff file

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

Using Webrev

Link to Webrev Comment

…phi_on_cmp

When running with `-XX:-OptimizePtrCompare` (which disables pointer comparison optimization), the compiler may hit an assertion failure in debug builds because `optimize_ptr_compare` is still being called. This violates the intended usage of the flag and leads to unexpected crashes.

This patch adds an early return to `reduce_phi_on_cmp` when `OptimizePtrCompare` is false. Since the optimization relies on `optimize_ptr_compare` for static reasoning about comparisons, there's no benefit in proceeding with `reduce_phi_on_cmp` when this support is disabled.
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 4, 2025

👋 Welcome back hgqxjj! 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 Jul 4, 2025

@hgqxjj 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:

8361140: Missing OptimizePtrCompare check in ConnectionGraph::reduce_phi_on_cmp

Reviewed-by: chagedorn, cslucas

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 4 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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@chhagedorn, @JohnTortugo) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 4, 2025
@openjdk
Copy link

openjdk bot commented Jul 4, 2025

@hgqxjj 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.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Jul 4, 2025
@mlbridge
Copy link

mlbridge bot commented Jul 4, 2025

Webrevs

Comment on lines 979 to 981
if (!OptimizePtrCompare) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for working on this! IIUC, having the bailout here will fail to reduce the phi which could be unexpected. Shouldn't we just return UNKNOWN from within ConnectionGraph::optimize_ptr_compare() when we run without OptimizePtrCompare?

On a separate note, can you also add a regression test? Maybe you can also just add a run with -XX:-OptimizePtrCompare - maybe together with -XX:+VerifyReduceAllocationMerges for more verification - to compiler/c2/irTests/scalarReplacement/AllocationMergesTests.java.

@JohnTortugo you might also want to have a look at this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks a lot for your suggestion!
I took a closer look at the code, and I now fully agree that your approach is the better one. Returning UNKNOWN from optimize_ptr_compare() when OptimizePtrCompare is disabled makes the behavior more consistent and avoids skipping reduce_phi_on_cmp() entirely, which could lead to unexpected results or missed optimization opportunities. I appreciate your feedback and will move forward with this approach. Thanks again!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the ping @chhagedorn and I fully agree with your comment. Actually, that's the correct way to do this.
Thank you for fixing this @hgqxjj .

Copy link
Member Author

Choose a reason for hiding this comment

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

hi @chhagedorn , I already update PR and add regression test. Please take another look when you have time .
Thanks a lot.

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.

Thanks for the update! I have some follow-up comments.

@hgqxjj
Copy link
Member Author

hgqxjj commented Jul 10, 2025

hi @chhagedorn ,thanks a lot for your detailed and thoughtful review. I'm still learning more about this area, and your feedback has been a great help. I've updated the PR based on your suggestions . Please feel free to let me know if anything else needs improvement.

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.

Looks good, thanks! I'll give this a spinning in our testing and report back again.

@openjdk
Copy link

openjdk bot commented Jul 11, 2025

⚠️ @hgqxjj the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout 8361140
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 11, 2025
@hgqxjj
Copy link
Member Author

hgqxjj commented Jul 11, 2025

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jul 11, 2025
@openjdk
Copy link

openjdk bot commented Jul 11, 2025

@hgqxjj
Your change (at version 0e9aa95) is now ready to be sponsored by a Committer.

@hgqxjj
Copy link
Member Author

hgqxjj commented Jul 11, 2025

@chhagedorn @JohnTortugo Thanks again for all your feedback. It’s been very helpful! If possible, could you please run /sponsor?

@chhagedorn
Copy link
Member

Testing was clean 👍

/sponsor

@openjdk
Copy link

openjdk bot commented Jul 14, 2025

Going to push as commit 14c79be.
Since your change was applied there have been 21 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 14, 2025
@openjdk openjdk bot closed this Jul 14, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 14, 2025
@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Jul 14, 2025
@openjdk
Copy link

openjdk bot commented Jul 14, 2025

@chhagedorn @hgqxjj Pushed as commit 14c79be.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants