Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

chhagedorn
Copy link
Member

@chhagedorn chhagedorn commented Aug 28, 2023

While working on a Valhalla bug, I've noticed that we sometimes miss RegionNode::try_clean_mem_phi() calls to remove a useless diamond

     If
True    False
   Region

with 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 because has_unique_phi() is false and we bail out:

bool RegionNode::try_clean_mem_phi(PhaseGVN *phase) {
// Incremental inlining + PhaseStringOpts sometimes produce:
//
// cmpP with 1 top input
// |
// If
// / \
// IfFalse IfTrue /- Some Node
// \ / / /
// Region / /-MergeMem
// \---Phi
//
//
// It's expected by PhaseStringOpts that the Region goes away and is
// replaced by If's control input but because there's still a Phi,
// the Region stays in the graph. The top input from the cmpP is
// propagated forward and a subgraph that is useful goes away. The
// code below replaces the Phi with the MergeMem so that the Region
// is simplified.
PhiNode* phi = has_unique_phi();
if (phi && phi->type() == Type::MEMORY && req() == 3 && phi->is_diamond_phi(true)) {

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

  • 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-8314997: Missing optimization opportunities due to missing try_clean_mem_phi() calls (Enhancement - P4)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 28, 2023

👋 Welcome back chagedorn! 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.

@chhagedorn chhagedorn changed the title 8314997: Missing optimizations due to missing try_clean_mem_phi() calls 8314997: Missing optimization opportunities due to missing try_clean_mem_phi() calls Aug 28, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 28, 2023
@openjdk
Copy link

openjdk bot commented Aug 28, 2023

@chhagedorn 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 Aug 28, 2023
@mlbridge
Copy link

mlbridge bot commented Aug 28, 2023

Webrevs

Copy link
Contributor

@rwestrel rwestrel left a 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.

@openjdk
Copy link

openjdk bot commented Aug 28, 2023

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

8314997: Missing optimization opportunities due to missing try_clean_mem_phi() calls

Reviewed-by: roland, kvn, thartmann

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 master branch:

  • 764f65c: 8315278: Patch 'print-targets' target to print targets separated by new line
  • 7754ac0: 8314925: ChoiceFormat does not specify IllegalArgumentExceptions
  • 2264667: 8315422: getSoTimeout() would be in try block in SSLSocketImpl
  • d5973bd: 6333341: [BI] Doc: java.text.BreakIterator class specification is unclear
  • 63f561f: 8306882: (fs) Path.toRealPath(LinkOption.NOFOLLOW_LINKS) fails when "../../" follows a link
  • 2436fb0: 8312306: Add more Reference.reachabilityFence() calls to the security classes using Cleaner
  • 351c31e: 8315378: [BACKOUT] runtime/NMT/SummarySanityCheck.java failed with "Total committed (MMMMMM) did not match the summarized committed (NNNNNN)"
  • c12ca88: 8312521: Unused field LocaleProviderAdapter#defaultLocaleProviderAdapter could be removed
  • b38bcae: 8313656: assert(!JvmtiExport::can_support_virtual_threads()) with -XX:-DoJVMTIVirtualThreadTransitions
  • c8acab1: 8315413: Remove special filtering of Continuation.yield0 in StackWalker
  • ... and 83 more: https://git.openjdk.org/jdk/compare/de0e46c2f6dfa817bfa745195573810d250640de...master

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 added the ready Pull request is ready to be integrated label Aug 28, 2023
@chhagedorn
Copy link
Member Author

Thanks Roland for your review!

Copy link
Contributor

@vnkozlov vnkozlov 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. Only few small comments.

Comment on lines +501 to +503
if (left_path == nullptr || right_path == nullptr) {
return false;
}
Copy link
Contributor

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.

Copy link
Member Author

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.

if (_type != Type::MEMORY) {
return false;
}
assert(is_diamond_phi(), "sanity");
Copy link
Contributor

Choose a reason for hiding this comment

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

Add explicit check > 0

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, added.

@chhagedorn
Copy link
Member Author

Thanks Vladimir for your review! I've pushed an update.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Good.

Copy link
Member

@TobiHartmann TobiHartmann left a 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!

@chhagedorn
Copy link
Member Author

Thanks Roland, Vladimir, and Tobias for your reviews!

@chhagedorn
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Sep 4, 2023

Going to push as commit 2dc930d.
Since your change was applied there have been 109 commits pushed to the master branch:

  • ab12c5d: 8315549: CITime misreports code/total nmethod sizes
  • ba8d5c2: 8315582: Exclude compiler/codecache/CodeCacheFullCountTest.java with Xcomp
  • 75d4ac2: 8311775: [TEST] duplicate verifyHeapDump in several tests
  • 4f90aba: 8311585: Add JRadioButtonMenuItem to bug8031573.java
  • 2a11bc4: 8314837: 5 compiled/codecache tests ignore VM flags
  • 2f7c65e: 8303427: Fixpath confused if unix root contains "/jdk"
  • e9e0c56: 8314319: LogCompilation doesn't reset lateInlining when it encounters a failure.
  • 56b8db1: 8258970: Disabled JPasswordField foreground color is wrong with GTK LAF
  • 0d4cadb: 8315195: RISC-V: Update hwprobe query for new extensions
  • b4f7069: 8315446: G1: Remove unused G1AllocRegion::attempt_allocation
  • ... and 99 more: https://git.openjdk.org/jdk/compare/de0e46c2f6dfa817bfa745195573810d250640de...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 4, 2023
@openjdk openjdk bot closed this Sep 4, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 4, 2023
@openjdk
Copy link

openjdk bot commented Sep 4, 2023

@chhagedorn Pushed as commit 2dc930d.

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

4 participants