Skip to content

Commit b9f7bd2

Browse files
committed
8386482: C2 CountedLoopConverter::filtered_type_from_dominators: assert(_base == Int) failed: Not an Int
Reviewed-by: kvn, qamai
1 parent d4acb51 commit b9f7bd2

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

src/hotspot/share/opto/loopnode.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3892,7 +3892,16 @@ const TypeInt* CountedLoopConverter::filtered_type_from_dominators(Node* val, No
38923892
if (rtn_t == nullptr) {
38933893
rtn_t = if_t;
38943894
} else {
3895-
rtn_t = rtn_t->join(if_t)->is_int();
3895+
const Type* join_t = rtn_t->join(if_t);
3896+
if (!join_t->isa_int()) {
3897+
// We may have encountered multiple if conditions, that have no
3898+
// overlap, and produce an empty/top type. Returning nullptr
3899+
// is conservative, it means we do not constrain the type, which
3900+
// will just prevent further optimiziations.
3901+
assert(join_t->empty(), "top");
3902+
return nullptr;
3903+
}
3904+
rtn_t = join_t->is_int();
38963905
}
38973906
}
38983907
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2026, 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+
package compiler.loopopts;
25+
26+
/*
27+
* @test
28+
* @bug 8386482
29+
* @summary Test case for CountedLoopConverter::filtered_type_from_dominators/
30+
* CountedLoopConverter::has_truncation_wrap where the type becomes
31+
* empty / top. This used to trigger the assert:
32+
* assert(_base == Int) failed: Not an Int
33+
* @library /test/lib /
34+
* @run main/othervm -Xcomp
35+
* -XX:CompileCommand=compileonly,${test.main.class}::test
36+
* ${test.main.class}
37+
* @run main ${test.main.class}
38+
*/
39+
40+
public class TestTruncationWrapEmptyType {
41+
public static void main(String[] args) {
42+
for (int i = 0; i < 10_000; i++) {
43+
test(1);
44+
}
45+
}
46+
47+
static int test(int init) {
48+
if (init < 1) {
49+
return -1;
50+
}
51+
// if implies: init in [1..max_int]
52+
53+
int i = init;
54+
while (i < 0) {
55+
// while implies: init in [min_int .. 0]
56+
// That contradicts the "if" above: empty intersection
57+
//
58+
// See CountedLoopConverter::filtered_type_from_dominators:
59+
// rtn_t = rtn_t->join(if_t)->is_int()
60+
// -> top type in join, fails "is_int".
61+
i = (short)(i + 1);
62+
}
63+
return 0;
64+
}
65+
}

0 commit comments

Comments
 (0)