8291466: C2: assert(false) failed: infinite loop in PhaseIterGVN::transform_old with -XX:+StressIGVN

Reviewed-by: roland, chagedorn
This commit is contained in:
Pengfei Li 2022-08-29 13:06:20 +00:00
parent d5167a91a9
commit a88a9e344f
3 changed files with 97 additions and 20 deletions

View File

@ -239,18 +239,18 @@ MulNode* MulNode::make(Node* in1, Node* in2, BasicType bt) {
//------------------------------Ideal------------------------------------------
// Check for power-of-2 multiply, then try the regular MulNode::Ideal
Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) {
// Swap constant to right
jint con;
if ((con = in(1)->find_int_con(0)) != 0) {
swap_edges(1, 2);
// Finish rest of method to use info in 'con'
} else if ((con = in(2)->find_int_con(0)) == 0) {
const jint con = in(2)->find_int_con(0);
if (con == 0) {
// If in(2) is not a constant, call Ideal() of the parent class to
// try to move constant to the right side.
return MulNode::Ideal(phase, can_reshape);
}
// Now we have a constant Node on the right and the constant in con
if (con == 0) return NULL; // By zero is handled by Value call
if (con == 1) return NULL; // By one is handled by Identity call
// Now we have a constant Node on the right and the constant in con.
if (con == 1) {
// By one is handled by Identity call
return NULL;
}
// Check for negative constant; if so negate the final result
bool sign_flip = false;
@ -262,7 +262,7 @@ Node *MulINode::Ideal(PhaseGVN *phase, bool can_reshape) {
// Get low bit; check for being the only bit
Node *res = NULL;
unsigned int bit1 = abs_con & (0-abs_con); // Extract low bit
unsigned int bit1 = submultiple_power_of_2(abs_con);
if (bit1 == abs_con) { // Found a power of 2?
res = new LShiftINode(in(1), phase->intcon(log2i_exact(bit1)));
} else {
@ -334,18 +334,18 @@ const Type *MulINode::mul_ring(const Type *t0, const Type *t1) const {
//------------------------------Ideal------------------------------------------
// Check for power-of-2 multiply, then try the regular MulNode::Ideal
Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
// Swap constant to right
jlong con;
if ((con = in(1)->find_long_con(0)) != 0) {
swap_edges(1, 2);
// Finish rest of method to use info in 'con'
} else if ((con = in(2)->find_long_con(0)) == 0) {
const jlong con = in(2)->find_long_con(0);
if (con == 0) {
// If in(2) is not a constant, call Ideal() of the parent class to
// try to move constant to the right side.
return MulNode::Ideal(phase, can_reshape);
}
// Now we have a constant Node on the right and the constant in con
if (con == CONST64(0)) return NULL; // By zero is handled by Value call
if (con == CONST64(1)) return NULL; // By one is handled by Identity call
// Now we have a constant Node on the right and the constant in con.
if (con == 1) {
// By one is handled by Identity call
return NULL;
}
// Check for negative constant; if so negate the final result
bool sign_flip = false;
@ -356,7 +356,7 @@ Node *MulLNode::Ideal(PhaseGVN *phase, bool can_reshape) {
// Get low bit; check for being the only bit
Node *res = NULL;
julong bit1 = abs_con & (0-abs_con); // Extract low bit
julong bit1 = submultiple_power_of_2(abs_con);
if (bit1 == abs_con) { // Found a power of 2?
res = new LShiftLNode(in(1), phase->intcon(log2i_exact(bit1)));
} else {

View File

@ -128,4 +128,14 @@ inline T ceil_log2(T value) {
return ret;
}
// Return the largest power of two that is a submultiple of the given value.
// This is the same as the numeric value of the least-significant set bit.
// For unsigned values, it replaces the old trick of (value & -value).
// precondition: value > 0.
template<typename T, ENABLE_IF(std::is_integral<T>::value)>
inline T submultiple_power_of_2(T value) {
assert(value > 0, "Invalid value");
return value & -value;
}
#endif // SHARE_UTILITIES_POWEROFTWO_HPP

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2022, Arm Limited. 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
* @key stress randomness
* @bug 8291466
* @summary Infinite loop in PhaseIterGVN::transform_old with -XX:+StressIGVN
* @requires vm.compiler2.enabled
* @run main/othervm -Xbatch -XX:-TieredCompilation
* -XX:+UnlockDiagnosticVMOptions -XX:+StressIGVN
* -XX:StressSeed=1 compiler.c2.TestMulNodeInfiniteGVN
*/
package compiler.c2;
public class TestMulNodeInfiniteGVN {
private static int fun() {
int sum = 0;
for (int c = 0; c < 50000; c++) {
int x = 9;
while ((x += 2) < 12) {
for (int k = 1; k < 2; k++) {
sum += x * k;
}
}
int y = 11;
while ((y += 2) < 14) {
for (int k = 1; k < 2; k++) {
sum += y * k;
}
}
int z = 17;
while ((z += 2) < 20) {
for (int k = 1; k < 2; k++) {
sum += z * k;
}
}
}
return sum;
}
public static void main(String[] args) {
fun();
}
}