From 57c3bb6091f8ba0caced6f5ecf21dc998ffeee9f Mon Sep 17 00:00:00 2001 From: Roland Westrelin Date: Wed, 6 Nov 2024 14:47:14 +0000 Subject: [PATCH] 8343068: C2: CastX2P Ideal transformation not always applied Reviewed-by: kvn, thartmann --- src/hotspot/share/opto/phaseX.cpp | 8 ++ .../c2/TestCastX2NotProcessedIGVN.java | 80 +++++++++++++++++++ .../compiler/lib/ir_framework/IRNode.java | 5 ++ 3 files changed, 93 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/c2/TestCastX2NotProcessedIGVN.java diff --git a/src/hotspot/share/opto/phaseX.cpp b/src/hotspot/share/opto/phaseX.cpp index dae4a5c68a3..f766146a894 100644 --- a/src/hotspot/share/opto/phaseX.cpp +++ b/src/hotspot/share/opto/phaseX.cpp @@ -1695,6 +1695,14 @@ void PhaseIterGVN::add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_ worklist.push(cmp); } } + if (use->Opcode() == Op_AddX) { + for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) { + Node* u = use->fast_out(i2); + if (u->Opcode() == Op_CastX2P) { + worklist.push(u); + } + } + } } /** diff --git a/test/hotspot/jtreg/compiler/c2/TestCastX2NotProcessedIGVN.java b/test/hotspot/jtreg/compiler/c2/TestCastX2NotProcessedIGVN.java new file mode 100644 index 00000000000..6ab45af39c5 --- /dev/null +++ b/test/hotspot/jtreg/compiler/c2/TestCastX2NotProcessedIGVN.java @@ -0,0 +1,80 @@ +/* + * 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. + */ + +package compiler.c2; + +import compiler.lib.ir_framework.*; +import jdk.internal.misc.Unsafe; + +/* + * @test + * @bug 8343068 + * @summary C2: CastX2P Ideal transformation not always applied + * @modules java.base/jdk.internal.misc + * @library /test/lib / + * @run driver compiler.c2.TestCastX2NotProcessedIGVN + */ + +public class TestCastX2NotProcessedIGVN { + private static final Unsafe UNSAFE = Unsafe.getUnsafe(); + static int size = 1024; + static long base = UNSAFE.allocateMemory(4 * size); + + + public static void main(String[] args) { + TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED"); + } + + @Test + @IR(failOn = IRNode.ADD_L, counts = {IRNode.ADD_P, "1"}) + public static byte test1(long base) { + int offset = 0; + do { + offset++; + } while (offset < 100); + long longOffset = ((long) offset) * 2; + return UNSAFE.getByte(null, base + longOffset); + } + + @Run(test = "test1") + public static void test1Runner() { + test1(base); + } + + @Test + @IR(counts = {IRNode.LOAD_VECTOR_I, "> 1"}) + public static int test2(int stop, int[] array) { + int v = 0; + stop = Math.min(stop, Integer.MAX_VALUE / 4); + for (int i = 0; i < stop; i++) { + long offset = ((long)i) * 4; + array[i] = UNSAFE.getInt(null, offset + base); + } + return v; + } + + @Run(test = "test2") + public static void test2Runner() { + test2(size, new int[size]); + } +} diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java b/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java index 8c4b3c93343..fc55662d801 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java @@ -219,6 +219,11 @@ public class IRNode { beforeMatchingNameRegex(ADD_L, "AddL"); } + public static final String ADD_P = PREFIX + "ADD_P" + POSTFIX; + static { + beforeMatchingNameRegex(ADD_P, "AddP"); + } + public static final String ADD_VD = VECTOR_PREFIX + "ADD_VD" + POSTFIX; static { vectorNode(ADD_VD, "AddVD", TYPE_DOUBLE);