From 053ff76e14046f796f6e10a9cb2ede1f1ae22ed6 Mon Sep 17 00:00:00 2001 From: Roland Westrelin Date: Tue, 19 Mar 2024 07:57:53 +0000 Subject: [PATCH] 8308660: C2 compilation hits 'node must be dead' assert Reviewed-by: chagedorn, kvn --- src/hotspot/share/opto/ifnode.cpp | 4 ++ .../compiler/c2/TestFoldIfRemovesTopNode.java | 69 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/c2/TestFoldIfRemovesTopNode.java diff --git a/src/hotspot/share/opto/ifnode.cpp b/src/hotspot/share/opto/ifnode.cpp index 0e21933b6de..9760be95ddd 100644 --- a/src/hotspot/share/opto/ifnode.cpp +++ b/src/hotspot/share/opto/ifnode.cpp @@ -1051,6 +1051,10 @@ bool IfNode::fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* f } hook->destruct(igvn); + if (adjusted_val->is_top() || adjusted_lim->is_top()) { + return false; + } + if (igvn->type(adjusted_lim)->is_int()->_lo < 0 && !igvn->C->post_loop_opts_phase()) { // If range check elimination applies to this comparison, it includes code to protect from overflows that may diff --git a/test/hotspot/jtreg/compiler/c2/TestFoldIfRemovesTopNode.java b/test/hotspot/jtreg/compiler/c2/TestFoldIfRemovesTopNode.java new file mode 100644 index 00000000000..e36897aa7d8 --- /dev/null +++ b/test/hotspot/jtreg/compiler/c2/TestFoldIfRemovesTopNode.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024, Red Hat, Inc. 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 8308660 + * @summary C2 compilation hits 'node must be dead' assert + * @requires vm.compiler2.enabled + * @run main/othervm -XX:-BackgroundCompilation -XX:-TieredCompilation -XX:-UseOnStackReplacement + * -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN -XX:StressSeed=242006623 TestFoldIfRemovesTopNode + * @run main/othervm -XX:-BackgroundCompilation -XX:-TieredCompilation -XX:-UseOnStackReplacement + * -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN TestFoldIfRemovesTopNode + * + */ + +public class TestFoldIfRemovesTopNode { + + public static void main(String[] args) { + int[] array = new int[100]; + for (int i = 0; i < 20_000; i++) { + test(false, true, 0, array); + test(false, false, 0, array); + testHelper2(false, false, 0, array); + testHelper(0, true, array); + } + } + + private static void test(boolean flag, boolean flag2, int k, int[] array) { + if (flag2) { + testHelper2(flag, flag2, k, array); + } + } + + private static void testHelper2(boolean flag, boolean flag2, int k, int[] array) { + if (flag2) { + k = -1; + } + testHelper(k, flag, array); + } + + private static void testHelper(int k, boolean flag, int[] array) { + if (flag) { + k = new int[k].length; + int j = k + 3; + if (j >= 0 && j <= array.length) { + } + } + } +}