From 2820c789fa6daf625b1f0f6bfe03a7c3eb428d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20H=C3=A4ssig?= Date: Mon, 1 Jun 2026 07:26:30 +0000 Subject: [PATCH] 8385408: C2: no reachable node should have no use Reviewed-by: dlong, kvn --- src/hotspot/share/opto/mulnode.cpp | 3 +- .../compiler/igvn/TestShiftWorklist.java | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/hotspot/jtreg/compiler/igvn/TestShiftWorklist.java diff --git a/src/hotspot/share/opto/mulnode.cpp b/src/hotspot/share/opto/mulnode.cpp index 5e05d6a6e04..e48acd23b87 100644 --- a/src/hotspot/share/opto/mulnode.cpp +++ b/src/hotspot/share/opto/mulnode.cpp @@ -894,7 +894,8 @@ static Node* mask_and_replace_shift_amount(PhaseGVN* phase, Node* shift_node, ui } if (replace) { - shift_node->set_req(2, phase->intcon(masked_shift)); // Replace shift count with masked value. + // Replace shift count with masked value and put potential dead nodes on the worklist. + shift_node->set_req_X(2, phase->intcon(masked_shift), phase); // We need to notify the caller that the graph was reshaped, as Ideal needs // to return the root of the reshaped graph if any change was made. diff --git a/test/hotspot/jtreg/compiler/igvn/TestShiftWorklist.java b/test/hotspot/jtreg/compiler/igvn/TestShiftWorklist.java new file mode 100644 index 00000000000..64c5a5fe658 --- /dev/null +++ b/test/hotspot/jtreg/compiler/igvn/TestShiftWorklist.java @@ -0,0 +1,75 @@ +/* + * 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 8385408 + * @summary Test that inputs to removed shifts are put on the worklist and cleaned up + * @library /test/lib / + * @run main/othervm -Xbatch -XX:-TieredCompilation -XX:-UseOnStackReplacement + * -XX:CompileCommand=compileonly,${test.main.class}::test + * ${test.main.class} + * @run main ${test.main.class} + */ + +package compiler.igvn; + +import jdk.test.lib.Asserts; + +public class TestShiftWorklist { + int N = 400; + int iArr[] = new int[N]; + + public static void main(String[] args) { + TestShiftWorklist t = new TestShiftWorklist(); + for (int i = 0; i < 2_000; i++) { + int result = t.test(); + Asserts.assertEQ(result, 0); + } + } + + private int test() { + long[] lArr = new long[N]; + long l = 1957; // l % 32 = 5 + int n = 1; + for (int i = 1; i < 30; ++i) { + for (double j = 1; j < 12; j++) { + iArr[i] = 3; + for (long k = 1; k < 2; k++) { + // C2 is able to prove that the effecive shift value for the int n is always 5. + n >>= l; + } + l = 907436423360901L; // l % 32 = 5 + } + } + return (int) checkSum(lArr); + } + + private static long checkSum(long[] a) { + long sum = 0; + for (int j = 0; j < a.length; j++) { + sum += (a[j] / (j + 1) + a[j] % (j + 1)); + } + return sum; + } +}