Skip to content

Commit 293d44f

Browse files
committed
8262017: C2: assert(n != __null) failed: Bad immediate dominator info.
Reviewed-by: roland Backport-of: 2db9005
1 parent 2a3d908 commit 293d44f

File tree

4 files changed

+308
-12
lines changed

4 files changed

+308
-12
lines changed

src/hotspot/share/opto/addnode.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "opto/cfgnode.hpp"
3030
#include "opto/connode.hpp"
3131
#include "opto/machnode.hpp"
32+
#include "opto/movenode.hpp"
3233
#include "opto/mulnode.hpp"
3334
#include "opto/phaseX.hpp"
3435
#include "opto/subnode.hpp"
@@ -832,6 +833,95 @@ const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const {
832833
return TypeLong::make( r0->get_con() ^ r1->get_con() );
833834
}
834835

836+
837+
Node* MaxNode::build_min_max(Node* a, Node* b, bool is_max, bool is_unsigned, const Type* t, PhaseGVN& gvn) {
838+
bool is_int = gvn.type(a)->isa_int();
839+
assert(is_int || gvn.type(a)->isa_long(), "int or long inputs");
840+
assert(is_int == (gvn.type(b)->isa_int() != NULL), "inconsistent inputs");
841+
if (!is_unsigned) {
842+
if (is_max) {
843+
if (is_int) {
844+
Node* res = gvn.transform(new MaxINode(a, b));
845+
assert(gvn.type(res)->is_int()->_lo >= t->is_int()->_lo && gvn.type(res)->is_int()->_hi <= t->is_int()->_hi, "type doesn't match");
846+
return res;
847+
} else {
848+
Node* cmp = gvn.transform(new CmpLNode(a, b));
849+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
850+
return gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));
851+
}
852+
} else {
853+
if (is_int) {
854+
Node* res = gvn.transform(new MinINode(a, b));
855+
assert(gvn.type(res)->is_int()->_lo >= t->is_int()->_lo && gvn.type(res)->is_int()->_hi <= t->is_int()->_hi, "type doesn't match");
856+
return res;
857+
} else {
858+
Node* cmp = gvn.transform(new CmpLNode(b, a));
859+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
860+
return gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));
861+
}
862+
}
863+
} else {
864+
if (is_max) {
865+
if (is_int) {
866+
Node* cmp = gvn.transform(new CmpUNode(a, b));
867+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
868+
return gvn.transform(new CMoveINode(bol, a, b, t->is_int()));
869+
} else {
870+
Node* cmp = gvn.transform(new CmpULNode(a, b));
871+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
872+
return gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));
873+
}
874+
} else {
875+
if (is_int) {
876+
Node* cmp = gvn.transform(new CmpUNode(b, a));
877+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
878+
return gvn.transform(new CMoveINode(bol, a, b, t->is_int()));
879+
} else {
880+
Node* cmp = gvn.transform(new CmpULNode(b, a));
881+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
882+
return gvn.transform(new CMoveLNode(bol, a, b, t->is_long()));
883+
}
884+
}
885+
}
886+
}
887+
888+
Node* MaxNode::build_min_max_diff_with_zero(Node* a, Node* b, bool is_max, const Type* t, PhaseGVN& gvn) {
889+
bool is_int = gvn.type(a)->isa_int();
890+
assert(is_int || gvn.type(a)->isa_long(), "int or long inputs");
891+
assert(is_int == (gvn.type(b)->isa_int() != NULL), "inconsistent inputs");
892+
Node* zero = NULL;
893+
if (is_int) {
894+
zero = gvn.intcon(0);
895+
} else {
896+
zero = gvn.longcon(0);
897+
}
898+
if (is_max) {
899+
if (is_int) {
900+
Node* cmp = gvn.transform(new CmpINode(a, b));
901+
Node* sub = gvn.transform(new SubINode(a, b));
902+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
903+
return gvn.transform(new CMoveINode(bol, sub, zero, t->is_int()));
904+
} else {
905+
Node* cmp = gvn.transform(new CmpLNode(a, b));
906+
Node* sub = gvn.transform(new SubLNode(a, b));
907+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
908+
return gvn.transform(new CMoveLNode(bol, sub, zero, t->is_long()));
909+
}
910+
} else {
911+
if (is_int) {
912+
Node* cmp = gvn.transform(new CmpINode(b, a));
913+
Node* sub = gvn.transform(new SubINode(a, b));
914+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
915+
return gvn.transform(new CMoveINode(bol, sub, zero, t->is_int()));
916+
} else {
917+
Node* cmp = gvn.transform(new CmpLNode(b, a));
918+
Node* sub = gvn.transform(new SubLNode(a, b));
919+
Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::lt));
920+
return gvn.transform(new CMoveLNode(bol, sub, zero, t->is_long()));
921+
}
922+
}
923+
}
924+
835925
//=============================================================================
836926
//------------------------------add_ring---------------------------------------
837927
// Supplied function returns the sum of the inputs.

