8385408: C2: no reachable node should have no use

Reviewed-by: dlong, kvn
This commit is contained in:
Manuel Hässig 2026-06-01 07:26:30 +00:00
parent 3760d75e66
commit 2820c789fa
2 changed files with 77 additions and 1 deletions

View File

@ -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.

View File

@ -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;
}
}