diff --git a/src/hotspot/share/opto/parse2.cpp b/src/hotspot/share/opto/parse2.cpp index a7c5398171b6c..24ca68ea86b5f 100644 --- a/src/hotspot/share/opto/parse2.cpp +++ b/src/hotspot/share/opto/parse2.cpp @@ -1803,8 +1803,8 @@ static bool match_type_check(PhaseGVN& gvn, assert(idx == 1 || idx == 2, ""); Node* vcon = val->in(idx); - assert(val->find_edge(con) > 0, ""); if ((btest == BoolTest::eq && vcon == con) || (btest == BoolTest::ne && vcon != con)) { + assert(val->find_edge(con) > 0, ""); SubTypeCheckNode* sub = b1->in(1)->as_SubTypeCheck(); Node* obj_or_subklass = sub->in(SubTypeCheckNode::ObjOrSubKlass); Node* superklass = sub->in(SubTypeCheckNode::SuperKlass); diff --git a/test/hotspot/jtreg/compiler/types/TestSubTypeCheckMismatch.java b/test/hotspot/jtreg/compiler/types/TestSubTypeCheckMismatch.java new file mode 100644 index 0000000000000..dfd62123a11ab --- /dev/null +++ b/test/hotspot/jtreg/compiler/types/TestSubTypeCheckMismatch.java @@ -0,0 +1,50 @@ +/* + * 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. + */ + +/** + * @test + * @bug 8374496 + * @summary "C2: assert(val->find_edge(con) > 0) failed" + * + * @run main/othervm -Xbatch compiler.types.TestSubTypeCheckMismatch + */ +package compiler.types; + +public class TestSubTypeCheckMismatch { + static class A {} + + static Integer test(Object o, int a, int b) { + int i = -1; + if (o instanceof A) { // results in SubTypeCheck node and diamond-shape if + i = Math.min(a, b); + } + return Integer.valueOf(i); // late inlined + } + + public static void main(String[] args) { + for (int i = 0; i < 20_000; i++) { + test(new A(), 0, 0); + test(new Object(), 0, 0); + } + } +}