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?

Backport-of: ba1a46392f0b9c77c64278f82513aaf51f5c9b1b
  • Loading branch information
GoeLin committed Oct 4, 2023
1 parent bbfbc7b commit 67d2836
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 @@ -1737,6 +1737,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;
}
}

1 comment on commit 67d2836

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.