8297384: Add IR tests for existing idealizations of arithmetic nodes

Reviewed-by: chagedorn
This commit is contained in:
Zhiqiang Zang 2022-11-25 08:17:44 +00:00 committed by Christian Hagedorn
parent cfe5a3716e
commit fd910f77bc
11 changed files with 596 additions and 77 deletions

@ -45,7 +45,7 @@ public class AddINodeIdealizationTests {
"test14", "test15", "test16",
"test17", "test18", "test19",
"test20", "test21", "test22",
"test23"})
"test23", "test24", "test25"})
public void runMethod() {
int a = RunInfo.getRandom().nextInt();
int b = RunInfo.getRandom().nextInt();
@ -63,31 +63,33 @@ public class AddINodeIdealizationTests {
@DontCompile
public void assertResult(int a, int b, int c, int d) {
Asserts.assertEQ(((a+a) + (a+a)) , additions(a));
Asserts.assertEQ(0 , xMinusX(a));
Asserts.assertEQ(a + 1 + 2 , test1(a));
Asserts.assertEQ((a + 2021) + b , test2(a, b));
Asserts.assertEQ(a + (b + 2021) , test3(a, b));
Asserts.assertEQ((1 - a) + 2 , test4(a));
Asserts.assertEQ((a - b) + (c - d), test5(a, b, c, d));
Asserts.assertEQ((a - b) + (b + c), test6(a, b, c));
Asserts.assertEQ((a - b) + (c + b), test7(a, b, c));
Asserts.assertEQ((a - b) + (b - c), test8(a, b, c));
Asserts.assertEQ((a - b) + (c - a), test9(a, b, c));
Asserts.assertEQ(a + (0 - b) , test10(a, b));
Asserts.assertEQ((0 - b) + a , test11(a, b));
Asserts.assertEQ((a - b) + b , test12(a, b));
Asserts.assertEQ(b + (a - b) , test13(a, b));
Asserts.assertEQ(a + 0 , test14(a));
Asserts.assertEQ(0 + a , test15(a));
Asserts.assertEQ(a*b + a*c , test16(a, b, c));
Asserts.assertEQ(a*b + b*c , test17(a, b, c));
Asserts.assertEQ(a*c + b*c , test18(a, b, c));
Asserts.assertEQ(a*b + c*a , test19(a, b, c));
Asserts.assertEQ((a - b) + 210 , test20(a, b));
Asserts.assertEQ((a - b) + 190 , test21(a, b));
Asserts.assertEQ((a - b) + 210 , test22(a, b));
Asserts.assertEQ((a - b) + 190 , test23(a, b));
Asserts.assertEQ(((a+a) + (a+a)) , additions(a));
Asserts.assertEQ(0 , xMinusX(a));
Asserts.assertEQ(a + 1 + 2 , test1(a));
Asserts.assertEQ((a + 2021) + b , test2(a, b));
Asserts.assertEQ(a + (b + 2021) , test3(a, b));
Asserts.assertEQ((1 - a) + 2 , test4(a));
Asserts.assertEQ((a - b) + (c - d) , test5(a, b, c, d));
Asserts.assertEQ((a - b) + (b + c) , test6(a, b, c));
Asserts.assertEQ((a - b) + (c + b) , test7(a, b, c));
Asserts.assertEQ((a - b) + (b - c) , test8(a, b, c));
Asserts.assertEQ((a - b) + (c - a) , test9(a, b, c));
Asserts.assertEQ(a + (0 - b) , test10(a, b));
Asserts.assertEQ((0 - b) + a , test11(a, b));
Asserts.assertEQ((a - b) + b , test12(a, b));
Asserts.assertEQ(b + (a - b) , test13(a, b));
Asserts.assertEQ(a + 0 , test14(a));
Asserts.assertEQ(0 + a , test15(a));
Asserts.assertEQ(a*b + a*c , test16(a, b, c));
Asserts.assertEQ(a*b + b*c , test17(a, b, c));
Asserts.assertEQ(a*c + b*c , test18(a, b, c));
Asserts.assertEQ(a*b + c*a , test19(a, b, c));
Asserts.assertEQ((a - b) + 210 , test20(a, b));
Asserts.assertEQ((a - b) + 190 , test21(a, b));
Asserts.assertEQ((a - b) + 210 , test22(a, b));
Asserts.assertEQ((a - b) + 190 , test23(a, b));
Asserts.assertEQ(Math.max(a, b) + Math.min(a, b), test24(a, b));
Asserts.assertEQ(Math.min(a, b) + Math.max(a, b), test25(a, b));
}
@Test
@ -293,4 +295,20 @@ public class AddINodeIdealizationTests {
public int test23(int x, int y) {
return x + (-10 - y) + 200; // transformed to (x - y) + 190;
}
@Test
@IR(failOn = { IRNode.MAX, IRNode.MIN })
@IR(counts = { IRNode.ADD, "1" })
// Checks Math.max(a, b) + Math.min(a, b) => a + b
public int test24(int a, int b) {
return Math.max(a, b) + Math.min(a, b);
}
@Test
@IR(failOn = { IRNode.MAX, IRNode.MIN })
@IR(counts = { IRNode.ADD, "1" })
// Checks Math.min(a, b) + Math.max(a, b) => a + b
public int test25(int a, int b) {
return Math.min(a, b) + Math.max(a, b);
}
}

@ -44,7 +44,8 @@ public class AddLNodeIdealizationTests {
"test11", "test12", "test13",
"test14", "test15", "test16",
"test17", "test18", "test19",
"test20", "test21", "test22"})
"test20", "test21", "test22",
"test23", "test24"})
public void runMethod() {
long a = RunInfo.getRandom().nextLong();
long b = RunInfo.getRandom().nextLong();
@ -62,30 +63,32 @@ public class AddLNodeIdealizationTests {
@DontCompile
public void assertResult(long a, long b, long c, long d) {
Asserts.assertEQ(((a+a) + (a+a)) , additions(a));
Asserts.assertEQ(0L , xMinusX(a));
Asserts.assertEQ(a + 1 + 2 , test1(a));
Asserts.assertEQ((a + 2021) + b , test2(a, b));
Asserts.assertEQ(a + (b + 2021) , test3(a, b));
Asserts.assertEQ((1 - a) + 2 , test4(a));
Asserts.assertEQ((a - b) + (c - d) , test5(a, b, c, d));
Asserts.assertEQ((a - b) + (b + c) , test6(a, b, c));
Asserts.assertEQ((a - b) + (c + b) , test7(a, b, c));
Asserts.assertEQ((a - b) + (c - a) , test8(a, b, c));
Asserts.assertEQ(a + (0 - b) , test9(a, b));
Asserts.assertEQ((0 - b) + a , test10(a, b));
Asserts.assertEQ((a - b) + b , test11(a, b));
Asserts.assertEQ(b + (a - b) , test12(a, b));
Asserts.assertEQ(a + 0 , test13(a));
Asserts.assertEQ(0 + a , test14(a));
Asserts.assertEQ(a*b + a*c , test15(a, b, c));
Asserts.assertEQ(a*b + b*c , test16(a, b, c));
Asserts.assertEQ(a*c + b*c , test17(a, b, c));
Asserts.assertEQ(a*b + c*a , test18(a, b, c));
Asserts.assertEQ((a - b) + 123_456_789_123L , test19(a, b));
Asserts.assertEQ((a - b) + -123_456_788_877L , test20(a, b));
Asserts.assertEQ((a - b) + 123_456_789_123L , test21(a, b));
Asserts.assertEQ((a - b) + -123_456_788_877L , test22(a, b));
Asserts.assertEQ(((a+a) + (a+a)) , additions(a));
Asserts.assertEQ(0L , xMinusX(a));
Asserts.assertEQ(a + 1 + 2 , test1(a));
Asserts.assertEQ((a + 2021) + b , test2(a, b));
Asserts.assertEQ(a + (b + 2021) , test3(a, b));
Asserts.assertEQ((1 - a) + 2 , test4(a));
Asserts.assertEQ((a - b) + (c - d) , test5(a, b, c, d));
Asserts.assertEQ((a - b) + (b + c) , test6(a, b, c));
Asserts.assertEQ((a - b) + (c + b) , test7(a, b, c));
Asserts.assertEQ((a - b) + (c - a) , test8(a, b, c));
Asserts.assertEQ(a + (0 - b) , test9(a, b));
Asserts.assertEQ((0 - b) + a , test10(a, b));
Asserts.assertEQ((a - b) + b , test11(a, b));
Asserts.assertEQ(b + (a - b) , test12(a, b));
Asserts.assertEQ(a + 0 , test13(a));
Asserts.assertEQ(0 + a , test14(a));
Asserts.assertEQ(a*b + a*c , test15(a, b, c));
Asserts.assertEQ(a*b + b*c , test16(a, b, c));
Asserts.assertEQ(a*c + b*c , test17(a, b, c));
Asserts.assertEQ(a*b + c*a , test18(a, b, c));
Asserts.assertEQ((a - b) + 123_456_789_123L , test19(a, b));
Asserts.assertEQ((a - b) + -123_456_788_877L , test20(a, b));
Asserts.assertEQ((a - b) + 123_456_789_123L , test21(a, b));
Asserts.assertEQ((a - b) + -123_456_788_877L , test22(a, b));
Asserts.assertEQ(Math.max(a, b) + Math.min(a, b), test23(a, b));
Asserts.assertEQ(Math.min(a, b) + Math.max(a, b), test24(a, b));
}
@Test
@ -287,4 +290,20 @@ public class AddLNodeIdealizationTests {
return x + (-123_456_789_000L - y) + 123;
// transformed to (x - y) + -123_456_788_877L;
}
@Test
@IR(failOn = { IRNode.MAX, IRNode.MIN })
@IR(counts = { IRNode.ADD, "1" })
// Checks Math.max(a, b) + Math.min(a, b) => a + b
public long test23(long a, long b) {
return Math.max(a, b) + Math.min(a, b);
}
@Test
@IR(failOn = { IRNode.MAX, IRNode.MIN })
@IR(counts = { IRNode.ADD, "1" })
// Checks Math.min(a, b) + Math.max(a, b) => a + b
public long test24(long a, long b) {
return Math.min(a, b) + Math.max(a, b);
}
}

@ -0,0 +1,66 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. 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.irTests;
import jdk.test.lib.Asserts;
import compiler.lib.ir_framework.*;
/*
* @test
* @bug 8297384
* @summary Test that Ideal transformations of AndINode* are being performed as expected.
* @library /test/lib /
* @run driver compiler.c2.irTests.AndINodeIdealizationTests
*/
public class AndINodeIdealizationTests {
public static void main(String[] args) {
TestFramework.run();
}
@Run(test = { "test1" })
public void runMethod() {
int a = RunInfo.getRandom().nextInt();
int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE;
assertResult(0);
assertResult(a);
assertResult(min);
assertResult(max);
}
@DontCompile
public void assertResult(int a) {
Asserts.assertEQ((0 - a) & 1, test1(a));
}
@Test
@IR(failOn = { IRNode.SUB })
@IR(counts = { IRNode.AND, "1" })
// Checks (0 - x) & 1 => x & 1
public int test1(int x) {
return (0 - x) & 1;
}
}

@ -0,0 +1,74 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. 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.irTests;
import jdk.test.lib.Asserts;
import compiler.lib.ir_framework.*;
/*
* @test
* @bug 8297384
* @summary Test that Ideal transformations of LShiftINode* are being performed as expected.
* @library /test/lib /
* @run driver compiler.c2.irTests.LShiftINodeIdealizationTests
*/
public class LShiftINodeIdealizationTests {
public static void main(String[] args) {
TestFramework.run();
}
@Run(test = { "test1", "test2" })
public void runMethod() {
int a = RunInfo.getRandom().nextInt();
int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE;
assertResult(0);
assertResult(a);
assertResult(min);
assertResult(max);
}
@DontCompile
public void assertResult(int a) {
Asserts.assertEQ((a >> 2022) << 2022, test1(a));
Asserts.assertEQ((a >>> 2022) << 2022, test2(a));
}
@Test
@IR(failOn = { IRNode.LSHIFT, IRNode.RSHIFT })
@IR(counts = { IRNode.AND, "1" })
// Checks (x >> 2022) << 2022 => x & C where C = -(1 << 6)
public int test1(int x) {
return (x >> 2022) << 2022;
}
@Test
@IR(failOn = { IRNode.LSHIFT, IRNode.URSHIFT })
@IR(counts = { IRNode.AND, "1" })
// Checks (x >>> 2022) << 2022 => x & C where C = -(1 << 6)
public int test2(int x) {
return (x >>> 2022) << 2022;
}
}

@ -40,7 +40,8 @@ public class MulINodeIdealizationTests {
@Run(test = {"combineConstants", "moveConstants", "moveConstantsAgain",
"multiplyZero", "multiplyZeroAgain", "distribute",
"identity", "identityAgain", "powerTwo",
"powerTwoAgain", "powerTwoPlusOne", "powerTwoMinusOne"})
"powerTwoAgain", "powerTwoPlusOne", "powerTwoMinusOne",
"negativeCancelledOut", "maxMin"})
public void runMethod() {
int a = RunInfo.getRandom().nextInt();
int b = RunInfo.getRandom().nextInt();
@ -56,18 +57,20 @@ public class MulINodeIdealizationTests {
@DontCompile
public void assertResult(int a, int b) {
Asserts.assertEQ((a * 13) * 14 , combineConstants(a));
Asserts.assertEQ((a * 13) * b , moveConstants(a, b));
Asserts.assertEQ(a * (b * 13) , moveConstantsAgain(a, b));
Asserts.assertEQ(0 * a , multiplyZero(a));
Asserts.assertEQ(a * 0 , multiplyZeroAgain(a));
Asserts.assertEQ((13 + a) * 14 , distribute(a));
Asserts.assertEQ(1 * a , identity(a));
Asserts.assertEQ(a * 1 , identityAgain(a));
Asserts.assertEQ(a * 64 , powerTwo(a));
Asserts.assertEQ(a * (1025 - 1), powerTwoAgain(a));
Asserts.assertEQ(a * (64 + 1) , powerTwoPlusOne(a));
Asserts.assertEQ(a * (64 - 1) , powerTwoMinusOne(a));
Asserts.assertEQ((a * 13) * 14 , combineConstants(a));
Asserts.assertEQ((a * 13) * b , moveConstants(a, b));
Asserts.assertEQ(a * (b * 13) , moveConstantsAgain(a, b));
Asserts.assertEQ(0 * a , multiplyZero(a));
Asserts.assertEQ(a * 0 , multiplyZeroAgain(a));
Asserts.assertEQ((13 + a) * 14 , distribute(a));
Asserts.assertEQ(1 * a , identity(a));
Asserts.assertEQ(a * 1 , identityAgain(a));
Asserts.assertEQ(a * 64 , powerTwo(a));
Asserts.assertEQ(a * (1025 - 1) , powerTwoAgain(a));
Asserts.assertEQ(a * (64 + 1) , powerTwoPlusOne(a));
Asserts.assertEQ(a * (64 - 1) , powerTwoMinusOne(a));
Asserts.assertEQ((0 - a) * (0 - b) , negativeCancelledOut(a, b));
Asserts.assertEQ(Math.max(a, b) * Math.min(a, b), maxMin(a, b));
}
@Test
@ -163,4 +166,20 @@ public class MulINodeIdealizationTests {
public int powerTwoMinusOne(int x) {
return x * (64 - 1);
}
@Test
@IR(failOn = { IRNode.SUB })
@IR(counts = { IRNode.MUL, "1" })
// Checks (0 - x) * (0 - y) => x * y
public int negativeCancelledOut(int x, int y) {
return (0 - x) * (0 - y);
}
@Test
@IR(failOn = { IRNode.MAX, IRNode.MIN })
@IR(counts = { IRNode.MUL, "1" })
// Checks Math.max(x, y) * Math.min(x, y) => x * y
public int maxMin(int x, int y) {
return Math.max(x, y) * Math.min(x, y);
}
}

@ -40,7 +40,8 @@ public class MulLNodeIdealizationTests {
@Run(test = {"combineConstants", "moveConstants", "moveConstantsAgain",
"multiplyZero", "multiplyZeroAgain", "distribute",
"identity", "identityAgain", "powerTwo",
"powerTwoAgain", "powerTwoPlusOne", "powerTwoMinusOne"})
"powerTwoAgain", "powerTwoPlusOne", "powerTwoMinusOne",
"negativeCancelledOut", "maxMin"})
public void runMethod() {
long a = RunInfo.getRandom().nextLong();
long b = RunInfo.getRandom().nextLong();
@ -56,18 +57,20 @@ public class MulLNodeIdealizationTests {
@DontCompile
public void assertResult(long a, long b) {
Asserts.assertEQ((a * 13) * 14 * 15, combineConstants(a));
Asserts.assertEQ((a * 13) * b , moveConstants(a, b));
Asserts.assertEQ(a * (b * 13) , moveConstantsAgain(a, b));
Asserts.assertEQ(0 * a , multiplyZero(a));
Asserts.assertEQ(a * 0 , multiplyZeroAgain(a));
Asserts.assertEQ((13 + a) * 14 , distribute(a));
Asserts.assertEQ(1 * a , identity(a));
Asserts.assertEQ(a * 1 , identityAgain(a));
Asserts.assertEQ(a * 64 , powerTwo(a));
Asserts.assertEQ(a * (1025 - 1) , powerTwoAgain(a));
Asserts.assertEQ(a * (64 + 1) , powerTwoPlusOne(a));
Asserts.assertEQ(a * (64 - 1) , powerTwoMinusOne(a));
Asserts.assertEQ((a * 13) * 14 * 15 , combineConstants(a));
Asserts.assertEQ((a * 13) * b , moveConstants(a, b));
Asserts.assertEQ(a * (b * 13) , moveConstantsAgain(a, b));
Asserts.assertEQ(0 * a , multiplyZero(a));
Asserts.assertEQ(a * 0 , multiplyZeroAgain(a));
Asserts.assertEQ((13 + a) * 14 , distribute(a));
Asserts.assertEQ(1 * a , identity(a));
Asserts.assertEQ(a * 1 , identityAgain(a));
Asserts.assertEQ(a * 64 , powerTwo(a));
Asserts.assertEQ(a * (1025 - 1) , powerTwoAgain(a));
Asserts.assertEQ(a * (64 + 1) , powerTwoPlusOne(a));
Asserts.assertEQ(a * (64 - 1) , powerTwoMinusOne(a));
Asserts.assertEQ((0 - a) * (0 - b) , negativeCancelledOut(a, b));
Asserts.assertEQ(Math.max(a, b) * Math.min(a, b), maxMin(a, b));
}
@Test
@ -163,4 +166,20 @@ public class MulLNodeIdealizationTests {
public long powerTwoMinusOne(long x) {
return x * (64 - 1);
}
@Test
@IR(failOn = { IRNode.SUB })
@IR(counts = { IRNode.MUL, "1" })
// Checks (0 - x) * (0 - y) => x * y
public long negativeCancelledOut(long x, long y) {
return (0 - x) * (0 - y);
}
@Test
@IR(failOn = { IRNode.MAX, IRNode.MIN })
@IR(counts = { IRNode.MUL, "1" })
// Checks Math.max(x, y) * Math.min(x, y) => x * y
public long maxMin(long x, long y) {
return Math.max(x, y) * Math.min(x, y);
}
}

@ -0,0 +1,67 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. 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.irTests;
import jdk.test.lib.Asserts;
import compiler.lib.ir_framework.*;
/*
* @test
* @bug 8297384
* @summary Test that Ideal transformations of RotateLeftNode* are being performed as expected.
* @library /test/lib /
* @run driver compiler.c2.irTests.RotateLeftNodeIntIdealizationTests
* @requires os.arch == "x86_64" | os.arch == "aarch64" | os.arch == "riscv64"
*/
public class RotateLeftNodeIntIdealizationTests {
public static void main(String[] args) {
TestFramework.run();
}
@Run(test = { "test1" })
public void runMethod() {
int a = RunInfo.getRandom().nextInt();
int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE;
assertResult(0);
assertResult(a);
assertResult(min);
assertResult(max);
}
@DontCompile
public void assertResult(int a) {
Asserts.assertEQ(Integer.rotateLeft(a, 2022), test1(a));
}
@Test
@IR(failOn = { IRNode.ROTATE_LEFT })
@IR(counts = { IRNode.ROTATE_RIGHT, "1" })
// Checks Integer.rotateLeft(x, 2022) => Integer.rotateRight(x, C) where C = 32 - (2022 & 31)
public int test1(int x) {
return Integer.rotateLeft(x, 2022);
}
}

@ -0,0 +1,67 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. 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.irTests;
import jdk.test.lib.Asserts;
import compiler.lib.ir_framework.*;
/*
* @test
* @bug 8297384
* @summary Test that Ideal transformations of RotateLeftNode* are being performed as expected.
* @library /test/lib /
* @run driver compiler.c2.irTests.RotateLeftNodeLongIdealizationTests
* @requires os.arch == "x86_64" | os.arch == "aarch64" | os.arch == "riscv64"
*/
public class RotateLeftNodeLongIdealizationTests {
public static void main(String[] args) {
TestFramework.run();
}
@Run(test = { "test1" })
public void runMethod() {
long a = RunInfo.getRandom().nextInt();
long min = Long.MIN_VALUE;
long max = Long.MAX_VALUE;
assertResult(0);
assertResult(a);
assertResult(min);
assertResult(max);
}
@DontCompile
public void assertResult(long a) {
Asserts.assertEQ(Long.rotateLeft(a, 2022), test1(a));
}
@Test
@IR(failOn = { IRNode.ROTATE_LEFT })
@IR(counts = { IRNode.ROTATE_RIGHT, "1" })
// Checks Long.rotateLeft(x, 2022) => Long.rotateRight(x, C) where C = 64 - (2022 & 63)
public long test1(long x) {
return Long.rotateLeft(x, 2022);
}
}

@ -0,0 +1,75 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. 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.irTests;
import jdk.test.lib.Asserts;
import compiler.lib.ir_framework.*;
/*
* @test
* @bug 8297384
* @summary Test that Ideal transformations of URShiftINode* are being performed as expected.
* @library /test/lib /
* @run driver compiler.c2.irTests.URShiftINodeIdealizationTests
*/
public class URShiftINodeIdealizationTests {
public static void main(String[] args) {
TestFramework.run();
}
@Run(test = { "test1", "test2" })
public void runMethod() {
int a = RunInfo.getRandom().nextInt();
int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE;
assertResult(0);
assertResult(a);
assertResult(min);
assertResult(max);
}
@DontCompile
public void assertResult(int a) {
Asserts.assertEQ((a << 2022) >>> 2022, test1(a));
Asserts.assertEQ((a >> 2022) >>> 31, test2(a));
}
@Test
@IR(failOn = { IRNode.LSHIFT, IRNode.URSHIFT })
@IR(counts = { IRNode.AND, "1" })
// Checks (x << 2022) >>> 2022 => x & C where C = ((1 << (32 - 6)) - 1)
public int test1(int x) {
return (x << 2022) >>> 2022;
}
@Test
@IR(failOn = { IRNode.RSHIFT })
@IR(counts = { IRNode.URSHIFT, "1" })
// Checks (x >> 2022) >>> 31 => x >>> 31
public int test2(int x) {
return (x >> 2022) >>> 31;
}
}

@ -0,0 +1,75 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. 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.irTests;
import jdk.test.lib.Asserts;
import compiler.lib.ir_framework.*;
/*
* @test
* @bug 8297384
* @summary Test that Ideal transformations of URShiftLNode* are being performed as expected.
* @library /test/lib /
* @run driver compiler.c2.irTests.URShiftLNodeIdealizationTests
*/
public class URShiftLNodeIdealizationTests {
public static void main(String[] args) {
TestFramework.run();
}
@Run(test = { "test1", "test2" })
public void runMethod() {
long a = RunInfo.getRandom().nextInt();
long min = Long.MIN_VALUE;
long max = Long.MAX_VALUE;
assertResult(0);
assertResult(a);
assertResult(min);
assertResult(max);
}
@DontCompile
public void assertResult(long a) {
Asserts.assertEQ((a << 2022) >>> 2022, test1(a));
Asserts.assertEQ((a >> 2022) >>> 63, test2(a));
}
@Test
@IR(failOn = { IRNode.LSHIFT, IRNode.URSHIFT })
@IR(counts = { IRNode.AND, "1" })
// Checks (x << 2022) >>> 2022 => x & C where C = ((1 << (64 - 38)) - 1)
public long test1(long x) {
return (x << 2022) >>> 2022;
}
@Test
@IR(failOn = { IRNode.RSHIFT })
@IR(counts = { IRNode.URSHIFT, "1" })
// Checks (x >> 2022) >>> 63 => x >>> 63
public long test2(long x) {
return (x >> 2022) >>> 63;
}
}

@ -593,6 +593,11 @@ public class IRNode {
afterBarrierExpansionToBeforeMatching(MACRO_LOGIC_V, "MacroLogicV");
}
public static final String MAX = PREFIX + "MAX" + POSTFIX;
static {
beforeMatchingNameRegex(MAX, "Max(I|L)");
}
public static final String MAX_I = PREFIX + "MAX_I" + POSTFIX;
static {
beforeMatchingNameRegex(MAX_I, "MaxI");
@ -613,6 +618,11 @@ public class IRNode {
beforeMatchingNameRegex(MEMBAR_STORESTORE, "MemBarStoreStore");
}
public static final String MIN = PREFIX + "MIN" + POSTFIX;
static {
beforeMatchingNameRegex(MIN, "Min(I|L)");
}
public static final String MIN_I = PREFIX + "MIN_I" + POSTFIX;
static {
beforeMatchingNameRegex(MIN_I, "MinI");
@ -752,6 +762,16 @@ public class IRNode {
beforeMatchingNameRegex(ROUND_VF, "RoundVF");
}
public static final String ROTATE_LEFT = PREFIX + "ROTATE_LEFT" + POSTFIX;
static {
beforeMatchingNameRegex(ROTATE_LEFT, "RotateLeft");
}
public static final String ROTATE_RIGHT = PREFIX + "ROTATE_RIGHT" + POSTFIX;
static {
beforeMatchingNameRegex(ROTATE_RIGHT, "RotateRight");
}
public static final String RSHIFT = PREFIX + "RSHIFT" + POSTFIX;
static {
beforeMatchingNameRegex(RSHIFT, "RShift(I|L)");