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

8317723: C2: CountedLoopEndNodes and Zero Trip Guards are wrongly treated as Runtime Predicate #16596

Closed
wants to merge 2 commits into from

Conversation

chhagedorn
Copy link
Member

@chhagedorn chhagedorn commented Nov 10, 2023

In testCountedLoopEndAsRuntimePredicate(), a CountedLoopEndNode is wrongly treated as Runtime Predicate and added to a Predicate Block. This happens because a predicate trap ends up at one of the projections of the CountedLoopEndNode due to folding some other nodes:

image

The verification code then reports this failure when trying to find all predicates above 530 CountedLoop. I've fixed RuntimePredicate::is_success_proj() to only treat an IfNode or a RangeCheckNode as Runtime Predicate.

We could also end up treating a zero trip guard If node with an OpaqueZeroTripGuardNode as Runtime Predicate (see testZeroTripGuardAsRuntimePredicate()):

image

This could also potentially lead to problems. I've improved RuntimePredicate::is_success_proj() to additionally exclude zero trip guard checks. I've strengthened the verification code accordingly such that it would have failed with testZeroTripGuardAsRuntimePredicate().

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-8317723: C2: CountedLoopEndNodes and Zero Trip Guards are wrongly treated as Runtime Predicate (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16596

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

Using diff file

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

Webrev

Link to Webrev Comment

@chhagedorn chhagedorn changed the title 8317723: C2: CountedLoopEndNodes are wrongly treated as Runtime Predicate 8317723: C2: CountedLoopEndNodes and Zero Trip Guards are wrongly treated as Runtime Predicate Nov 10, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Nov 10, 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.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 10, 2023
@openjdk
Copy link

openjdk bot commented Nov 10, 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 Nov 10, 2023
@mlbridge
Copy link

mlbridge bot commented Nov 10, 2023

Webrevs

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.

Looks good to me otherwise.

return false;
}

bool RuntimePredicate::is_not_zero_trip_guard(const IfProjNode* if_proj) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's worth adding a new method for this, especially since we should prefer negation of the result in the caller instead of using negation in method/variable names.

@openjdk
Copy link

openjdk bot commented Nov 13, 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:

8317723: C2: CountedLoopEndNodes and Zero Trip Guards are wrongly treated as Runtime Predicate

Reviewed-by: thartmann, 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 121 new commits pushed to the master branch:

  • 77a6966: 8320053: GHA: Cross-compile gtest code
  • 4f4d00f: 8319966: AIX: expected [[0:i4]] but found [[0:I4]] after JDK-8319882
  • 2e34a2e: 8318671: Potential uninitialized uintx value after JDK-8317683
  • fac6b51: 8319781: RISC-V: Refactor UseRVV related checks
  • bad6999: 8313672: C2: PhaseCCP does not correctly track analysis dependencies involving shift, convert, and mask
  • fbe1937: 8319955: Improve dependencies removal during class unloading
  • 4c1540b: 8287284: C2: loop optimization performs split_thru_phi infinitely many times
  • 70f0c01: 8320054: Remove unused _count from NMT walker classes
  • e7486e8: 8315986: [macos14] javax/swing/JMenuItem/4654927/bug4654927.java: component must be showing on the screen to determine its location
  • a6343c0: 8319999: Refactor MetaspaceShared::use_full_module_graph()
  • ... and 111 more: https://git.openjdk.org/jdk/compare/8fb94fd4fe46bc12885c7cc0c7ebbbc10fba47e5...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 Nov 13, 2023
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.

The solution looks reasonable.

But I wonder if there could not be a scenario, where we have some "normal" if (i.e. a condition stated by the user in java code), which has a loop on both sides of the condition. If now one side collapses to a bare uncommon trap, this if would look like a runtime predicate, right? Is this impossible? If not, we may need a more fundamental solution. Maybe some new (sub)class of node, or a flag in the If node.

@chhagedorn
Copy link
Member Author

chhagedorn commented Nov 15, 2023

The solution looks reasonable.

But I wonder if there could not be a scenario, where we have some "normal" if (i.e. a condition stated by the user in java code), which has a loop on both sides of the condition. If now one side collapses to a bare uncommon trap, this if would look like a runtime predicate, right? Is this impossible? If not, we may need a more fundamental solution. Maybe some new (sub)class of node, or a flag in the If node.

I've initially thought about marking Runtime Predicates with a flag or something like that. However, when one gets replaced by another node, we need to check if the new node should also be marked as a Runtime Predicate. I'm not sure how easy this is to get it right in all the cases. But doing this marking is probably not worth doing, because I think that, in theory, it is okay to treat normal If and RangeCheck nodes as Runtime Predicate even though they initially started out as non-predicates and only became one later due to folding one path to an uncommon trap path. It would even fit the definition of a Runtime Predicate: Check something and if it fails trap (with either Deoptimization::Reason_predicate, Reason_profile_predicate, or Reason_loop_limit_check).

With CountedLoopEndNodes we kinda have the free information that this node has not started out as a Runtime Predicate. So, stopping here always seems right.

There is also code that wants to find the zero trip guard check from a loop head. Wrongly treating a zero trip guard as Runtime Predicate and skipping over it could possibly become a problem (e.g. code that asserts that we must have a zero trip guard could fail etc.). However, I have not found a case where we currently crash (without the new code in this patch to stop at zero trip guards).

I therefore think updating the code to exclude these two cases is fine and enough for our purposes. What do you think?

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.

Ok, I understand. For now the fix seems good, thanks for the work!

@chhagedorn
Copy link
Member Author

Thanks Tobias and Emanuel for your review! I've pushed an update with the review suggestion.

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.

Thanks, still looks good.

@chhagedorn
Copy link
Member Author

Thanks @TobiHartmann and @eme64!

/integrate

@openjdk
Copy link

openjdk bot commented Nov 16, 2023

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

  • eaa4417: 8319301: Static analysis warnings after JDK-8318016
  • 3452210: 8283140: Remove unused encoding classes/operands from x86_64.ad
  • f0b7eb5: 8304020: Speed up test/jdk/java/util/zip/ZipFile/TestTooManyEntries.java and clarify its purpose
  • ffa35d8: 8301997: Move method resolution information out of the cpCache
  • 891d8cf: 8319986: Invalid/inconsistent description and example for DateFormat
  • 536b1ce: 8320130: Problemlist 2 vmTestbase/nsk/jdi/StepRequest/addClassFilter_rt tests with Xcomp
  • 0bda467: 8319187: Add three eMudhra emSign roots
  • 3c6ffca: 8318219: RISC-V: C2 ExpandBits
  • 77a6966: 8320053: GHA: Cross-compile gtest code
  • 4f4d00f: 8319966: AIX: expected [[0:i4]] but found [[0:I4]] after JDK-8319882
  • ... and 119 more: https://git.openjdk.org/jdk/compare/8fb94fd4fe46bc12885c7cc0c7ebbbc10fba47e5...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Nov 16, 2023

@chhagedorn Pushed as commit 2db9ea9.

💡 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
3 participants