Skip to content

Commit b4c163d

Browse files
committed
8319372: C2 compilation fails with "Bad immediate dominator info"
Backport-of: 7766785098816cfcdae3479540cdc866c1ed18ad
1 parent 0ac1bb7 commit b4c163d

File tree

4 files changed

+171
-73
lines changed

4 files changed

+171
-73
lines changed

src/hotspot/share/opto/castnode.cpp

-73
Original file line numberDiff line numberDiff line change
@@ -262,79 +262,6 @@ const Type* CastIINode::Value(PhaseGVN* phase) const {
262262
res = widen_type(phase, res, T_INT);
263263
}
264264

265-
// Try to improve the type of the CastII if we recognize a CmpI/If pattern.
266-
//
267-
// in1 in2
268-
// | |
269-
// +--- | --+
270-
// | | |
271-
// CmpINode |
272-
// | |
273-
// BoolNode |
274-
// | |
275-
// IfNode |
276-
// | |
277-
// IfProj |
278-
// | |
279-
// CastIINode
280-
//
281-
if (carry_dependency()) {
282-
if (in(0) != nullptr && in(0)->in(0) != nullptr && in(0)->in(0)->is_If()) {
283-
assert(in(0)->is_IfFalse() || in(0)->is_IfTrue(), "should be If proj");
284-
Node* proj = in(0);
285-
if (proj->in(0)->in(1)->is_Bool()) {
286-
Node* b = proj->in(0)->in(1);
287-
if (b->in(1)->Opcode() == Op_CmpI) {
288-
Node* cmp = b->in(1);
289-
if (cmp->in(1) == in(1) && phase->type(cmp->in(2))->isa_int()) {
290-
const TypeInt* in2_t = phase->type(cmp->in(2))->is_int();
291-
const Type* t = TypeInt::INT;
292-
BoolTest test = b->as_Bool()->_test;
293-
if (proj->is_IfFalse()) {
294-
test = test.negate();
295-
}
296-
BoolTest::mask m = test._test;
297-
jlong lo_long = min_jint;
298-
jlong hi_long = max_jint;
299-
if (m == BoolTest::le || m == BoolTest::lt) {
300-
hi_long = in2_t->_hi;
301-
if (m == BoolTest::lt) {
302-
hi_long -= 1;
303-
}
304-
} else if (m == BoolTest::ge || m == BoolTest::gt) {
305-
lo_long = in2_t->_lo;
306-
if (m == BoolTest::gt) {
307-
lo_long += 1;
308-
}
309-
} else if (m == BoolTest::eq) {
310-
lo_long = in2_t->_lo;
311-
hi_long = in2_t->_hi;
312-
} else if (m == BoolTest::ne) {
313-
// can't do any better
314-
} else {
315-
stringStream ss;
316-
test.dump_on(&ss);
317-
fatal("unexpected comparison %s", ss.freeze());
318-
}
319-
int lo_int = (int)lo_long;
320-
int hi_int = (int)hi_long;
321-
322-
if (lo_long != (jlong)lo_int) {
323-
lo_int = min_jint;
324-
}
325-
if (hi_long != (jlong)hi_int) {
326-
hi_int = max_jint;
327-
}
328-
329-
t = TypeInt::make(lo_int, hi_int, Type::WidenMax);
330-
331-
res = res->filter_speculative(t);
332-
return res;
333-
}
334-
}
335-
}
336-
}
337-
}
338265
return res;
339266
}
340267

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 8319372
27+
* @summary CastII because of condition guarding it becomes top
28+
* @requires vm.compiler2.enabled
29+
* @run main/othervm -Xcomp -XX:CompileOnly=TestTopCastIIOnUndetectedDeadPath::test -XX:CompileCommand=quiet -XX:-TieredCompilation
30+
* -XX:+UnlockDiagnosticVMOptions -XX:StressSeed=426264791 -XX:+StressIGVN TestTopCastIIOnUndetectedDeadPath
31+
* @run main/othervm -Xcomp -XX:CompileOnly=TestTopCastIIOnUndetectedDeadPath::test -XX:CompileCommand=quiet -XX:-TieredCompilation
32+
* -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN TestTopCastIIOnUndetectedDeadPath
33+
*/
34+
35+
public class TestTopCastIIOnUndetectedDeadPath {
36+
static class X {
37+
static void m(int[] a) {
38+
39+
}
40+
}
41+
42+
static int array[] = new int[10];
43+
44+
static void test(int val) {
45+
for (int i = 1; i < 10; ++i) {
46+
for (int j = i; j < 10; ++j) {
47+
if (i == 0 && j != 0) {
48+
X.m(array);
49+
}
50+
array[j - 1] = val;
51+
}
52+
}
53+
}
54+
55+
public static void main(String[] arg) {
56+
test(42);
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 8319372
27+
* @summary CastII because of condition guarding it becomes top
28+
* @requires vm.compiler2.enabled
29+
* @run main/othervm -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,TestTopCastIIOnUndetectedDeadPath2::test -XX:-TieredCompilation
30+
* -Xbatch -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN -XX:StressSeed=256120824 TestTopCastIIOnUndetectedDeadPath2
31+
* @run main/othervm -XX:CompileCommand=quiet -XX:CompileCommand=compileonly,TestTopCastIIOnUndetectedDeadPath2::test -XX:-TieredCompilation
32+
* -Xbatch -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN TestTopCastIIOnUndetectedDeadPath2
33+
*/
34+
35+
public class TestTopCastIIOnUndetectedDeadPath2 {
36+
static int array[] = new int[100];
37+
38+
static int test() {
39+
int res = 0;
40+
for (int i = 1; i < 100; ++i) {
41+
try {
42+
res = array[i - 1];
43+
int x = (42 % i);
44+
} catch (ArithmeticException e) {
45+
}
46+
}
47+
return res;
48+
}
49+
50+
public static void main(String[] args) {
51+
for (int i = 0; i < 10_000; i++) {
52+
test();
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 8319372
27+
* @summary CastII because of condition guarding it becomes top
28+
* @run main/othervm -Xcomp -XX:CompileOnly=TestTopCastIIOnUndetectedDeadPath3::* -XX:-TieredCompilation TestTopCastIIOnUndetectedDeadPath3
29+
*/
30+
31+
public class TestTopCastIIOnUndetectedDeadPath3 {
32+
33+
static long test() {
34+
int x = 6, y = 5;
35+
int[] iArr = new int[200];
36+
for (int i = 129; i > 5; i -= 2) { // OSR compiled
37+
try {
38+
y = iArr[i - 1];
39+
x = iArr[i + 1];
40+
x = 1 / i;
41+
} catch (ArithmeticException a_e) {
42+
}
43+
}
44+
Foo.empty();
45+
return x + y;
46+
}
47+
48+
public static void main(String[] strArr) {
49+
new TestTopCastIIOnUndetectedDeadPath3();
50+
for (int i = 0; i < 2000; i++) {
51+
test();
52+
}
53+
}
54+
}
55+
56+
class Foo {
57+
public static void empty() {}
58+
}

0 commit comments

Comments
 (0)