Skip to content

Instantly share code, notes, and snippets.

@JohnTortugo
Created April 29, 2021 23:48
Show Gist options
  • Save JohnTortugo/1986cb73447d07b8951193bbaac96253 to your computer and use it in GitHub Desktop.
Save JohnTortugo/1986cb73447d07b8951193bbaac96253 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2021, 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 jdk.test.lib.hotspot.ir_framework.examples;
import jdk.test.lib.hotspot.ir_framework.*;
import java.util.Random;
/*
* @test
* @summary Test that Ideal transformations of AddINode* are being performed as expected.
* @library /test/lib
* @run driver jdk.test.lib.hotspot.ir_framework.examples.AddINodeIdealizationTests
*/
public class AddINodeIdealizationTests {
public static void main(String[] args) {
try {
TestFramework.run();
} catch (IRViolationException e) {
throw e;
}
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "1"})
// Checks (x + c1) + c2 => x + c3 where c3 = c1 + c2
public int simpleOne(int x) {
return (x + 1) + 2;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "2"})
// Checks (x + c1) + y => (x + y) + c1
public int simpleTwo(int x, int y) {
return (x + 2021) + y;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "2"})
// Checks x + (y + c1) => (x + y) + c1
public int simpleThree(int x, int y) {
return x + (y + 2021);
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (c1 - x) + c2 => c3 - x where c3 = c1 + c2
public int simpleFour(int x) {
return (1 - x) + 2;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV})
@IR(counts = {IRNode.SUB, "1",
IRNode.ADD, "2",
})
// Checks (a - b) + (c - d) => (a + c) - (b + d)
public int simpleFive(int a, int b, int c, int d) {
return (a - b) + (c - d);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "1"})
// Checks (a - b) + (b + c) => (a + c)
public int simpleSix(int a, int b, int c) {
return (a - b) + (b + c);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "1"})
// Checks (a - b) + (c + b) => (a + c)
public int simpleSeven(int a, int b, int c) {
return (a - b) + (c + b);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (a - b) + (b - c) => (a - c)
public int simpleEight(int a, int b, int c) {
return (a - b) + (b - c);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (a - b) + (c - a) => (c - b)
public int simpleNine(int a, int b, int c) {
return (a - b) + (c - a);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks x + (0 - y) => (x - y)
public int simpleTen(int x, int y) {
return x + (0 - y);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (0 - y) + x => (x - y)
public int simpleEleven(int x, int y) {
return (0 - y) + x;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD, IRNode.SUB})
// Checks (x - y) + y => x
public int simpleTwelve(int x, int y) {
return (x - y) + y;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD, IRNode.SUB})
// Checks y + (x - y) => x
public int simpleThirteen(int x, int y) {
return y + (x - y);
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD, IRNode.SUB})
// Checks x + 0 => x
public int simpleFourteen(int x) {
return x + 0;
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD, IRNode.SUB})
// Checks 0 + x => x
public int simpleFifteen(int x) {
return 0 + x;
}
}
/*
* Copyright (c) 2021, 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 jdk.test.lib.hotspot.ir_framework.examples;
import jdk.test.lib.hotspot.ir_framework.*;
import java.util.Random;
/*
* @test
* @summary Test that Ideal transformations of AddLNode* are being performed as expected.
* @library /test/lib
* @run driver jdk.test.lib.hotspot.ir_framework.examples.AddLNodeIdealizationTests
*/
public class AddLNodeIdealizationTests {
public static void main(String[] args) {
try {
TestFramework.run();
} catch (IRViolationException e) {
throw e;
}
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "1"})
// Checks (x + c1) + c2 => x + c3 where c3 = c1 + c2
public long simpleOne(long x) {
return (x + 1) + 2;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "2"})
// Checks (x + c1) + y => (x + y) + c1
public long simpleTwo(long x, long y) {
return (x + 2021) + y;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "2"})
// Checks x + (y + c1) => (x + y) + c1
public long simpleThree(long x, long y) {
return x + (y + 2021);
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (c1 - x) + c2 => c3 - x where c3 = c1 + c2
public long simpleFour(long x) {
return (1 - x) + 2;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV})
@IR(counts = {IRNode.SUB, "1",
IRNode.ADD, "2",
})
// Checks (a - b) + (c - d) => (a + c) - (b + d)
public long simpleFive(long a, long b, long c, long d) {
return (a - b) + (c - d);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "1"})
// Checks (a - b) + (b + c) => (a + c)
public long simpleSix(long a, long b, long c) {
return (a - b) + (b + c);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "1"})
// Checks (a - b) + (c + b) => (a + c)
public long simpleSeven(long a, long b, long c) {
return (a - b) + (c + b);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (a - b) + (b - c) => (a - c)
public long simpleEight(long a, long b, long c) {
return (a - b) + (b - c);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (a - b) + (c - a) => (c - b)
public long simpleNine(long a, long b, long c) {
return (a - b) + (c - a);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks x + (0 - y) => (x - y)
public long simpleTen(long x, long y) {
return x + (0 - y);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (0 - y) + x => (x - y)
public long simpleEleven(long x, long y) {
return (0 - y) + x;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD, IRNode.SUB})
// Checks (x - y) + y => x
public long simpleTwelve(long x, long y) {
return (x - y) + y;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD, IRNode.SUB})
// Checks y + (x - y) => x
public long simpleThirteen(long x, long y) {
return y + (x - y);
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD, IRNode.SUB})
// Checks x + 0 => x
public long simpleFourteen(long x) {
return x + 0;
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD, IRNode.SUB})
// Checks 0 + x => x
public long simpleFifteen(long x) {
return 0 + x;
}
}
/*
* Copyright (c) 2021, 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 jdk.test.lib.hotspot.ir_framework.examples;
import jdk.test.lib.hotspot.ir_framework.*;
import java.util.Random;
/*
* @test
* @summary Test that Ideal transformations of SubINode* are being performed as expected.
* @library /test/lib
* @run driver jdk.test.lib.hotspot.ir_framework.examples.SubINodeIdealizationTests
*/
public class SubINodeIdealizationTests {
public static void main(String[] args) {
try {
TestFramework.run();
} catch (IRViolationException e) {
throw e;
}
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "1"})
// Checks (x - c0) => x + (-c0)
public int simpleOne(int x) {
return (x - 1);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV})
@IR(counts = {IRNode.ADD, "1",
IRNode.SUB, "1"
})
// Checks (x + c0) - y => (x - y) + c0
public int simpleTwo(int x, int y) {
return (x + 1) - y;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV})
@IR(counts = {IRNode.SUB, "1",
IRNode.ADD, "1"
})
// Checks x - (y + c0) => (x - y) + (-c0)
public int simpleThree(int x, int y) {
return x - (y + 2021);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks x - (x + y) => -y
public int simpleFour(int x, int y) {
return x - (x + y);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (x - y) - x => -y
public int simpleFive(int x, int y) {
return (x - y) - x;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks x - (y + x) => -y
public int simpleSix(int x, int y) {
return x - (y + x);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks 0 - (x - y) => y - x
public int simpleSeven(int x, int y) {
return 0 - (x - y);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks 0 - (x + 2021) => -2021 - x
public int simpleEight(int x, int y) {
return 0 - (x + 2021);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (x + a) - (x + b) => a - b;
public int simpleNine(int x, int a, int b) {
return (x + a) - (x + b);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (a + x) - (b + x) => a - b
public int simpleTen(int x, int a, int b) {
return (a + x) - (b + x);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (a + x) - (x + b) => a - b
public int simpleEleven(int x, int a, int b) {
return (a + x) - (x + b);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (x + a) - (b + x) => a - b
public int simpleTwelve(int x, int a, int b) {
return (x + a) - (b + x);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV})
@IR(counts = {IRNode.SUB, "1",
IRNode.ADD, "1"
})
// Checks a - (b - c) => (a + c) - b
public int simpleThirteen(int a, int b, int c) {
return a - (b - c);
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB, IRNode.ADD})
// Checks 0 - (a >> 31) => a >> 31
public int simpleFourteen(int a) {
return 0 - (a >> 31);
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB, IRNode.ADD})
// Checks 0 - (0 - x) => x
public int simpleFifteen(int x) {
return 0 - (0 - x);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB, IRNode.ADD})
// Checks (x + y) -y => y
public int simpleSixteen(int x, int y) {
return (x + y) - y;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB, IRNode.ADD})
// Checks (x + y) - x => y
public int simpleSeventeen(int x, int y) {
return (x + y) - x;
}
}
/*
* Copyright (c) 2021, 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 jdk.test.lib.hotspot.ir_framework.examples;
import jdk.test.lib.hotspot.ir_framework.*;
import java.util.Random;
/*
* @test
* @summary Test that Ideal transformations of SubLNode* are being performed as expected.
* @library /test/lib
* @run driver jdk.test.lib.hotspot.ir_framework.examples.SubLNodeIdealizationTests
*/
public class SubLNodeIdealizationTests {
public static void main(String[] args) {
try {
TestFramework.run();
} catch (IRViolationException e) {
throw e;
}
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB})
@IR(counts = {IRNode.ADD, "1"})
// Checks (x - c0) => x + (-c0)
public long simpleOne(long x) {
return (x - 1);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV})
@IR(counts = {IRNode.ADD, "1",
IRNode.SUB, "1"
})
// Checks (x + c0) - y => (x - y) + c0
public long simpleTwo(long x, long y) {
return (x + 1) - y;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV})
@IR(counts = {IRNode.SUB, "1",
IRNode.ADD, "1"
})
// Checks x - (y + c0) => (x - y) + (-c0)
public long simpleThree(long x, long y) {
return x - (y + 2021);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks x - (x + y) => 0 - y
public long simpleFour(long x, long y) {
return x - (x + y);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (x - y) - x => 0 - y
public long simpleFive(long x, long y) {
return (x - y) - x;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks x - (y + x) => 0 - y
public long simpleSix(long x, long y) {
return x - (y + x);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks 0 - (x - y) => y - x
public long simpleSeven(long x, long y) {
return 0 - (x - y);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks 0 - (x + 2021) => -2021 - x
public long simpleEight(long x, long y) {
return 0 - (x + 2021);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (x + a) - (x + b) => a - b;
public long simpleNine(long x, long a, long b) {
return (x + a) - (x + b);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (a + x) - (b + x) => a - b
public long simpleTen(long x, long a, long b) {
return (a + x) - (b + x);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (a + x) - (x + b) => a - b
public long simpleEleven(long x, long a, long b) {
return (a + x) - (x + b);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.ADD})
@IR(counts = {IRNode.SUB, "1"})
// Checks (x + a) - (b + x) => a - b
public long simpleTwelve(long x, long a, long b) {
return (x + a) - (b + x);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV})
@IR(counts = {IRNode.SUB, "1",
IRNode.ADD, "1"
})
// Checks a - (b - c) => (a + c) - b
public long simpleThirteen(long a, long b, long c) {
return a - (b - c);
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB, IRNode.ADD})
// Checks 0 - (a >> 63) => a >>> 63
public long simpleFourteen(long a) {
return 0 - (a >> 63);
}
@Test
@Arguments(Argument.RANDOM_EACH)
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB, IRNode.ADD})
// Checks 0 - (0 - x) => x
public long simpleFifteen(long x) {
return 0 - (0 - x);
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB, IRNode.ADD})
// Checks (x + y) -y => y
public long simpleSixteen(long x, long y) {
return (x + y) - y;
}
@Test
@Arguments({Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = {IRNode.LOAD, IRNode.STORE, IRNode.MUL, IRNode.DIV, IRNode.SUB, IRNode.ADD})
// Checks (x + y) - x => y
public long simpleSeventeen(long x, long y) {
return (x + y) - x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment