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

8308892: Bad graph detected in build_loop_late after JDK-8305635 #14196

Closed
wants to merge 5 commits into from

Conversation

chhagedorn
Copy link
Member

@chhagedorn chhagedorn commented May 28, 2023

The cleanup done in JDK-8305635 wrongly identifies unrelated Parse Predicates which are not cleaned up, yet. It just walks from the entry of the loop up and tries to find each of the three Parse Predicates once but in no particular order. This order insensitive walk is wrong as seen in the following graph (from the attached replay file of this bug):

image

We first find 116 Parse Predicate for Loop Predicates, then 84 Parse Predicate for Profiled Loop Predicates and then stop when finding 71 Parse Predicate for Loop Predicates because we've already found a Parse Predicate for Loop Predicates already. We then wrongly create Loop Predicates (above 116 Parse Predicate) which are below newly created Profiled Loop Predicates (above 84 Parse Predicate). This could lead to a bad graph because of data dependencies that rely on the fact that Loop Predicates are above Profiled Loop Predicates:

bool can_create_loop_predicates = true;
// We cannot add Loop Predicates if:
// - Already added Profiled Loop Predicates (Loop Predicates and Profiled Loop Predicates can be dependent
// through a data node, and thus we should only add new Profiled Loop Predicates which are below Loop Predicates
// in the graph).
// - There are currently no Profiled Loop Predicates, but we have a data node with a control dependency on the Loop
// Parse Predicate (could happen, for example, if we've removed an earlier created Profiled Loop Predicate with
// dominated_by()). We should not create a Loop Predicate for a check that is dependent on this data node because
// the Loop Predicate would end up above the data node with its dependency on the Loop Parse Predicate below. This
// would become unschedulable. However, we can still hoist the check as Profiled Loop Predicate which would end up
// below the Loop Parse Predicate.
if (Predicates::has_profiled_loop_predicates(parse_predicates)
|| (parse_predicates.loop_predicate_proj() != nullptr && parse_predicates.loop_predicate_proj()->outcnt() != 1)) {
can_create_loop_predicates = false;
}

The fix is straight forward to make the assignment of Parse Predicate projections in ParsePredicates aware of the relative ordering constraint. Note that this class will be refactored again in JDK-8305636. But I think properly fixing this first is better than waiting for JDK-8305636 to go in.

Testing: tier1-4, hs-precheckin-comp, hs-stress-comp

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-8308892: Bad graph detected in build_loop_late after JDK-8305635

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14196

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 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.

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

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

mlbridge bot commented May 28, 2023

Webrevs

Copy link
Contributor

@robcasloz robcasloz 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!

Windows build failure in GHA testing is unrelated.

@openjdk
Copy link

openjdk bot commented May 29, 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:

8308892: Bad graph detected in build_loop_late after JDK-8305635

Reviewed-by: rcastanedalo, roland, 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 112 new commits pushed to the master branch:

  • dc8bc6c: 8308090: Add container tests for on-the-fly resource quota updates
  • 73e7af9: 8309287: Add fontconfig requirement to building.md for Debian
  • aeb53e6: 8308711: Develop additional Tests for KEM implementation
  • dcd9590: 8309224: Fix xlc17 clang 15 warnings in java.desktop
  • 8f1ce78: 8308752: Generational ZGC: Avoid final marking through stack chunks
  • 7b0a336: 8308387: CLD created and unloading list sharing _next node pointer leads to concurrent YC missing CLD roots
  • 60f3b87: 8309295: C2: MaxNode::signed_min() returns nullptr for int operands
  • 8007599: 8309093: Underscore with brackets
  • 5bd2af2: 8307478: Implementation of Prepare to Restrict The Dynamic Loading of Agents
  • 325940b: 8307105: JFileChooser InvalidPathException when selecting some system folders on Windows
  • ... and 102 more: https://git.openjdk.org/jdk/compare/90e57fd5a96199b01e7c058a4d8a82e467d7f41a...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 May 29, 2023
@chhagedorn
Copy link
Member Author

Thanks Roberto for your review!

@rwestrel
Copy link
Contributor

The cleanup done in JDK-8305635 wrongly identifies unrelated Parse Predicates which are not cleaned up, yet.

So which of the 3 predicates will get cleaned up? Are some of the 3 predicates for another loop that doesn't exist anymore?

@chhagedorn
Copy link
Member Author

chhagedorn commented May 30, 2023

The cleanup done in JDK-8305635 wrongly identifies unrelated Parse Predicates which are not cleaned up, yet.

So which of the 3 predicates will get cleaned up? Are some of the 3 predicates for another loop that doesn't exist anymore?

Sorry, the explanation of the bug was not precise enough - there is a missing piece: It should have cleaned up 84 Parse Predicate and 71 Parse Predicate in eliminate_useless_predicates() but it does not because we also use the broken ParsePredicates class to collect them:

ParsePredicates parse_predicates(entry);
ProjNode* predicate_proj = parse_predicates.loop_limit_check_predicate_proj();
if (predicate_proj != nullptr) { // right pattern that can be used by loop predication
assert(predicate_proj->in(0)->in(1)->in(1)->Opcode() == Op_Opaque1, "must be");
useful_predicates.push(predicate_proj->in(0)->in(1)->in(1)); // good one
}
if (UseProfiledLoopPredicate) {
predicate_proj = parse_predicates.profiled_loop_predicate_proj();
if (predicate_proj != nullptr) { // right pattern that can be used by loop predication
useful_predicates.push(predicate_proj->in(0)->in(1)->in(1)); // good one
get_assertion_predicates(predicate_proj, useful_predicates, true);
}
}
if (UseLoopPredicate) {
predicate_proj = parse_predicates.loop_predicate_proj();
if (predicate_proj != nullptr) { // right pattern that can be used by loop predication
useful_predicates.push(predicate_proj->in(0)->in(1)->in(1)); // good one
get_assertion_predicates(predicate_proj, useful_predicates, true);
}
}
}

So, we keep 116 Parse Predicate and 84 Parse Predicate as useful predicates while 71 Parse Predicate is removed before Loop Predication.

The useless predicates were added normally for the loop while the additional 116 Parse Predicate was added with maybe_add_predicate_after_if() (the profiled loop predicate was skipped due to too_may_trap(reason) being true).

@rwestrel
Copy link
Contributor

The useless predicates were added normally for the loop while the additional 116 Parse Predicate was added with maybe_add_predicate_after_if() (the profiled loop predicate was skipped due to too_may_trap(reason) being true).

Do I read that correctly that parsing inserts useless/duplicate predicates?

@chhagedorn
Copy link
Member Author

After the first IGVN round, after parsing, they become useless because the If that triggered the insertion of the predicates with maybe_add_predicate_after_if() is folded away. I think it's unfortunate, though, that we eliminate 71 Parse Predicate and 84 Parse Predicate instead of 116 Parse Predicate (so, we cannot add profiled loop predicates anymore). But that might be an edge case.

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 good to me.

@rwestrel
Copy link
Contributor

Thanks for the explanation. Can a test case be added?

@chhagedorn
Copy link
Member Author

Thanks Roland for your review!

I was able to come up with a test that fails with the same graph pattern. I've pushed an update.

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.

@chhagedorn
Copy link
Member Author

Thanks Tobias for your review! I've simplified the test some more but the fix remains the same.

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.

Still looks good.

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 good to me.

@chhagedorn
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 2, 2023

Going to push as commit 7dbdad5.
Since your change was applied there have been 112 commits pushed to the master branch:

  • dc8bc6c: 8308090: Add container tests for on-the-fly resource quota updates
  • 73e7af9: 8309287: Add fontconfig requirement to building.md for Debian
  • aeb53e6: 8308711: Develop additional Tests for KEM implementation
  • dcd9590: 8309224: Fix xlc17 clang 15 warnings in java.desktop
  • 8f1ce78: 8308752: Generational ZGC: Avoid final marking through stack chunks
  • 7b0a336: 8308387: CLD created and unloading list sharing _next node pointer leads to concurrent YC missing CLD roots
  • 60f3b87: 8309295: C2: MaxNode::signed_min() returns nullptr for int operands
  • 8007599: 8309093: Underscore with brackets
  • 5bd2af2: 8307478: Implementation of Prepare to Restrict The Dynamic Loading of Agents
  • 325940b: 8307105: JFileChooser InvalidPathException when selecting some system folders on Windows
  • ... and 102 more: https://git.openjdk.org/jdk/compare/90e57fd5a96199b01e7c058a4d8a82e467d7f41a...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jun 2, 2023

@chhagedorn Pushed as commit 7dbdad5.

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