Skip to content

Commit 385e34d

Browse files
franferraxmartinuy
authored andcommitted
8262017: C2: assert(n != __null) failed: Bad immediate dominator info.
8205407: [windows, vs<2017] C4800 after 8203197 Reviewed-by: mbalao, roland Backport-of: 2db9005c07585b580b3ec0889b8b5e3ed0d0ca6a
1 parent 44eac48 commit 385e34d

File tree

5 files changed

+308
-13
lines changed

5 files changed

+308
-13
lines changed

hotspot/make/windows/makefiles/compile.make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ CXX=cl.exe
5353
# improving the quality of crash log stack traces involving jvm.dll.
5454

5555
# These are always used in all compiles
56-
CXX_FLAGS=$(EXTRA_CFLAGS) /nologo /W3 /WX
56+
CXX_FLAGS=$(EXTRA_CFLAGS) /nologo /W3 /WX /wd4800
5757

5858
# Let's add debug information when Full Debug Symbols is enabled
5959
!if "$(ENABLE_FULL_DEBUG_SYMBOLS)" == "1"

hotspot/src/share/vm/opto/addnode.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,95 @@ const Type *XorLNode::add_ring( const Type *t0, const Type *t1 ) const {
833833
return TypeLong::make( r0->get_con() ^ r1->get_con() );
834834
}
835835

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 (gvn.C) 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 (gvn.C) CmpLNode(a, b));
849+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
850+
return gvn.transform(new (gvn.C) CMoveLNode(bol, a, b, t->is_long()));
851+
}
852+
} else {
853+
if (is_int) {
854+
Node* res = gvn.transform(new (gvn.C) 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 (gvn.C) CmpLNode(b, a));
859+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
860+
return gvn.transform(new (gvn.C) 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 (gvn.C) CmpUNode(a, b));
867+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
868+
return gvn.transform(new (gvn.C) CMoveINode(bol, a, b, t->is_int()));
869+
} else {
870+
Node* cmp = gvn.transform(new (gvn.C) CmpULNode(a, b));
871+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
872+
return gvn.transform(new (gvn.C) CMoveLNode(bol, a, b, t->is_long()));
873+
}
874+
} else {
875+
if (is_int) {
876+
Node* cmp = gvn.transform(new (gvn.C) CmpUNode(b, a));
877+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
878+
return gvn.transform(new (gvn.C) CMoveINode(bol, a, b, t->is_int()));
879+
} else {
880+
Node* cmp = gvn.transform(new (gvn.C) CmpULNode(b, a));
881+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
882+
return gvn.transform(new (gvn.C) 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 (gvn.C) CmpINode(a, b));
901+
Node* sub = gvn.transform(new (gvn.C) SubINode(a, b));
902+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
903+
return gvn.transform(new (gvn.C) CMoveINode(bol, sub, zero, t->is_int()));
904+
} else {
905+
Node* cmp = gvn.transform(new (gvn.C) CmpLNode(a, b));
906+
Node* sub = gvn.transform(new (gvn.C) SubLNode(a, b));
907+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
908+
return gvn.transform(new (gvn.C) CMoveLNode(bol, sub, zero, t->is_long()));
909+
}
910+
} else {
911+
if (is_int) {
912+
Node* cmp = gvn.transform(new (gvn.C) CmpINode(b, a));
913+
Node* sub = gvn.transform(new (gvn.C) SubINode(a, b));
914+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
915+
return gvn.transform(new (gvn.C) CMoveINode(bol, sub, zero, t->is_int()));
916+
} else {
917+
Node* cmp = gvn.transform(new (gvn.C) CmpLNode(b, a));
918+
Node* sub = gvn.transform(new (gvn.C) SubLNode(a, b));
919+
Node* bol = gvn.transform(new (gvn.C) BoolNode(cmp, BoolTest::lt));
920+
return gvn.transform(new (gvn.C) CMoveLNode(bol, sub, zero, t->is_long()));
921+
}
922+
}
923+
}
924+
836925
//=============================================================================
837926
//------------------------------add_ring---------------------------------------
838927
// Supplied function returns the sum of the inputs.

