From b9f7bd2be81421e4198c57ed77e8c0bee3bf197b Mon Sep 17 00:00:00 2001 From: Emanuel Peter Date: Mon, 15 Jun 2026 07:08:29 +0000 Subject: [PATCH] 8386482: C2 CountedLoopConverter::filtered_type_from_dominators: assert(_base == Int) failed: Not an Int Reviewed-by: kvn, qamai --- src/hotspot/share/opto/loopnode.cpp | 11 +++- .../loopopts/TestTruncationWrapEmptyType.java | 65 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/hotspot/jtreg/compiler/loopopts/TestTruncationWrapEmptyType.java diff --git a/src/hotspot/share/opto/loopnode.cpp b/src/hotspot/share/opto/loopnode.cpp index 13feeb77947..7c62e313803 100644 --- a/src/hotspot/share/opto/loopnode.cpp +++ b/src/hotspot/share/opto/loopnode.cpp @@ -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(); } } } diff --git a/test/hotspot/jtreg/compiler/loopopts/TestTruncationWrapEmptyType.java b/test/hotspot/jtreg/compiler/loopopts/TestTruncationWrapEmptyType.java new file mode 100644 index 00000000000..5d6d49796f2 --- /dev/null +++ b/test/hotspot/jtreg/compiler/loopopts/TestTruncationWrapEmptyType.java @@ -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; + } +}