Skip to content

Commit 57c3bb6

Browse files
committedNov 6, 2024
8343068: C2: CastX2P Ideal transformation not always applied
Reviewed-by: kvn, thartmann
1 parent 83f3d42 commit 57c3bb6

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
 

‎src/hotspot/share/opto/phaseX.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,14 @@ void PhaseIterGVN::add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_
16951695
worklist.push(cmp);
16961696
}
16971697
}
1698+
if (use->Opcode() == Op_AddX) {
1699+
for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
1700+
Node* u = use->fast_out(i2);
1701+
if (u->Opcode() == Op_CastX2P) {
1702+
worklist.push(u);
1703+
}
1704+
}
1705+
}
16981706
}
16991707

17001708
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2024, Red Hat, Inc. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package compiler.c2;
25+
26+
import compiler.lib.ir_framework.*;
27+
import jdk.internal.misc.Unsafe;
28+
29+
/*
30+
* @test
31+
* @bug 8343068
32+
* @summary C2: CastX2P Ideal transformation not always applied
33+
* @modules java.base/jdk.internal.misc
34+
* @library /test/lib /
35+
* @run driver compiler.c2.TestCastX2NotProcessedIGVN
36+
*/
37+
38+
public class TestCastX2NotProcessedIGVN {
39+
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
40+
static int size = 1024;
41+
static long base = UNSAFE.allocateMemory(4 * size);
42+
43+
44+
public static void main(String[] args) {
45+
TestFramework.runWithFlags("--add-modules", "java.base", "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED");
46+
}
47+
48+
@Test
49+
@IR(failOn = IRNode.ADD_L, counts = {IRNode.ADD_P, "1"})
50+
public static byte test1(long base) {
51+
int offset = 0;
52+
do {
53+
offset++;
54+
} while (offset < 100);
55+
long longOffset = ((long) offset) * 2;
56+
return UNSAFE.getByte(null, base + longOffset);
57+
}
58+
59+
@Run(test = "test1")
60+
public static void test1Runner() {
61+
test1(base);
62+
}
63+
64+
@Test
65+
@IR(counts = {IRNode.LOAD_VECTOR_I, "> 1"})
66+
public static int test2(int stop, int[] array) {
67+
int v = 0;
68+
stop = Math.min(stop, Integer.MAX_VALUE / 4);
69+
for (int i = 0; i < stop; i++) {
70+
long offset = ((long)i) * 4;
71+
array[i] = UNSAFE.getInt(null, offset + base);
72+
}
73+
return v;
74+
}
75+
76+
@Run(test = "test2")
77+
public static void test2Runner() {
78+
test2(size, new int[size]);
79+
}
80+
}

‎test/hotspot/jtreg/compiler/lib/ir_framework/IRNode.java

+5
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ public class IRNode {
219219
beforeMatchingNameRegex(ADD_L, "AddL");
220220
}
221221

222+
public static final String ADD_P = PREFIX + "ADD_P" + POSTFIX;
223+
static {
224+
beforeMatchingNameRegex(ADD_P, "AddP");
225+
}
226+
222227
public static final String ADD_VD = VECTOR_PREFIX + "ADD_VD" + POSTFIX;
223228
static {
224229
vectorNode(ADD_VD, "AddVD", TYPE_DOUBLE);

0 commit comments

Comments
 (0)
Please sign in to comment.