Skip to content

Commit 2db9005

Browse files
committed
8262017: C2: assert(n != __null) failed: Bad immediate dominator info.
Reviewed-by: roland, neliasso, kvn
1 parent 7bc96db commit 2db9005

File tree

2 files changed

+188
-12
lines changed

2 files changed

+188
-12
lines changed

src/hotspot/share/opto/loopTransform.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,22 +2331,40 @@ Node* PhaseIdealLoop::adjust_limit(bool is_positive_stride, Node* scale, Node* o
23312331
register_new_node(limit, pre_ctrl);
23322332
}
23332333

2334-
// Clamp the limit to handle integer under-/overflows.
2334+
// Clamp the limit to handle integer under-/overflows by using long values.
2335+
// We only convert the limit back to int when we handled under-/overflows.
2336+
// Note that all values are longs in the following computations.
23352337
// When reducing the limit, clamp to [min_jint, old_limit]:
2336-
// MIN(old_limit, MAX(limit, min_jint))
2338+
// INT(MINL(old_limit, MAXL(limit, min_jint)))
2339+
// - integer underflow of limit: MAXL chooses min_jint.
2340+
// - integer overflow of limit: MINL chooses old_limit (<= MAX_INT < limit)
23372341
// When increasing the limit, clamp to [old_limit, max_jint]:
2338-
// MAX(old_limit, MIN(limit, max_jint))
2339-
Node* cmp = new CmpLNode(limit, _igvn.longcon(is_positive_stride ? min_jint : max_jint));
2342+
// INT(MAXL(old_limit, MINL(limit, max_jint)))
2343+
// - integer overflow of limit: MINL chooses max_jint.
2344+
// - integer underflow of limit: MAXL chooses old_limit (>= MIN_INT > limit)
2345+
// INT() is finally converting the limit back to an integer value.
2346+
2347+
// We use CMove nodes to implement long versions of min/max (MINL/MAXL).
2348+
// We use helper methods for inner MINL/MAXL which return CMoveL nodes to keep a long value for the outer MINL/MAXL comparison:
2349+
Node* inner_result_long;
2350+
if (is_positive_stride) {
2351+
inner_result_long = MaxNode::signed_max(limit, _igvn.longcon(min_jint), TypeLong::LONG, _igvn);
2352+
} else {
2353+
inner_result_long = MaxNode::signed_min(limit, _igvn.longcon(max_jint), TypeLong::LONG, _igvn);
2354+
}
2355+
set_subtree_ctrl(inner_result_long, false);
2356+
2357+
// Outer MINL/MAXL:
2358+
// The comparison is done with long values but the result is the converted back to int by using CmovI.
2359+
Node* old_limit_long = new ConvI2LNode(old_limit);
2360+
register_new_node(old_limit_long, pre_ctrl);
2361+
Node* cmp = new CmpLNode(old_limit_long, limit);
23402362
register_new_node(cmp, pre_ctrl);
2341-
Node* bol = new BoolNode(cmp, is_positive_stride ? BoolTest::lt : BoolTest::gt);
2363+
Node* bol = new BoolNode(cmp, is_positive_stride ? BoolTest::gt : BoolTest::lt);
23422364
register_new_node(bol, pre_ctrl);
2343-
limit = new ConvL2INode(limit);
2344-
register_new_node(limit, pre_ctrl);
2345-
limit = new CMoveINode(bol, limit, _igvn.intcon(is_positive_stride ? min_jint : max_jint), TypeInt::INT);
2346-
register_new_node(limit, pre_ctrl);
2347-
2348-
limit = is_positive_stride ? (Node*)(new MinINode(old_limit, limit))
2349-
: (Node*)(new MaxINode(old_limit, limit));
2365+
Node* inner_result_int = new ConvL2INode(inner_result_long); // Could under-/overflow but that's fine as comparison was done with CmpL
2366+
register_new_node(inner_result_int, pre_ctrl);
2367+
limit = new CMoveINode(bol, old_limit, inner_result_int, TypeInt::INT);
23502368
register_new_node(limit, pre_ctrl);
23512369
return limit;
23522370
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. 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 8262017
27+
* @summary Dominator failure because ConvL2I node becomes TOP due to missing overflow/underflow handling in range check elimination
28+
* in PhaseIdealLoop::add_constraint().
29+
* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileCommand=compileonly,compiler.rangechecks.TestRangeCheckLimits::*
30+
* compiler.rangechecks.TestRangeCheckLimits
31+
*/
32+
33+
package compiler.rangechecks;
34+
35+
public class TestRangeCheckLimits {
36+
static int a = 400;
37+
static volatile int b;
38+
static long lFld;
39+
static int iFld;
40+
41+
public static void main(String[] k) {
42+
// Test all cases in PhaseIdealLoop::add_constraint().
43+
testPositiveCaseMainLoop();
44+
testNegativeCaseMainLoop();
45+
testPositiveCasePreLoop();
46+
testNegativeCasePreLoop();
47+
}
48+
49+
public static void testPositiveCaseMainLoop() {
50+
int e, f, g = 0, h[] = new int[a];
51+
double i[] = new double[a];
52+
long j = 9;
53+
Helper.init(h, 3);
54+
for (e = 5; e < 154; e++) {
55+
for (f = 1; f < 169; f += 2) {
56+
b = e;
57+
}
58+
i[1] = b;
59+
for (g = 8; g < 168; g += 2) {
60+
j = g - 5;
61+
if (j > Integer.MAX_VALUE - 1) {
62+
switch (3) {
63+
case 3:
64+
}
65+
}
66+
}
67+
}
68+
if (g != 168) {
69+
throw new RuntimeException("fail");
70+
}
71+
lFld = j;
72+
}
73+
74+
75+
public static void testPositiveCasePreLoop() {
76+
int e, f, g = 0, h[] = new int[a];
77+
double i[] = new double[a];
78+
long j = 9;
79+
Helper.init(h, 3);
80+
for (e = 5; e < 154; e++) {
81+
for (f = 1; f < 169; f += 2) {
82+
b = e;
83+
}
84+
i[1] = b;
85+
for (g = 8; g < 168; g += 2) {
86+
j = g + 5;
87+
if (j > 180) {
88+
switch (3) {
89+
case 3:
90+
}
91+
}
92+
}
93+
}
94+
if (g != 168) {
95+
throw new RuntimeException("fail");
96+
}
97+
lFld = j;
98+
}
99+
100+
public static void testNegativeCaseMainLoop() {
101+
int e, f, g = 0, h[] = new int[a];
102+
double i[] = new double[a];
103+
long j = 9;
104+
Helper.init(h, 3);
105+
for (e = 5; e < 154; e++) {
106+
for (f = 1; f < 169; f += 2) {
107+
b = e;
108+
}
109+
i[1] = b;
110+
for (g = 8; g < 168; g += 2) {
111+
j = g;
112+
if (j < 5) {
113+
switch (3) {
114+
case 3:
115+
}
116+
}
117+
}
118+
}
119+
if (g != 168) {
120+
throw new RuntimeException("fail");
121+
}
122+
lFld = j;
123+
}
124+
125+
126+
public static void testNegativeCasePreLoop() {
127+
int e, f, g = 0, h[] = new int[a];
128+
double i[] = new double[a];
129+
long j = 9;
130+
Helper.init(h, 3);
131+
for (e = 5; e < 154; e++) {
132+
for (f = 1; f < 169; f += 2) {
133+
b = e;
134+
}
135+
i[1] = b;
136+
for (g = 168; g > 8; g -= 2) {
137+
j = g - 5;
138+
if (j > Integer.MAX_VALUE - 1) {
139+
switch (3) {
140+
case 3:
141+
}
142+
}
143+
}
144+
}
145+
if (g != 8) {
146+
throw new RuntimeException("fail");
147+
}
148+
lFld = j;
149+
}
150+
}
151+
152+
class Helper {
153+
public static void init(int[] a, int seed) {
154+
for (int j = 0; j < a.length; j++) {
155+
a[j] = (j % 2 == 0) ? seed + j : seed - j;
156+
}
157+
}
158+
}

0 commit comments

Comments
 (0)