-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8314997: Missing optimization opportunities due to missing try_clean_mem_phi() calls #15445
Conversation
👋 Welcome back chagedorn! A progress list of the required criteria for merging this PR into |
@chhagedorn The following label will be automatically applied to this pull request:
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. |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me.
@chhagedorn 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:
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 93 new commits pushed to the
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 |
Thanks Roland for your review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Only few small comments.
if (left_path == nullptr || right_path == nullptr) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the TOP input will fail next check. May be add comment about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a comment at the next if
.
src/hotspot/share/opto/cfgnode.cpp
Outdated
if (_type != Type::MEMORY) { | ||
return false; | ||
} | ||
assert(is_diamond_phi(), "sanity"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add explicit check > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, added.
Thanks Vladimir for your review! I've pushed an update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice analysis. The fix looks good to me!
Thanks Roland, Vladimir, and Tobias for your reviews! |
/integrate |
Going to push as commit 2dc930d.
Your commit was automatically rebased without conflicts. |
@chhagedorn Pushed as commit 2dc930d. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
While working on a Valhalla bug, I've noticed that we sometimes miss
RegionNode::try_clean_mem_phi()
calls to remove a useless diamondwith only a single memory phi. This blocks further optimizations like converting a loop into a counted one. The code in Valhalla looks slightly different but the problem is also reproducible in mainline.
Problem
In the test case, a region is transformed in IGVN such that it merges a diamond without any dependencies on both paths. The region has two phis. One of them is a memory phi which could be transformed by
RegionNode::try_clean_mem_phi()
. But when processing the region with its two phis in IGVN, we do not optimize the memory phi away becausehas_unique_phi()
is false and we bail out:jdk/src/hotspot/share/opto/cfgnode.cpp
Lines 450 to 471 in 725ec0c
Later in IGVN, the second phi dies and we only have the single memory phi left. But the region will not be added to the IGVN worklist again to re-apply
try_clean_mem_phi()
. We therefore miss the removal of the diamond and we fail to apply further optimizations. In the test case, we fail to convert the loop into a counted loop.Proposed Fix
The fix I propose is to try to apply
try_clean_mem_phi()
whenever a region is merging a diamond with the assumption that the transformation of a memory phi does not hurt when being applied without being able to remove the region with the diamond (because there are other phis left that cannot be removed). Another option would be to re-add the region to the IGVN worklist when the second last phi dies. But the first approach seems simpler and less invasive.I've also applied some clean-ups and added an IR test.
Thanks,
Christian
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15445/head:pull/15445
$ git checkout pull/15445
Update a local copy of the PR:
$ git checkout pull/15445
$ git pull https://git.openjdk.org/jdk.git pull/15445/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15445
View PR using the GUI difftool:
$ git pr show -t 15445
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15445.diff
Webrev
Link to Webrev Comment