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
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/hotspot/share/opto/escape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,9 @@ void ConnectionGraph::reduce_phi_on_castpp_field_load(Node* curr_castpp, Growabl
//
//
void ConnectionGraph::reduce_phi_on_cmp(Node* cmp) {
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.

Node* ophi = cmp->in(1)->is_Con() ? cmp->in(2) : cmp->in(1);
assert(ophi->is_Phi(), "Expected this to be a Phi node.");

Expand Down