Skip to content

JDK-8275854: C2: assert(stride_con != 0) failed: missed some peephole opt #6099

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

Conversation

casparcwang
Copy link
Contributor

@casparcwang casparcwang commented Oct 25, 2021

If subsume optimization will eliminate LongCountedLoopEndNode node by mistake, which will lead to PhaseIdealLoop optimization crash.

For example, the test of node 538 and node 553 will become the same after the first PhaseIdealLoop optimization. Node 555 is the back edge to the loop, and node 553 will be replaced by a LongCountedLoopEndNode node.
image

In the next PhaseIdealLoop optimization, node 538 find node 553 is redundant, and will subsume node 553. Then the PhaseIdealLoop optimization will crash, because there is no loop end node.
image

There are two way to fix the crash, the first is like the way in this pr, just exit IFNode subsume optimization when it's a LongCountedLoopEndNode node. The second possible fix is that exchange the dominating IF node with the LongCountedLoopEndNode node:

diff --git a/src/hotspot/share/opto/ifnode.cpp b/src/hotspot/share/opto/ifnode.cpp
index 38b40a6..31ff172 100644
--- a/src/hotspot/share/opto/ifnode.cpp
+++ b/src/hotspot/share/opto/ifnode.cpp
@@ -1674,6 +1674,21 @@ Node* IfNode::simple_subsuming(PhaseIterGVN* igvn) {
     }
   }
 
+  if (is_LongCountedLoopEnd()) {
+    set_req(0, dom->in(0));
+    set_req(1, dom->in(1));
+    dom->set_req(0, pre);
+    dom->set_req(1, igvn->intcon(is_always_true ? 1 : 0));
+    Node* proj0 = raw_out(0);
+    Node* proj1 = raw_out(1);
+    Node* dom_proj0 = dom->raw_out(0);
+    Node* dom_proj1 = dom->raw_out(1);
+    dom_proj0->set_req(0, this);
+    dom_proj1->set_req(0, this);
+    proj0->set_req(0, dom);
+    proj1->set_req(0, dom);
+  }
+
   if (bol->outcnt() == 0) {
     igvn->remove_dead_node(bol);    // Kill the BoolNode.
   }
diff --git a/src/hotspot/share/opto/loopnode.cpp b/src/hotspot/share/opto/loopnode.cpp
index 6f7e34d..7955722 100644
--- a/src/hotspot/share/opto/loopnode.cpp
+++ b/src/hotspot/share/opto/loopnode.cpp
@@ -802,7 +802,7 @@ bool PhaseIdealLoop::transform_long_counted_loop(IdealLoopTree* loop, Node_List
   Node* back_control = head->in(LoopNode::LoopBackControl);
 
   // data nodes on back branch not supported
-  if (back_control->outcnt() > 1) {
+  if (back_control->outcnt() > 1 || back_control->Opcode() != Op_IfTrue) {
     return false;
   }
 

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8275854: C2: assert(stride_con != 0) failed: missed some peephole opt

Reviewers

Contributors

  • Roland Westrelin <roland@openjdk.org>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6099/head:pull/6099
$ git checkout pull/6099

Update a local copy of the PR:
$ git checkout pull/6099
$ git pull https://git.openjdk.java.net/jdk pull/6099/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6099

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6099.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 25, 2021

👋 Welcome back casparcwang! 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 Oct 25, 2021
@openjdk
Copy link

openjdk bot commented Oct 25, 2021

@casparcwang 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 Oct 25, 2021
@mlbridge
Copy link

mlbridge bot commented Oct 25, 2021

@rwestrel
Copy link
Contributor

If subsume optimization will eliminate LongCountedLoopEndNode node by mistake, which will lead to PhaseIdealLoop optimization crash.

Is it by mistake (that is it's erroneous to eliminate the LongCountedLoopEndNode)?
Do you have a test case for this? Ideally, the PR should include one.

@casparcwang
Copy link
Contributor Author

casparcwang commented Oct 26, 2021

Is it by mistake (that is it's erroneous to eliminate the LongCountedLoopEndNode)? Do you have a test case for this? Ideally, the PR should include one.

Thank you for your review. The crash is reported by our fuzz test cluster, and caused by an OSR compilation. I have added the complete fuzz test as the test case.

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.

The problem with such large and non-targeted regression tests is that they won't work for long. Other changes to C2 and/or HotSpot will change timing, profile information, IR shape, optimization sequence or other factors such that the issue will not reproduce anymore with that test. Often, the test also does not reproduce the issue in older JDK versions that are affected as well.

We therefore usually run creduce --not-c on our generated tests to simplify them (see creduce). You might want to increase the number of loop iterations in the main method first and also add -Xbatch.

@rwestrel
Copy link
Contributor

The optimization is valid AFAIU, so I don't think blocking it is the right fix. What about something like this:

diff --git a/src/hotspot/share/opto/ifnode.cpp b/src/hotspot/share/opto/ifnode.cpp
index 38b40a68b1f..b28a382ebe7 100644
--- a/src/hotspot/share/opto/ifnode.cpp
+++ b/src/hotspot/share/opto/ifnode.cpp
@@ -1721,6 +1721,14 @@ Node* IfProjNode::Identity(PhaseGVN* phase) {
        // will cause this node to be reprocessed once the dead branch is killed.
        in(0)->outcnt() == 1))) {
     // IfNode control
+    if (in(0)->is_BaseCountedLoopEnd()) {
+      Node* head = unique_ctrl_out();
+      if (head != NULL && head->is_BaseCountedLoop() && head->in(LoopNode::LoopBackControl) == this) {
+        Node* new_head = new LoopNode(head->in(LoopNode::EntryControl), this);
+        phase->is_IterGVN()->register_new_node_with_optimizer(new_head);
+        phase->is_IterGVN()->replace_node(head, new_head);
+      }
+    }
     return in(0)->in(0);
   }
   // no progress

That prevents the crash and gives the loop another chance to be optimized.

@casparcwang
Copy link
Contributor Author

The problem with such large and non-targeted regression tests is that they won't work for long. Other changes to C2 and/or HotSpot will change timing, profile information, IR shape, optimization sequence or other factors such that the issue will not reproduce anymore with that test. Often, the test also does not reproduce the issue in older JDK versions that are affected as well.

We therefore usually run creduce --not-c on our generated tests to simplify them (see creduce). You might want to increase the number of loop iterations in the main method first and also add -Xbatch.

Thank you for your review. The test is indeed not targeted. I will try to reduce the test to a simpler case.

@casparcwang
Copy link
Contributor Author

The optimization is valid AFAIU, so I don't think blocking it is the right fix. What about something like this:

diff --git a/src/hotspot/share/opto/ifnode.cpp b/src/hotspot/share/opto/ifnode.cpp
index 38b40a68b1f..b28a382ebe7 100644
--- a/src/hotspot/share/opto/ifnode.cpp
+++ b/src/hotspot/share/opto/ifnode.cpp
@@ -1721,6 +1721,14 @@ Node* IfProjNode::Identity(PhaseGVN* phase) {
        // will cause this node to be reprocessed once the dead branch is killed.
        in(0)->outcnt() == 1))) {
     // IfNode control
+    if (in(0)->is_BaseCountedLoopEnd()) {
+      Node* head = unique_ctrl_out();
+      if (head != NULL && head->is_BaseCountedLoop() && head->in(LoopNode::LoopBackControl) == this) {
+        Node* new_head = new LoopNode(head->in(LoopNode::EntryControl), this);
+        phase->is_IterGVN()->register_new_node_with_optimizer(new_head);
+        phase->is_IterGVN()->replace_node(head, new_head);
+      }
+    }
     return in(0)->in(0);
   }
   // no progress

