Skip to content

Commit 1f0dfdb

Browse files
8360561: PhaseIdealLoop::create_new_if_for_predicate hits "must be a uct if pattern" assert
Reviewed-by: mhaessig, thartmann, qamai
1 parent 0b8ae26 commit 1f0dfdb

File tree

4 files changed

+228
-0
lines changed

4 files changed

+228
-0
lines changed

src/hotspot/share/opto/subnode.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,11 @@ const Type *CmpINode::sub( const Type *t1, const Type *t2 ) const {
694694
return TypeInt::CC_LE;
695695
else if( r0->_lo == r1->_hi ) // Range is never low?
696696
return TypeInt::CC_GE;
697+
698+
const Type* joined = r0->join(r1);
699+
if (joined == Type::TOP) {
700+
return TypeInt::CC_NE;
701+
}
697702
return TypeInt::CC; // else use worst case results
698703
}
699704

@@ -798,6 +803,12 @@ const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const {
798803
// looks at the structure of the node in any other case.)
799804
if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check())
800805
return TypeInt::CC_LT;
806+
807+
const Type* joined = r0->join(r1);
808+
if (joined == Type::TOP) {
809+
return TypeInt::CC_NE;
810+
}
811+
801812
return TypeInt::CC; // else use worst case results
802813
}
803814

@@ -939,6 +950,12 @@ const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const {
939950
return TypeInt::CC_LE;
940951
else if( r0->_lo == r1->_hi ) // Range is never low?
941952
return TypeInt::CC_GE;
953+
954+
const Type* joined = r0->join(r1);
955+
if (joined == Type::TOP) {
956+
return TypeInt::CC_NE;
957+
}
958+
942959
return TypeInt::CC; // else use worst case results
943960
}
944961

@@ -993,6 +1010,11 @@ const Type* CmpULNode::sub(const Type* t1, const Type* t2) const {
9931010
}
9941011
}
9951012

1013+
const Type* joined = r0->join(r1);
1014+
if (joined == Type::TOP) {
1015+
return TypeInt::CC_NE;
1016+
}
1017+
9961018
return TypeInt::CC; // else use worst case results
9971019
}
9981020

@@ -1368,6 +1390,10 @@ const Type *BoolTest::cc2logical( const Type *CC ) const {
13681390
if( _test == le ) return TypeInt::ONE;
13691391
if( _test == gt ) return TypeInt::ZERO;
13701392
}
1393+
if( CC == TypeInt::CC_NE ) {
1394+
if( _test == ne ) return TypeInt::ONE;
1395+
if( _test == eq ) return TypeInt::ZERO;
1396+
}
13711397

13721398
return TypeInt::BOOL;
13731399
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2025, 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 8360561
27+
* @summary Ranges can be proven to be disjoint but not orderable (thanks to unsigned range)
28+
* Comparing such values in such range with != should always be true.
29+
* @run main/othervm -Xcomp
30+
* -XX:CompileCommand=compileonly,compiler.igvn.CmpDisjointButNonOrderedRanges::*
31+
* compiler.igvn.CmpDisjointButNonOrderedRanges
32+
* @run main compiler.igvn.CmpDisjointButNonOrderedRanges
33+
*/
34+
package compiler.igvn;
35+
36+
public class CmpDisjointButNonOrderedRanges {
37+
static boolean bFld;
38+
39+
public static void main(String[] strArr) {
40+
test();
41+
}
42+
43+
static void test() {
44+
int x = 7;
45+
int y = 4;
46+
for (int i = 3; i < 12; i++) {
47+
// x = 7 \/ x = -195 => x \in [-195, 7] as a signed value
48+
// but [7, bitwise_cast_uint(-195)] as unsigned
49+
// So 0 is not possible.
50+
if (x != 0) {
51+
A.foo();
52+
// Because A is not loaded, A.foo() traps and this point is not reachable.
53+
}
54+
// x is tighten to be in the meet (so Hotspot's join) of [0, 0] and [7, bitwise_cast_uint(-195)]
55+
// that is bottom (Hotspot's top). Data is dead, control needs to be dead as well.
56+
for (int j = 1; j < 8; j++) {
57+
x = -195;
58+
if (bFld) {
59+
y += 2;
60+
}
61+
}
62+
}
63+
}
64+
65+
static void foo() {
66+
}
67+
}
68+
69+
70+
class A {
71+
static void foo() {
72+
}
73+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2025, 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 8360561
27+
* @summary Ranges can be proven to be disjoint but not orderable (thanks to unsigned range)
28+
* Comparing such values in such range with != should always be true.
29+
* @run main/othervm -Xbatch
30+
* -XX:CompileCommand=compileonly,compiler.igvn.CmpDisjointButNonOrderedRanges2::*
31+
* -XX:-TieredCompilation
32+
* -XX:+UnlockExperimentalVMOptions
33+
* -XX:PerMethodTrapLimit=0
34+
* compiler.igvn.CmpDisjointButNonOrderedRanges2
35+
* @run main compiler.igvn.CmpDisjointButNonOrderedRanges2
36+
*/
37+
package compiler.igvn;
38+
39+
public class CmpDisjointButNonOrderedRanges2 {
40+
int array[];
41+
42+
void test() {
43+
int val = 2;
44+
for (int i = 0; i < 10; i++) {
45+
// val = 2 \/ val = -12 => val \in [-12, 2] as a signed value
46+
// but [2, bitwise_cast_uint(-12)] as unsigned
47+
// So 0 is not possible.
48+
if (val != 0) {
49+
return;
50+
}
51+
// val is tighten to be in the meet (so Hotspot's join) of [0, 0] and [2, bitwise_cast_uint(-12)]
52+
// that is bottom (Hotspot's top). Data is dead, control needs to be dead as well.
53+
for (int j = 0; j < 10; j++) {
54+
array[1] = val;
55+
val = -12;
56+
}
57+
}
58+
}
59+
60+
static public void main(String[] args) {
61+
var c = new CmpDisjointButNonOrderedRanges2();
62+
for (int i = 0; i < 1000; ++i) {
63+
c.test();
64+
for (int j = 0; j < 100; ++j) {
65+
}
66+
}
67+
}
68+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2025, 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 8360561
27+
* @summary Ranges can be proven to be disjoint but not orderable (thanks to unsigned range)
28+
* Comparing such values in such range with != should always be true.
29+
* @library /test/lib /
30+
* @run main compiler.igvn.CmpDisjointButNonOrderedRangesLong
31+
*/
32+
package compiler.igvn;
33+
34+
import compiler.lib.ir_framework.*;
35+
36+
public class CmpDisjointButNonOrderedRangesLong {
37+
static boolean bFld;
38+
static double dFld1;
39+
static double dFld2;
40+
41+
public static void main(String[] strArr) {
42+
TestFramework.run();
43+
}
44+
45+
@Test
46+
@IR(failOn = {IRNode.PHI})
47+
@Warmup(0)
48+
static int test() {
49+
long x = 7;
50+
if (bFld) {
51+
x = -195;
52+
}
53+
54+
dFld1 = dFld2 % 2.5;
55+
56+
if (x == 0) {
57+
return 0;
58+
}
59+
return 1;
60+
}
61+
}

0 commit comments

Comments
 (0)