src/hotspot/share/opto/addnode.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,39 @@ class XorLNode : public AddNode {
217217
// all the behavior of addition on a ring. Only new thing is that we allow
218218
// 2 equal inputs to be equal.
219219
class MaxNode : public AddNode {
220+
private:
221+
static Node* build_min_max(Node* a, Node* b, bool is_max, bool is_unsigned, const Type* t, PhaseGVN& gvn);
222+
static Node* build_min_max_diff_with_zero(Node* a, Node* b, bool is_max, const Type* t, PhaseGVN& gvn);
223+
220224
public:
221225
MaxNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}
222226
virtual int Opcode() const = 0;
227+
228+
static Node* unsigned_max(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {
229+
return build_min_max(a, b, true, true, t, gvn);
230+
}
231+
232+
static Node* unsigned_min(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {
233+
return build_min_max(a, b, false, true, t, gvn);
234+
}
235+
236+
static Node* signed_max(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {
237+
return build_min_max(a, b, true, false, t, gvn);
238+
}
239+
240+
static Node* signed_min(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {
241+
return build_min_max(a, b, false, false, t, gvn);
242+
}
243+
244+
// max(a-b, 0)
245+
static Node* max_diff_with_zero(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {
246+
return build_min_max_diff_with_zero(a, b, true, t, gvn);
247+
}
248+
249+
// min(a-b, 0)
250+
static Node* min_diff_with_zero(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {
251+
return build_min_max_diff_with_zero(a, b, false, t, gvn);
252+
}
223253
};
224254

225255
//------------------------------MaxINode---------------------------------------

src/hotspot/share/opto/loopTransform.cpp

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

2181-
// Clamp the limit to handle integer under-/overflows.
2181+
// Clamp the limit to handle integer under-/overflows by using long values.
2182+
// We only convert the limit back to int when we handled under-/overflows.
2183+
// Note that all values are longs in the following computations.
21822184
// When reducing the limit, clamp to [min_jint, old_limit]:
2183-
// MIN(old_limit, MAX(limit, min_jint))
2185+
// INT(MINL(old_limit, MAXL(limit, min_jint)))
2186+
// - integer underflow of limit: MAXL chooses min_jint.
2187+
// - integer overflow of limit: MINL chooses old_limit (<= MAX_INT < limit)
21842188
// When increasing the limit, clamp to [old_limit, max_jint]:
2185-
// MAX(old_limit, MIN(limit, max_jint))
2186-
Node* cmp = new CmpLNode(limit, _igvn.longcon(is_positive_stride ? min_jint : max_jint));
2189+
// INT(MAXL(old_limit, MINL(limit, max_jint)))
2190+
// - integer overflow of limit: MINL chooses max_jint.
2191+
// - integer underflow of limit: MAXL chooses old_limit (>= MIN_INT > limit)
2192+
// INT() is finally converting the limit back to an integer value.
2193+
2194+
// We use CMove nodes to implement long versions of min/max (MINL/MAXL).
2195+
// We use helper methods for inner MINL/MAXL which return CMoveL nodes to keep a long value for the outer MINL/MAXL comparison:
2196+
Node* inner_result_long;
2197+
if (is_positive_stride) {
2198+
inner_result_long = MaxNode::signed_max(limit, _igvn.longcon(min_jint), TypeLong::LONG, _igvn);
2199+
} else {
2200+
inner_result_long = MaxNode::signed_min(limit, _igvn.longcon(max_jint), TypeLong::LONG, _igvn);
2201+
}
2202+
set_subtree_ctrl(inner_result_long);
2203+
2204+
// Outer MINL/MAXL:
2205+
// The comparison is done with long values but the result is the converted back to int by using CmovI.
2206+
Node* old_limit_long = new ConvI2LNode(old_limit);
2207+
register_new_node(old_limit_long, pre_ctrl);
2208+
Node* cmp = new CmpLNode(old_limit_long, limit);
21872209
register_new_node(cmp, pre_ctrl);
2188-
Node* bol = new BoolNode(cmp, is_positive_stride ? BoolTest::lt : BoolTest::gt);
2210+
Node* bol = new BoolNode(cmp, is_positive_stride ? BoolTest::gt : BoolTest::lt);
21892211
register_new_node(bol, pre_ctrl);
2190-
limit = new ConvL2INode(limit);
2191-
register_new_node(limit, pre_ctrl);
2192-
limit = new CMoveINode(bol, limit, _igvn.intcon(is_positive_stride ? min_jint : max_jint), TypeInt::INT);
2193-
register_new_node(limit, pre_ctrl);
2194-
2195-
limit = is_positive_stride ? (Node*)(new MinINode(old_limit, limit))
2196-
: (Node*)(new MaxINode(old_limit, limit));
2212+
Node* inner_result_int = new ConvL2INode(inner_result_long); // Could under-/overflow but that's fine as comparison was done with CmpL
2213+
register_new_node(inner_result_int, pre_ctrl);
2214+
limit = new CMoveINode(bol, old_limit, inner_result_int, TypeInt::INT);
21972215
register_new_node(limit, pre_ctrl);
21982216
return limit;
21992217
}
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)