hotspot/src/share/vm/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---------------------------------------

hotspot/src/share/vm/opto/loopTransform.cpp

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

1547-
// Clamp the limit to handle integer under-/overflows.
1547+
// Clamp the limit to handle integer under-/overflows by using long values.
1548+
// We only convert the limit back to int when we handled under-/overflows.
1549+
// Note that all values are longs in the following computations.
15481550
// When reducing the limit, clamp to [min_jint, old_limit]:
1549-
// MIN(old_limit, MAX(limit, min_jint))
1551+
// INT(MINL(old_limit, MAXL(limit, min_jint)))
1552+
// - integer underflow of limit: MAXL chooses min_jint.
1553+
// - integer overflow of limit: MINL chooses old_limit (<= MAX_INT < limit)
15501554
// When increasing the limit, clamp to [old_limit, max_jint]:
1551-
// MAX(old_limit, MIN(limit, max_jint))
1552-
Node* cmp = new (C) CmpLNode(limit, _igvn.longcon(is_positive_stride ? min_jint : max_jint));
1555+
// INT(MAXL(old_limit, MINL(limit, max_jint)))
1556+
// - integer overflow of limit: MINL chooses max_jint.
1557+
// - integer underflow of limit: MAXL chooses old_limit (>= MIN_INT > limit)
1558+
// INT() is finally converting the limit back to an integer value.
1559+
1560+
// We use CMove nodes to implement long versions of min/max (MINL/MAXL).
1561+
// We use helper methods for inner MINL/MAXL which return CMoveL nodes to keep a long value for the outer MINL/MAXL comparison:
1562+
Node* inner_result_long;
1563+
if (is_positive_stride) {
1564+
inner_result_long = MaxNode::signed_max(limit, _igvn.longcon(min_jint), TypeLong::LONG, _igvn);
1565+
} else {
1566+
inner_result_long = MaxNode::signed_min(limit, _igvn.longcon(max_jint), TypeLong::LONG, _igvn);
1567+
}
1568+
set_subtree_ctrl(inner_result_long);
1569+
1570+
// Outer MINL/MAXL:
1571+
// The comparison is done with long values but the result is the converted back to int by using CmovI.
1572+
Node* old_limit_long = new (C) ConvI2LNode(old_limit);
1573+
register_new_node(old_limit_long, pre_ctrl);
1574+
Node* cmp = new (C) CmpLNode(old_limit_long, limit);
15531575
register_new_node(cmp, pre_ctrl);
1554-
Node* bol = new (C) BoolNode(cmp, is_positive_stride ? BoolTest::lt : BoolTest::gt);
1576+
Node* bol = new (C) BoolNode(cmp, is_positive_stride ? BoolTest::gt : BoolTest::lt);
15551577
register_new_node(bol, pre_ctrl);
1556-
limit = new (C) ConvL2INode(limit);
1557-
register_new_node(limit, pre_ctrl);
1558-
limit = new (C) CMoveINode(bol, limit, _igvn.intcon(is_positive_stride ? min_jint : max_jint), TypeInt::INT);
1559-
register_new_node(limit, pre_ctrl);
1560-
1561-
limit = is_positive_stride ? (Node*)(new (C) MinINode(old_limit, limit))
1562-
: (Node*)(new (C) MaxINode(old_limit, limit));
1578+
Node* inner_result_int = new (C) ConvL2INode(inner_result_long); // Could under-/overflow but that's fine as comparison was done with CmpL
1579+
register_new_node(inner_result_int, pre_ctrl);
1580+
limit = new (C) CMoveINode(bol, old_limit, inner_result_int, TypeInt::INT);
15631581
register_new_node(limit, pre_ctrl);
15641582
return limit;
15651583
}
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)