Skip to content

Commit ed1ea5f

Browse files
committed
8314024: SIGSEGV in PhaseIdealLoop::build_loop_late_post_work due to bad immediate dominator info
Reviewed-by: kvn, chagedorn
1 parent f3aeb02 commit ed1ea5f

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

src/hotspot/share/opto/loopTransform.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,6 +2962,8 @@ void PhaseIdealLoop::do_range_check(IdealLoopTree *loop, Node_List &old_new) {
29622962
continue; // Don't rce this check but continue looking for other candidates.
29632963
}
29642964

2965+
assert(is_dominator(compute_early_ctrl(limit, limit_c), pre_end), "node pinned on loop exit test?");
2966+
29652967
// Check for scaled induction variable plus an offset
29662968
Node *offset = nullptr;
29672969

@@ -2980,6 +2982,8 @@ void PhaseIdealLoop::do_range_check(IdealLoopTree *loop, Node_List &old_new) {
29802982
if (is_dominator(ctrl, offset_c)) {
29812983
continue; // Don't rce this check but continue looking for other candidates.
29822984
}
2985+
2986+
assert(is_dominator(compute_early_ctrl(offset, offset_c), pre_end), "node pinned on loop exit test?");
29832987
#ifdef ASSERT
29842988
if (TraceRangeLimitCheck) {
29852989
tty->print_cr("RC bool node%s", flip ? " flipped:" : ":");

src/hotspot/share/opto/loopopts.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,14 @@ bool PhaseIdealLoop::ctrl_of_use_out_of_loop(const Node* n, Node* n_ctrl, IdealL
17991799
if (n_loop->is_member(u_loop)) {
18001800
return false; // Found use in inner loop
18011801
}
1802+
// Sinking a node from a pre loop to its main loop pins the node between the pre and main loops. If that node is input
1803+
// to a check that's eliminated by range check elimination, it becomes input to an expression that feeds into the exit
1804+
// test of the pre loop above the point in the graph where it's pinned.
1805+
if (n_loop->_head->is_CountedLoop() && n_loop->_head->as_CountedLoop()->is_pre_loop() &&
1806+
u_loop->_head->is_CountedLoop() && u_loop->_head->as_CountedLoop()->is_main_loop() &&
1807+
n_loop->_next == get_loop(u_loop->_head->as_CountedLoop()->skip_strip_mined())) {
1808+
return false;
1809+
}
18021810
return true;
18031811
}
18041812

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2023, Red Hat, Inc. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8314024
27+
* @requires vm.compiler2.enabled
28+
* @summary Node used in check in main loop sunk from pre loop before RC elimination
29+
* @run main/othervm -XX:-BackgroundCompilation -XX:-UseLoopPredicate TestNodeSunkFromPreLoop
30+
*
31+
*/
32+
33+
public class TestNodeSunkFromPreLoop {
34+
private static int unusedField;
35+
36+
public static void main(String[] args) {
37+
A object = new A();
38+
for (int i = 0; i < 20_000; i++) {
39+
test(object, 1000, 0);
40+
}
41+
}
42+
43+
private static int test(A object, int stop, int inv) {
44+
int res = 0;
45+
// pre/main/post loops created for this loop
46+
for (int i = 0; i < stop; i++) {
47+
// Optimized out. Delay transformation of loop above.
48+
for (int j = 0; j < 10; j++) {
49+
for (int k = 0; k < 10; k++) {
50+
}
51+
}
52+
// null check in pre loop so field load also in pre loop
53+
int v = object.field;
54+
int v2 = (v + inv);
55+
if (i > 1000) {
56+
// never taken. v + inv has a use out of loop at an unc.
57+
unusedField = v2;
58+
}
59+
// transformed in the main loop to i + (v + inv)
60+
int v3 = (v + (i + inv));
61+
if (v3 > 1000) {
62+
break;
63+
}
64+
}
65+
return res;
66+
}
67+
68+
private static class A {
69+
public int field;
70+
}
71+
}

0 commit comments

Comments
 (0)