Skip to content

Commit

Permalink
8315377: C2: assert(u->find_out_with(Op_AddP) == nullptr) failed: mor…
Browse files Browse the repository at this point in the history
…e than 2 chained AddP nodes?

Reviewed-by: chagedorn, kvn, thartmann
  • Loading branch information
rwestrel committed Sep 6, 2023
1 parent a258fc4 commit ba1a463
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/opto/loopnode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,8 @@ class PhaseIdealLoop : public PhaseTransform {
bool clone_cmp_loadklass_down(Node* n, const Node* blk1, const Node* blk2);

bool at_relevant_ctrl(Node* n, const Node* blk1, const Node* blk2);

void update_addp_chain_base(Node* x, Node* old_base, Node* new_base);
};


Expand Down
35 changes: 23 additions & 12 deletions src/hotspot/share/opto/loopopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,9 +1677,10 @@ void PhaseIdealLoop::try_sink_out_of_loop(Node* n) {
assert(!n_loop->is_member(get_loop(x_ctrl)), "should have moved out of loop");
register_new_node(x, x_ctrl);

// Chain of AddP: (AddP base (AddP base )) must keep the same base after sinking so:
// 1- We don't add a CastPP here when the first one is sunk so if the second one is not, their bases remain
// the same.
// Chain of AddP nodes: (AddP base (AddP base (AddP base )))
// All AddP nodes must keep the same base after sinking so:
// 1- We don't add a CastPP here until the last one of the chain is sunk: if part of the chain is not sunk,
// their bases remain the same.
// (see 2- below)
assert(!x->is_AddP() || !x->in(AddPNode::Address)->is_AddP() ||
x->in(AddPNode::Address)->in(AddPNode::Base) == x->in(AddPNode::Base) ||
Expand All @@ -1704,16 +1705,10 @@ void PhaseIdealLoop::try_sink_out_of_loop(Node* n) {
register_new_node(cast, x_ctrl);
}
x->replace_edge(in, cast);
// Chain of AddP:
// 2- A CastPP of the base is only added now that both AddP nodes are sunk
// Chain of AddP nodes:
// 2- A CastPP of the base is only added now that all AddP nodes are sunk
if (x->is_AddP() && k == AddPNode::Base) {
for (DUIterator_Fast imax, i = x->fast_outs(imax); i < imax; i++) {
Node* u = x->fast_out(i);
if (u->is_AddP() && u->in(AddPNode::Base) == n->in(AddPNode::Base)) {
_igvn.replace_input_of(u, AddPNode::Base, cast);
assert(u->find_out_with(Op_AddP) == nullptr, "more than 2 chained AddP nodes?");
}
}
update_addp_chain_base(x, n->in(AddPNode::Base), cast);
}
break;
}
Expand All @@ -1728,6 +1723,22 @@ void PhaseIdealLoop::try_sink_out_of_loop(Node* n) {
}
}

void PhaseIdealLoop::update_addp_chain_base(Node* x, Node* old_base, Node* new_base) {
ResourceMark rm;
Node_List wq;
wq.push(x);
while (wq.size() != 0) {
Node* n = wq.pop();
for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
Node* u = n->fast_out(i);
if (u->is_AddP() && u->in(AddPNode::Base) == old_base) {
_igvn.replace_input_of(u, AddPNode::Base, new_base);
wq.push(u);
}
}
}
}

// Compute the early control of a node by following its inputs until we reach
// nodes that are pinned. Then compute the LCA of the control of all pinned nodes.
Node* PhaseIdealLoop::compute_early_ctrl(Node* n, Node* n_ctrl) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2023, Red Hat, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test
* @bug 8315377
* @requires vm.compiler2.enabled
* @summary C2: assert(u->find_out_with(Op_AddP) == nullptr) failed: more than 2 chained AddP nodes?
* @library /test/lib
* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileOnly=TestSinkingMoreThan2AddPNodes::test TestSinkingMoreThan2AddPNodes
*
*/

import jdk.test.lib.Utils;

public class TestSinkingMoreThan2AddPNodes {
public static void main(String[] strArr) throws Exception {
Thread t = new Thread(new Runnable() {
public void run() {
test();
}
});
t.setDaemon(true);
t.start();
Thread.sleep(Utils.adjustTimeout(500));
}

static void test() {
double dArr[] = new double[10];
int i4 = 5, i11, i12 = 2, iArr[] = new int[400];
long l1;
byte by1 = 0;
short s1 = 8;

for (int i = 0; i < iArr.length; i++) {
iArr[i] = (i % 2 == 0) ? 23 : 34;
}

for (i11 = 10; i11 > 9; ) {
l1 = 1;
do {
try {
i4 = 6 % i4;
i12 = iArr[(int) l1];
} catch (ArithmeticException a_e) {
}
by1 += 8;
iArr = iArr;
} while (++l1 < 11);
}

long meth_res = i12;
}
}

3 comments on commit ba1a463

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on ba1a463 Oct 2, 2023

Choose a reason for hiding this comment

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

/backport jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on ba1a463 Oct 2, 2023

Choose a reason for hiding this comment

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

@GoeLin the backport was successfully created on the branch GoeLin-backport-ba1a4639 in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit ba1a4639 from the openjdk/jdk repository.

The commit being backported was authored by Roland Westrelin on 6 Sep 2023 and was reviewed by Christian Hagedorn, Vladimir Kozlov and Tobias Hartmann.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u:

$ git fetch https://github.com/openjdk-bots/jdk21u.git GoeLin-backport-ba1a4639:GoeLin-backport-ba1a4639
$ git checkout GoeLin-backport-ba1a4639
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u.git GoeLin-backport-ba1a4639

Please sign in to comment.