That prevents the crash and gives the loop another chance to be optimized.

Replace the CountedLoopNode node with a new Loop node is more elegant, and will generate more optimized code as the second proposed version (which exchange the two if node), but your suggested code is more compact. I will change to your suggested version.

@casparcwang
Copy link
Contributor Author

/contributor add rwestrel

@openjdk
Copy link

openjdk bot commented Oct 29, 2021

@casparcwang Could not parse rwestrel as a valid contributor.
Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]. For example:

  • /contributor add @openjdk-bot
  • /contributor add duke
  • /contributor add J. Duke <duke@openjdk.org>

@casparcwang
Copy link
Contributor Author

/contributor add roland

@openjdk
Copy link

openjdk bot commented Oct 29, 2021

@casparcwang
Contributor Roland Westrelin <roland@openjdk.org> successfully added.

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.

That looks good to me.

@openjdk
Copy link

openjdk bot commented Oct 29, 2021

⚠️ @casparcwang the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout JDK-8275854
$ git commit -c user.name='Preferred Full Name' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented Oct 29, 2021

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

8275854: C2: assert(stride_con != 0) failed: missed some peephole opt

Co-authored-by: Roland Westrelin <roland@openjdk.org>
Reviewed-by: thartmann, roland, kvn

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 296 new commits pushed to the master branch:

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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@TobiHartmann, @rwestrel, @vnkozlov) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 29, 2021
@casparcwang
Copy link
Contributor Author

ping, can I have more review of this pr?

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.

That looks reasonable to me but please add a comment to the new code.

I'll run some testing in the meantime.

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. But please wait tests results from Tobias.

@casparcwang
Copy link
Contributor Author

That looks reasonable to me but please add a comment to the new code.

I'll run some testing in the meantime.

Thank you very much for your review and testing. I have added some comment to the newly added code.

@casparcwang
Copy link
Contributor Author

Looks good. But please wait tests results from Tobias.

Thank you very much for your review and work. I have passed jtreg and some test-suite on my server, and it's always a good thing to run more tests.

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.

The comment looks good and all tests passed.

@casparcwang
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Nov 11, 2021
@openjdk
Copy link

openjdk bot commented Nov 11, 2021

@casparcwang
Your change (at version 89d00e1) is now ready to be sponsored by a Committer.

@huishi-hs
Copy link

/sponsor

@openjdk
Copy link

openjdk bot commented Nov 11, 2021

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

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Nov 11, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Nov 11, 2021
@openjdk
Copy link

openjdk bot commented Nov 11, 2021

@huishi-hs @casparcwang Pushed as commit aea0967.

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

5 participants