Skip to content

Commit a88a9e3

Browse files
author
Pengfei Li
committedAug 29, 2022
8291466: C2: assert(false) failed: infinite loop in PhaseIterGVN::transform_old with -XX:+StressIGVN
Reviewed-by: roland, chagedorn
1 parent d5167a9 commit a88a9e3

File tree

3 files changed

+97
-20
lines changed

3 files changed

+97
-20
lines changed
 

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

+20-20
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,18 @@ MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) {
239239
//------------------------------Ideal------------------------------------------
240240
// Check for power-of-2 multiply, then try the regular MulNode::Ideal
241241
Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) {
242-
// Swap constant to right
243-
jint con;
244-
if ((con = in(1)->find_int_con(0)) != 0) {
245-
swap_edges(1, 2);
246-
// Finish rest of method to use info in 'con'
247-
} else if ((con = in(2)->find_int_con(0)) == 0) {
242+
const jint con = in(2)->find_int_con(0);
243+
if (con == 0) {
244+
// If in(2) is not a constant, call Ideal() of the parent class to
245+
// try to move constant to the right side.
248246
return MulNode::Ideal(phase, can_reshape);
249247
}
250248

251-
// Now we have a constant Node on the right and the constant in con
252-
if (con == 0) return NULL; // By zero is handled by Value call
253-
if (con == 1) return NULL; // By one is handled by Identity call
249+
// Now we have a constant Node on the right and the constant in con.
250+
if (con == 1) {
251+
// By one is handled by Identity call
252+
return NULL;
253+
}
254254

255255
// Check for negative constant; if so negate the final result
256256
bool sign_flip = false;
@@ -262,7 +262,7 @@ Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) {
262262

263263
// Get low bit; check for being the only bit
264264
Node *res = NULL;
265-
unsigned int bit1 = abs_con & (0-abs_con); // Extract low bit
265+
unsigned int bit1 = submultiple_power_of_2(abs_con);
266266
if (bit1 == abs_con) { // Found a power of 2?
267267
res = new LShiftINode(in(1), phase->intcon(log2i_exact(bit1)));
268268
} else {
@@ -334,18 +334,18 @@ const Type *MulINode::mul_ring(const Type *t0, const Type *t1) const {
334334
//------------------------------Ideal------------------------------------------
335335
// Check for power-of-2 multiply, then try the regular MulNode::Ideal
336336
Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
337-
// Swap constant to right
338-
jlong con;
339-
if ((con = in(1)->find_long_con(0)) != 0) {
340-
swap_edges(1, 2);
341-
// Finish rest of method to use info in 'con'
342-
} else if ((con = in(2)->find_long_con(0)) == 0) {
337+
const jlong con = in(2)->find_long_con(0);
338+
if (con == 0) {
339+
// If in(2) is not a constant, call Ideal() of the parent class to
340+
// try to move constant to the right side.
343341
return MulNode::Ideal(phase, can_reshape);
344342
}
345343

346-
// Now we have a constant Node on the right and the constant in con
347-
if (con == CONST64(0)) return NULL; // By zero is handled by Value call
348-
if (con == CONST64(1)) return NULL; // By one is handled by Identity call
344+
// Now we have a constant Node on the right and the constant in con.
345+
if (con == 1) {
346+
// By one is handled by Identity call
347+
return NULL;
348+
}
349349

350350
// Check for negative constant; if so negate the final result
351351
bool sign_flip = false;
@@ -356,7 +356,7 @@ Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
356356

357357
// Get low bit; check for being the only bit
358358
Node *res = NULL;
359-
julong bit1 = abs_con & (0-abs_con); // Extract low bit
359+
julong bit1 = submultiple_power_of_2(abs_con);
360360
if (bit1 == abs_con) { // Found a power of 2?
361361
res = new LShiftLNode(in(1), phase->intcon(log2i_exact(bit1)));
362362
} else {

‎src/hotspot/share/utilities/powerOfTwo.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,14 @@ inline T ceil_log2(T value) {
128128
return ret;
129129
}
130130

131+
// Return the largest power of two that is a submultiple of the given value.
132+
// This is the same as the numeric value of the least-significant set bit.
133+
// For unsigned values, it replaces the old trick of (value & -value).
134+
// precondition: value > 0.
135+
template<typename T, ENABLE_IF(std::is_integral<T>::value)>
136+
inline T submultiple_power_of_2(T value) {
137+
assert(value > 0, "Invalid value");
138+
return value & -value;
139+
}
140+
131141
#endif // SHARE_UTILITIES_POWEROFTWO_HPP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2022, Arm Limited. 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+
* @key stress randomness
27+
* @bug 8291466
28+
* @summary Infinite loop in PhaseIterGVN::transform_old with -XX:+StressIGVN
29+
* @requires vm.compiler2.enabled
30+
* @run main/othervm -Xbatch -XX:-TieredCompilation
31+
* -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN
32+
* -XX:StressSeed=1 compiler.c2.TestMulNodeInfiniteGVN
33+
*/
34+
35+
package compiler.c2;
36+
37+
public class TestMulNodeInfiniteGVN {
38+
39+
private static int fun() {
40+
int sum = 0;
41+
for (int c = 0; c < 50000; c++) {
42+
int x = 9;
43+
while ((x += 2) < 12) {
44+
for (int k = 1; k < 2; k++) {
45+
sum += x * k;
46+
}
47+
}
48+
int y = 11;
49+
while ((y += 2) < 14) {
50+
for (int k = 1; k < 2; k++) {
51+
sum += y * k;
52+
}
53+
}
54+
int z = 17;
55+
while ((z += 2) < 20) {
56+
for (int k = 1; k < 2; k++) {
57+
sum += z * k;
58+
}
59+
}
60+
}
61+
return sum;
62+
}
63+
64+
public static void main(String[] args) {
65+
fun();
66+
}
67+
}

0 commit comments

Comments
 (0)
Please sign in to comment.