8386482: C2 CountedLoopConverter::filtered_type_from_dominators: assert(_base == Int) failed: Not an Int

Reviewed-by: kvn, qamai
This commit is contained in:
Emanuel Peter 2026-06-15 07:08:29 +00:00
parent d4acb51b33
commit b9f7bd2be8
2 changed files with 75 additions and 1 deletions

View File

@ -3892,7 +3892,16 @@ const TypeInt* CountedLoopConverter::filtered_type_from_dominators(Node* val, No
if (rtn_t == nullptr) {
rtn_t = if_t;
} else {
rtn_t = rtn_t->join(if_t)->is_int();
const Type* join_t = rtn_t->join(if_t);
if (!join_t->isa_int()) {
// We may have encountered multiple if conditions, that have no
// overlap, and produce an empty/top type. Returning nullptr
// is conservative, it means we do not constrain the type, which
// will just prevent further optimiziations.
assert(join_t->empty(), "top");
return nullptr;
}
rtn_t = join_t->is_int();
}
}
}

View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package compiler.loopopts;
/*
* @test
* @bug 8386482
* @summary Test case for CountedLoopConverter::filtered_type_from_dominators/
* CountedLoopConverter::has_truncation_wrap where the type becomes
* empty / top. This used to trigger the assert:
* assert(_base == Int) failed: Not an Int
* @library /test/lib /
* @run main/othervm -Xcomp
* -XX:CompileCommand=compileonly,${test.main.class}::test
* ${test.main.class}
* @run main ${test.main.class}
*/
public class TestTruncationWrapEmptyType {
public static void main(String[] args) {
for (int i = 0; i < 10_000; i++) {
test(1);
}
}
static int test(int init) {
if (init < 1) {
return -1;
}
// if implies: init in [1..max_int]
int i = init;
while (i < 0) {
// while implies: init in [min_int .. 0]
// That contradicts the "if" above: empty intersection
//
// See CountedLoopConverter::filtered_type_from_dominators:
// rtn_t = rtn_t->join(if_t)->is_int()
// -> top type in join, fails "is_int".
i = (short)(i + 1);
}
return 0;
}
}