Skip to content

Commit ff75f76

Browse files
Jatin Bhatejaeme64
andcommitted
8351645: C2: Assertion failures in Expand/CompressBits idealizations with TOP
Co-authored-by: Emanuel Peter <epeter@openjdk.org> Reviewed-by: epeter, sviswanathan
1 parent a16d235 commit ff75f76

File tree

2 files changed

+133
-4
lines changed

2 files changed

+133
-4
lines changed

src/hotspot/share/opto/intrinsicnode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Node* CompressBitsNode::Ideal(PhaseGVN* phase, bool can_reshape) {
135135
Node* src = in(1);
136136
Node* mask = in(2);
137137
if (bottom_type()->isa_int()) {
138-
if (mask->Opcode() == Op_LShiftI && phase->type(mask->in(1))->is_int()->is_con()) {
138+
if (mask->Opcode() == Op_LShiftI && phase->type(mask->in(1))->isa_int() && phase->type(mask->in(1))->is_int()->is_con()) {
139139
// compress(x, 1 << n) == (x >> n & 1)
140140
if (phase->type(mask->in(1))->higher_equal(TypeInt::ONE)) {
141141
Node* rshift = phase->transform(new RShiftINode(in(1), mask->in(2)));
@@ -153,7 +153,7 @@ Node* CompressBitsNode::Ideal(PhaseGVN* phase, bool can_reshape) {
153153
}
154154
} else {
155155
assert(bottom_type()->isa_long(), "");
156-
if (mask->Opcode() == Op_LShiftL && phase->type(mask->in(1))->is_long()->is_con()) {
156+
if (mask->Opcode() == Op_LShiftL && phase->type(mask->in(1))->isa_long() && phase->type(mask->in(1))->is_long()->is_con()) {
157157
// compress(x, 1 << n) == (x >> n & 1)
158158
if (phase->type(mask->in(1))->higher_equal(TypeLong::ONE)) {
159159
Node* rshift = phase->transform(new RShiftLNode(in(1), mask->in(2)));
@@ -193,7 +193,7 @@ Node* ExpandBitsNode::Ideal(PhaseGVN* phase, bool can_reshape) {
193193
Node* src = in(1);
194194
Node* mask = in(2);
195195
if (bottom_type()->isa_int()) {
196-
if (mask->Opcode() == Op_LShiftI && phase->type(mask->in(1))->is_int()->is_con()) {
196+
if (mask->Opcode() == Op_LShiftI && phase->type(mask->in(1))->isa_int() && phase->type(mask->in(1))->is_int()->is_con()) {
197197
// expand(x, 1 << n) == (x & 1) << n
198198
if (phase->type(mask->in(1))->higher_equal(TypeInt::ONE)) {
199199
Node* andnode = phase->transform(new AndINode(in(1), phase->makecon(TypeInt::ONE)));
@@ -210,7 +210,7 @@ Node* ExpandBitsNode::Ideal(PhaseGVN* phase, bool can_reshape) {
210210
}
211211
} else {
212212
assert(bottom_type()->isa_long(), "");
213-
if (mask->Opcode() == Op_LShiftL && phase->type(mask->in(1))->is_long()->is_con()) {
213+
if (mask->Opcode() == Op_LShiftL && phase->type(mask->in(1))->isa_long() && phase->type(mask->in(1))->is_long()->is_con()) {
214214
// expand(x, 1 << n) == (x & 1) << n
215215
if (phase->type(mask->in(1))->higher_equal(TypeLong::ONE)) {
216216
Node* andnode = phase->transform(new AndLNode(in(1), phase->makecon(TypeLong::ONE)));
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. 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+
/*
25+
* @test
26+
* @bug 8351645
27+
* @summary C2: ExpandBitsNode::Ideal hits assert because of TOP input
28+
* @library /test/lib /
29+
* @run driver compiler.intrinsics.TestCompressExpandTopInput
30+
*/
31+
32+
package compiler.intrinsics;
33+
34+
import compiler.lib.ir_framework.*;
35+
import compiler.lib.verify.*;
36+
import java.util.stream.IntStream;
37+
import java.util.stream.LongStream;
38+
39+
public class TestCompressExpandTopInput {
40+
41+
public static int [] array_I0 = IntStream.range(0, 10000).toArray();
42+
public static int [] array_I1 = IntStream.range(10000, 20000).toArray();
43+
public static long [] array_L0 = LongStream.range(0, 10000).toArray();
44+
public static long [] array_L1 = LongStream.range(10000, 20000).toArray();
45+
46+
public static int oneI = 1;
47+
public static long oneL = 1L;
48+
49+
public static long [] GOLD_COMPRESS_LONG = testCompressBitsLong();
50+
public static long [] GOLD_EXPAND_LONG = testExpandBitsLong();
51+
public static int [] GOLD_COMPRESS_INT = testCompressBitsInt();
52+
public static int [] GOLD_EXPAND_INT = testExpandBitsInt();
53+
54+
@Test
55+
public static long[] testExpandBitsLong() {
56+
long[] out = new long[10000];
57+
for (int i = 0; i < out.length; i++) {
58+
long y = array_L0[i] % oneL;
59+
long x = (array_L1[i] | 4294967298L) << -7640610671680100954L;
60+
out[i] = Long.expand(y, x);
61+
}
62+
return out;
63+
}
64+
65+
@Check(test="testExpandBitsLong")
66+
public static void checkExpandBitsLong(long [] actual) {
67+
for (int i = 0; i < GOLD_EXPAND_LONG.length; i++) {
68+
Verify.checkEQ(GOLD_EXPAND_LONG[i], actual[i]);
69+
}
70+
}
71+
72+
@Test
73+
public static long[] testCompressBitsLong() {
74+
long[] out = new long[10000];
75+
for (int i = 0; i < out.length; i++) {
76+
long y = array_L0[i] % oneL;
77+
long x = (array_L1[i] | 4294967298L) << -7640610671680100954L;
78+
out[i] = Long.compress(y, x);
79+
}
80+
return out;
81+
}
82+
83+
@Check(test="testCompressBitsLong")
84+
public static void checkCompressBitsLong(long [] actual) {
85+
for (int i = 0; i < GOLD_COMPRESS_LONG.length; i++) {
86+
Verify.checkEQ(GOLD_COMPRESS_LONG[i], actual[i]);
87+
}
88+
}
89+
90+
@Test
91+
public static int[] testExpandBitsInt() {
92+
int[] out = new int[10000];
93+
for (int i = 0; i < out.length; i++) {
94+
int y = array_I0[i] % oneI;
95+
int x = (array_I1[i] | 22949672) << -76406101;
96+
out[i] = Integer.expand(y, x);
97+
}
98+
return out;
99+
}
100+
101+
@Check(test="testExpandBitsInt")
102+
public static void checkExpandBitsInt(int [] actual) {
103+
for (int i = 0; i < GOLD_EXPAND_INT.length; i++) {
104+
Verify.checkEQ(GOLD_EXPAND_INT[i], actual[i]);
105+
}
106+
}
107+
108+
@Test
109+
public static int[] testCompressBitsInt() {
110+
int[] out = new int[10000];
111+
for (int i = 0; i < out.length; i++) {
112+
int y = array_I0[i] % oneI;
113+
int x = (array_I1[i] | 429497) << -764061068;
114+
out[i] = Integer.compress(y, x);
115+
}
116+
return out;
117+
}
118+
119+
@Check(test="testCompressBitsInt")
120+
public static void checkCompressBitsInt(int [] actual) {
121+
for (int i = 0; i < GOLD_COMPRESS_INT.length; i++) {
122+
Verify.checkEQ(GOLD_COMPRESS_INT[i], actual[i]);
123+
}
124+
}
125+
126+
public static void main(String[] args) {
127+
TestFramework.runWithFlags("-XX:+StressIGVN");
128+
}
129+
}

0 commit comments

Comments
 (0)