Skip to content

Commit 3711d2b

Browse files
author
Satyen Subramaniam
committed
8342330: C2: "node pinned on loop exit test?" assert failure
Backport-of: 004aaea76db091569aa88eeb6b08db3408f288cd
1 parent 5a3aaa9 commit 3711d2b

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

src/hotspot/share/opto/loopopts.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,10 +1849,11 @@ bool PhaseIdealLoop::ctrl_of_use_out_of_loop(const Node* n, Node* n_ctrl, IdealL
18491849
// 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
18501850
// to a check that's eliminated by range check elimination, it becomes input to an expression that feeds into the exit
18511851
// test of the pre loop above the point in the graph where it's pinned.
1852-
if (n_loop->_head->is_CountedLoop() && n_loop->_head->as_CountedLoop()->is_pre_loop() &&
1853-
u_loop->_head->is_CountedLoop() && u_loop->_head->as_CountedLoop()->is_main_loop() &&
1854-
n_loop->_next == get_loop(u_loop->_head->as_CountedLoop()->skip_strip_mined())) {
1855-
return false;
1852+
if (n_loop->_head->is_CountedLoop() && n_loop->_head->as_CountedLoop()->is_pre_loop()) {
1853+
CountedLoopNode* pre_loop = n_loop->_head->as_CountedLoop();
1854+
if (is_dominator(pre_loop->loopexit(), ctrl)) {
1855+
return false;
1856+
}
18561857
}
18571858
return true;
18581859
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2024, 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 8342330
27+
* @summary C2: "node pinned on loop exit test?" assert failure
28+
* @requires vm.flavor == "server"
29+
*
30+
* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-TieredCompilation
31+
* -XX:-UseLoopPredicate -XX:LoopMaxUnroll=0 TestSunkRangeFromPreLoopRCE
32+
*
33+
*/
34+
35+
36+
import java.util.Arrays;
37+
38+
public class TestSunkRangeFromPreLoopRCE {
39+
private static int[] array = new int[1000];
40+
private static A objectField = new A(42);
41+
42+
public static void main(String[] args) {
43+
boolean[] allTrue = new boolean[1000];
44+
Arrays.fill(allTrue, true);
45+
boolean[] allFalse = new boolean[1000];
46+
for (int i = 0; i < 20_000; i++) {
47+
test1(array.length/4, allTrue, 1, 0);
48+
test1(array.length/4, allFalse, 1, 0);
49+
}
50+
}
51+
52+
private static int test1(int stop, boolean[] flags, int otherScale, int x) {
53+
int scale;
54+
for (scale = 0; scale < 4; scale++) {
55+
for (int i = 0; i < 10; i++) {
56+
57+
}
58+
}
59+
if (array == null) {
60+
}
61+
int v = 0;
62+
for (int i = 0; i < stop; i++) {
63+
v += array[i];
64+
v += array[scale * i];
65+
if (i * scale + (objectField.intField + 1) == x) {
66+
}
67+
v += (scale - 4) * (x-objectField.intField);
68+
if (flags[i]) {
69+
return (x-objectField.intField);
70+
}
71+
}
72+
return v;
73+
}
74+
75+
private static class A {
76+
A(int field) {
77+
intField = field;
78+
}
79+
public int intField;
80+
}
81+
}

0 commit comments

Comments
 (0)