8294715: Add IR checks to the reduction vectorization tests

Reviewed-by: rcastanedalo, epeter
This commit is contained in:
Daniel Skantz 2023-03-13 07:33:46 +00:00 committed by Emanuel Peter
parent c313e1ac7b
commit d20bde29f2
13 changed files with 623 additions and 685 deletions

View File

@ -181,6 +181,16 @@ public class IRNode {
superWordNodes(ADD_REDUCTION_VF, "AddReductionVF");
}
public static final String ADD_REDUCTION_VI = PREFIX + "ADD_REDUCTION_VI" + POSTFIX;
static {
superWordNodes(ADD_REDUCTION_VI, "AddReductionVI");
}
public static final String ADD_REDUCTION_VL = PREFIX + "ADD_REDUCTION_VL" + POSTFIX;
static {
superWordNodes(ADD_REDUCTION_VL, "AddReductionVL");
}
public static final String ALLOC = PREFIX + "ALLOC" + POSTFIX;
static {
String optoRegex = "(.*precise .*\\R((.*(?i:mov|xorl|nop|spill).*|\\s*)\\R)*.*(?i:call,static).*wrapper for: _new_instance_Java" + END;
@ -230,6 +240,11 @@ public class IRNode {
beforeMatchingNameRegex(AND_V_MASK, "AndVMask");
}
public static final String AND_REDUCTION_V = PREFIX + "AND_REDUCTION_V" + POSTFIX;
static {
superWordNodes(AND_REDUCTION_V, "AndReductionV");
}
public static final String CALL = PREFIX + "CALL" + POSTFIX;
static {
beforeMatchingNameRegex(CALL, "Call.*Java");
@ -709,6 +724,16 @@ public class IRNode {
superWordNodes(MUL_REDUCTION_VF, "MulReductionVF");
}
public static final String MUL_REDUCTION_VI = PREFIX + "MUL_REDUCTION_VI" + POSTFIX;
static {
superWordNodes(MUL_REDUCTION_VI, "MulReductionVI");
}
public static final String MUL_REDUCTION_VL = PREFIX + "MUL_REDUCTION_VL" + POSTFIX;
static {
superWordNodes(MUL_REDUCTION_VL, "MulReductionVL");
}
public static final String NEG_V = PREFIX + "NEG_V" + POSTFIX;
static {
beforeMatchingNameRegex(NEG_V, "NegV(F|D)");
@ -734,6 +759,11 @@ public class IRNode {
beforeMatchingNameRegex(OR_V_MASK, "OrVMask");
}
public static final String OR_REDUCTION_V = PREFIX + "OR_REDUCTION_V" + POSTFIX;
static {
superWordNodes(OR_REDUCTION_V, "OrReductionV");
}
public static final String OUTER_STRIP_MINED_LOOP = PREFIX + "OUTER_STRIP_MINED_LOOP" + POSTFIX;
static {
String regex = START + "OuterStripMinedLoop\\b" + MID + END;
@ -1353,6 +1383,11 @@ public class IRNode {
beforeMatchingNameRegex(XOR_V_MASK, "XorVMask");
}
public static final String XOR_REDUCTION_V = PREFIX + "XOR_REDUCTION_V" + POSTFIX;
static {
superWordNodes(XOR_REDUCTION_V, "XorReductionV");
}
public static final String XOR3_NEON = PREFIX + "XOR3_NEON" + POSTFIX;
static {
machOnlyNameRegex(XOR3_NEON, "veor3_neon");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -25,59 +25,40 @@
* @test
* @bug 8074981
* @summary Add C2 x86 Superword support for scalar product reduction optimizations : float test
* @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64" | os.arch=="riscv64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.ProdRed_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.ProdRed_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.ProdRed_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.ProdRed_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.ProdRed_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.ProdRed_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.ProdRed_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.ProdRed_Double
* @library /test/lib /
* @run driver compiler.loopopts.superword.ProdRed_Double
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class ProdRed_Double {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"prodReductionImplement",
"prodReductionWithStoreImplement"},
mode = RunMode.STANDALONE)
public void runTests() throws Exception {
double[] a = new double[256 * 1024];
double[] b = new double[256 * 1024];
double[] c = new double[256 * 1024];
prodReductionInit(a, b);
double valid = 2000;
double total = 0;
@ -85,13 +66,13 @@ public class ProdRed_Double {
total = j + 1;
total = prodReductionImplement(a, b, total);
}
if (total == valid) {
System.out.println("Success");
} else {
System.out.println("Invalid sum of elements variable in total: " + total);
System.out.println("Expected value = " + valid);
throw new Exception("Failed");
testCorrectness(valid, total, "prodReduction");
total = 0;
for (int j = 0; j < 2000; j++) {
total = j + 1;
total = prodReductionWithStoreImplement(a, b, c, total);
}
testCorrectness(valid, total, "prodReductionWithStore");
}
public static void prodReductionInit(double[] a, double[] b) {
@ -101,6 +82,11 @@ public class ProdRed_Double {
}
}
/* Vectorization is expected but not enabled (SuperWord::implemented).
A positive @IR test should be added later. */
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.MUL_REDUCTION_VD})
public static double prodReductionImplement(double[] a, double[] b, double total) {
for (int i = 0; i < a.length; i++) {
total *= a[i] - b[i];
@ -108,4 +94,29 @@ public class ProdRed_Double {
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.MUL_REDUCTION_VD})
@IR(applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
applyIfCPUFeature = {"sse2", "true"},
counts = {IRNode.MUL_REDUCTION_VD, ">= 1"})
public static double prodReductionWithStoreImplement(double[] a, double[] b, double[] c, double total) {
for (int i = 0; i < a.length; i++) {
c[i] = a[i] - b[i];
total *= c[i];
}
return total;
}
public static void testCorrectness(
double total,
double valid,
String op) throws Exception {
if (total != valid) {
throw new Exception(
"Invalid total: " + total + " " +
"Expected value = " + valid + " " + op + ": Failed");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -25,57 +25,36 @@
* @test
* @bug 8074981
* @summary Add C2 x86 Superword support for scalar product reduction optimizations : float test
* @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64" | os.arch=="riscv64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.ProdRed_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.ProdRed_Float
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.ProdRed_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.ProdRed_Float
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.ProdRed_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.ProdRed_Float
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.ProdRed_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.ProdRed_Float
* @library /test/lib /
* @run driver compiler.loopopts.superword.ProdRed_Float
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class ProdRed_Float {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"prodReductionImplement"},
mode = RunMode.STANDALONE)
public void runTests() throws Exception {
float[] a = new float[256 * 1024];
float[] b = new float[256 * 1024];
prodReductionInit(a, b);
@ -101,6 +80,12 @@ public class ProdRed_Float {
}
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.MUL_REDUCTION_VF})
@IR(applyIfCPUFeature = {"sse4.1", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.MUL_REDUCTION_VF, ">= 1"})
public static float prodReductionImplement(float[] a, float[] b, float total) {
for (int i = 0; i < a.length; i++) {
total *= a[i] - b[i];

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -25,57 +25,36 @@
* @test
* @bug 8074981
* @summary Add C2 x86 Superword support for scalar product reduction optimizations : int test
* @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64" | os.arch=="riscv64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.ProdRed_Int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.ProdRed_Int
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.ProdRed_Int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.ProdRed_Int
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.ProdRed_Int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.ProdRed_Int
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.ProdRed_Int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.ProdRed_Int
* @library /test/lib /
* @run driver compiler.loopopts.superword.ProdRed_Int
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class ProdRed_Int {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"prodReductionImplement"},
mode = RunMode.STANDALONE)
public void runTests() throws Exception {
int[] a = new int[256 * 1024];
int[] b = new int[256 * 1024];
prodReductionInit(a, b);
@ -100,6 +79,12 @@ public class ProdRed_Int {
}
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.MUL_REDUCTION_VI})
@IR(applyIfCPUFeature = {"sse4.1", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.MUL_REDUCTION_VI, ">= 1"})
public static int prodReductionImplement(int[] a, int[] b, int total) {
for (int i = 0; i < a.length; i++) {
total *= a[i] + b[i];

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, 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
@ -25,111 +25,83 @@
* @test
* @bug 8240248
* @summary Add C2 x86 Superword support for scalar logical reduction optimizations : int test
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-TieredCompilation
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.RedTest_int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.RedTest_int
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-TieredCompilation
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.RedTest_int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.RedTest_int
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-TieredCompilation
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.RedTest_int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.RedTest_int
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-TieredCompilation
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.RedTest_int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.RedTest_int
* @library /test/lib /
* @run driver compiler.loopopts.superword.RedTest_int
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class RedTest_int {
static final int NUM = 1024;
static final int ITER = 8000;
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:+SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll,
"-XX:-TieredCompilation");
i++;
}
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:-SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"sumReductionImplement",
"orReductionImplement",
"andReductionImplement",
"xorReductionImplement",
"mulReductionImplement"},
mode = RunMode.STANDALONE)
public void runTests() throws Exception {
int[] a = new int[NUM];
int[] b = new int[NUM];
int[] c = new int[NUM];
int[] d = new int[NUM];
reductionInit1(a, b, c);
int total = 0;
int valid = 0;
int valid = 1454604288;
for (int j = 0; j < ITER; j++) {
total = sumReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid += d[j];
total = sumReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "Add Reduction");
valid = 0;
total = 0;
valid = 91586175;
for (int j = 0; j < ITER; j++) {
total = orReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid |= d[j];
total = orReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "Or Reduction");
valid = -1;
total = -1;
valid = 91492404;
for (int j = 0; j < ITER; j++) {
total = andReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid &= d[j];
total = andReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "And Reduction");
total = -1;
valid = -1;
for (int j = 0; j < ITER; j++) {
total = xorReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid ^= d[j];
total = xorReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "Xor Reduction");
reductionInit2(a, b, c);
valid = 1;
total = 1;
valid = 1690042369;
for (int j = 0; j < ITER; j++) {
total = mulReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid *= d[j];
total = mulReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "Mul Reduction");
}
@ -157,67 +129,87 @@ public class RedTest_int {
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VI})
@IR(applyIfCPUFeature = {"sse4.1", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.ADD_REDUCTION_VI, ">= 1"})
public static int sumReductionImplement(
int[] a,
int[] b,
int[] c,
int[] d) {
int total = 0;
int total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total += d[i];
total += (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.OR_REDUCTION_V})
@IR(applyIfCPUFeature = {"sse4.1", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.OR_REDUCTION_V, ">= 1"})
public static int orReductionImplement(
int[] a,
int[] b,
int[] c,
int[] d) {
int total = 0;
int total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total |= d[i];
total |= (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.AND_REDUCTION_V})
@IR(applyIfCPUFeature = {"sse4.1", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.AND_REDUCTION_V, ">= 1"})
public static int andReductionImplement(
int[] a,
int[] b,
int[] c,
int[] d) {
int total = -1;
int total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total &= d[i];
total &= (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.XOR_REDUCTION_V})
@IR(applyIfCPUFeature = {"sse4.1", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.XOR_REDUCTION_V, ">= 1"})
public static int xorReductionImplement(
int[] a,
int[] b,
int[] c,
int[] d) {
int total = -1;
int total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total ^= d[i];
total ^= (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.MUL_REDUCTION_VI})
@IR(applyIfCPUFeature = {"sse4.1", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.MUL_REDUCTION_VI, ">= 1"})
public static int mulReductionImplement(
int[] a,
int[] b,
int[] c,
int[] d) {
int total = 1;
int total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total = total*d[i];
total *= (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@ -226,12 +218,10 @@ public class RedTest_int {
int total,
int valid,
String op) throws Exception {
if (total == valid) {
System.out.println(op + ": Success");
} else {
System.out.println("Invalid total: " + total);
System.out.println("Expected value = " + valid);
throw new Exception(op + ": Failed");
if (total != valid) {
throw new Exception(
"Invalid total: " + total + " " +
"Expected value = " + valid + " " + op + ": Failed");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, 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
@ -25,111 +25,84 @@
* @test
* @bug 8240248
* @summary Add C2 x86 Superword support for scalar logical reduction optimizations : long test
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-TieredCompilation
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.RedTest_long
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.RedTest_long
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-TieredCompilation
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.RedTest_long
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.RedTest_long
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-TieredCompilation
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.RedTest_long
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.RedTest_long
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-TieredCompilation
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.RedTest_long
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.RedTest_long
* @requires vm.bits == "64"
* @library /test/lib /
* @run driver compiler.loopopts.superword.RedTest_long
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class RedTest_long {
static final int NUM = 512;
static final int ITER = 8000;
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:+SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll,
"-XX:-TieredCompilation");
i++;
}
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:-SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"sumReductionImplement",
"orReductionImplement",
"andReductionImplement",
"xorReductionImplement",
"mulReductionImplement"},
mode = RunMode.STANDALONE)
public static void runTests() throws Exception {
long[] a = new long[NUM];
long[] b = new long[NUM];
long[] c = new long[NUM];
long[] d = new long[NUM];
reductionInit1(a, b, c);
long total = 0;
long valid = 0;
long valid = 374944929792000L;
for (int j = 0; j < ITER; j++) {
total = sumReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid += d[j];
total = sumReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "Add Reduction");
valid = 0;
total = 0;
valid = 91586175;
for (int j = 0; j < ITER; j++) {
total = orReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid |= d[j];
total = orReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "Or Reduction");
valid = -1;
total = -1;
valid = 91492404;
for (int j = 0; j < ITER; j++) {
total = andReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid &= d[j];
total = andReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "And Reduction");
total = -1;
valid = -1;
for (int j = 0; j < ITER; j++) {
total = xorReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid ^= d[j];
total = xorReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "Xor Reduction");
reductionInit2(a, b, c);
valid = 1;
total = 1;
valid = 2953257964269338625L;
for (int j = 0; j < ITER; j++) {
total = mulReductionImplement(a, b, c, d);
}
for (int j = 0; j < d.length; j++) {
valid *= d[j];
total = mulReductionImplement(a, b, c, total);
}
testCorrectness(total, valid, "Mul Reduction");
}
@ -157,67 +130,89 @@ public class RedTest_long {
}
/* Require avx2 due to filtering out small vector lengths
for long and int (SuperWord::implemented). */
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VL})
@IR(applyIfCPUFeature = {"avx2", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.ADD_REDUCTION_VL, ">= 1"})
public static long sumReductionImplement(
long[] a,
long[] b,
long[] c,
long[] d) {
long total = 0;
long total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total += d[i];
total += (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.OR_REDUCTION_V})
@IR(applyIfCPUFeature = {"avx2", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.OR_REDUCTION_V, ">= 1"})
public static long orReductionImplement(
long[] a,
long[] b,
long[] c,
long[] d) {
long total = 0;
long total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total |= d[i];
total |= (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.AND_REDUCTION_V})
@IR(applyIfCPUFeature = {"avx2", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.AND_REDUCTION_V, ">= 1"})
public static long andReductionImplement(
long[] a,
long[] b,
long[] c,
long[] d) {
long total = -1;
long total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total &= d[i];
total &= (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.XOR_REDUCTION_V})
@IR(applyIfCPUFeature = {"avx2", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.XOR_REDUCTION_V, ">= 1"})
public static long xorReductionImplement(
long[] a,
long[] b,
long[] c,
long[] d) {
long total = -1;
long total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total ^= d[i];
total ^= (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.MUL_REDUCTION_VL})
@IR(applyIfCPUFeature = {"avx512dq", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.MUL_REDUCTION_VL, ">= 1"})
public static long mulReductionImplement(
long[] a,
long[] b,
long[] c,
long[] d) {
long total = 1;
long total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total = total*d[i];
total *= (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@ -226,12 +221,10 @@ public class RedTest_long {
long total,
long valid,
String op) throws Exception {
if (total == valid) {
System.out.println(op + ": Success");
} else {
System.out.println("Invalid total: " + total);
System.out.println("Expected value = " + valid);
throw new Exception(op + ": Failed");
if (total != valid) {
throw new Exception(
"Invalid total: " + total + " " +
"Expected value = " + valid + " " + op + ": Failed");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -25,67 +25,45 @@
* @test
* @bug 8138583
* @summary Add C2 AArch64 Superword support for scalar sum reduction optimizations : double abs & neg test
* @requires os.arch=="aarch64" | os.arch=="riscv64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRedAbsNeg_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRedAbsNeg_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRedAbsNeg_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRedAbsNeg_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRedAbsNeg_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRedAbsNeg_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRedAbsNeg_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRedAbsNeg_Double
* @library /test/lib /
* @run driver compiler.loopopts.superword.SumRedAbsNeg_Double
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class SumRedAbsNeg_Double {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"sumReductionImplement"},
mode = RunMode.STANDALONE)
public void runTests() throws Exception {
double[] a = new double[256 * 1024];
double[] b = new double[256 * 1024];
double[] c = new double[256 * 1024];
double[] d = new double[256 * 1024];
sumReductionInit(a, b, c);
double total = 0;
double valid = 3.6028590866691944E19;
for (int j = 0; j < 2000; j++) {
total = sumReductionImplement(a, b, c, d, total);
total = sumReductionImplement(a, b, c, total);
}
if (total == valid) {
@ -110,15 +88,18 @@ public class SumRedAbsNeg_Double {
}
}
/* Does not vectorize due to profitability heuristic
(with or without store) in SuperWord::profitable. */
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VD, IRNode.ABS_V, IRNode.NEG_V})
public static double sumReductionImplement(
double[] a,
double[] b,
double[] c,
double[] d,
double total) {
for (int i = 0; i < a.length; i++) {
d[i] = Math.abs(-a[i] * -b[i]) + Math.abs(-a[i] * -c[i]) + Math.abs(-b[i] * -c[i]);
total += d[i];
total += Math.abs(-a[i] * -b[i]) + Math.abs(-a[i] * -c[i]) + Math.abs(-b[i] * -c[i]);
}
return total;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -25,67 +25,45 @@
* @test
* @bug 8138583
* @summary Add C2 AArch64 Superword support for scalar sum reduction optimizations : float abs & neg test
* @requires os.arch=="aarch64" | os.arch=="riscv64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRedAbsNeg_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRedAbsNeg_Float
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRedAbsNeg_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRedAbsNeg_Float
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRedAbsNeg_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRedAbsNeg_Float
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRedAbsNeg_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRedAbsNeg_Float
* @library /test/lib /
* @run driver compiler.loopopts.superword.SumRedAbsNeg_Float
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class SumRedAbsNeg_Float {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"sumReductionImplement"},
mode = RunMode.STANDALONE)
public void runTests() throws Exception {
float[] a = new float[256 * 1024];
float[] b = new float[256 * 1024];
float[] c = new float[256 * 1024];
float[] d = new float[256 * 1024];
sumReductionInit(a, b, c);
float total = 0;
float valid = (float) 4.611686E18;
for (int j = 0; j < 2000; j++) {
total = sumReductionImplement(a, b, c, d, total);
total = sumReductionImplement(a, b, c, total);
}
if (total == valid) {
@ -110,15 +88,19 @@ public class SumRedAbsNeg_Float {
}
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VF, IRNode.ABS_V, IRNode.NEG_V})
@IR(applyIfCPUFeature = {"sse2", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.ADD_REDUCTION_VF, ">= 1", IRNode.ABS_V, ">= 1", IRNode.NEG_V, ">= 1"})
public static float sumReductionImplement(
float[] a,
float[] b,
float[] c,
float[] d,
float total) {
for (int i = 0; i < a.length; i++) {
d[i] = Math.abs(-a[i] * -b[i]) + Math.abs(-a[i] * -c[i]) + Math.abs(-b[i] * -c[i]);
total += d[i];
total += Math.abs(-a[i] * -b[i]) + Math.abs(-a[i] * -c[i]) + Math.abs(-b[i] * -c[i]);
}
return total;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023, 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
@ -25,58 +25,37 @@
* @test
* @bug 8135028
* @summary Add C2 x86 Superword support for scalar sum reduction optimizations : double sqrt test
* @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64" | os.arch=="riscv64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRedSqrt_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRedSqrt_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRedSqrt_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRedSqrt_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRedSqrt_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRedSqrt_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRedSqrt_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRedSqrt_Double
* @library /test/lib /
* @run driver compiler.loopopts.superword.SumRedSqrt_Double
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class SumRedSqrt_Double {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"sumReductionWithStoreImplement"},
mode = RunMode.STANDALONE)
public void runTests() throws Exception {
double[] a = new double[256 * 1024];
double[] b = new double[256 * 1024];
double[] c = new double[256 * 1024];
@ -85,15 +64,9 @@ public class SumRedSqrt_Double {
double total = 0;
double valid = 2.06157643776E14;
for (int j = 0; j < 2000; j++) {
total = sumReductionImplement(a, b, c, d, total);
}
if (total == valid) {
System.out.println("Success");
} else {
System.out.println("Invalid sum of elements variable in total: " + total);
System.out.println("Expected value = " + valid);
throw new Exception("Failed");
total = sumReductionWithStoreImplement(a, b, c, d, total);
}
testCorrectness(total, valid, "sumReductionWithStore");
}
public static void sumReductionInit(
@ -109,7 +82,16 @@ public class SumRedSqrt_Double {
}
}
public static double sumReductionImplement(
/* Vectorization is expected but not enabled without store.
The store could be removed later.
Require avx for SQRT_VD. */
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VD, IRNode.SQRT_V})
@IR(applyIfCPUFeature = {"avx", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.ADD_REDUCTION_VD, ">= 1", IRNode.SQRT_V, ">= 1"})
public static double sumReductionWithStoreImplement(
double[] a,
double[] b,
double[] c,
@ -122,4 +104,15 @@ public class SumRedSqrt_Double {
return total;
}
public static void testCorrectness(
double total,
double valid,
String op) throws Exception {
if (total != valid) {
throw new Exception(
"Invalid total: " + total + " " +
"Expected value = " + valid + " " + op + ": Failed");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -25,57 +25,37 @@
* @test
* @bug 8074981
* @summary Add C2 x86 Superword support for scalar sum reduction optimizations : double test
* @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64" | os.arch=="riscv64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRed_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRed_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRed_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRed_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRed_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRed_Double
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRed_Double
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRed_Double
* @library /test/lib /
* @run driver compiler.loopopts.superword.SumRed_Double
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class SumRed_Double {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"sumReductionImplement",
"sumReductionWithStoreImplement"},
mode = RunMode.STANDALONE)
public static void runTests() throws Exception {
double[] a = new double[256 * 1024];
double[] b = new double[256 * 1024];
double[] c = new double[256 * 1024];
@ -84,15 +64,14 @@ public class SumRed_Double {
double total = 0;
double valid = 3.6028590866691944E19;
for (int j = 0; j < 2000; j++) {
total = sumReductionImplement(a, b, c, d, total);
total = sumReductionImplement(a, b, c, total);
}
if (total == valid) {
System.out.println("Success");
} else {
System.out.println("Invalid sum of elements variable in total: " + total);
System.out.println("Expected value = " + valid);
throw new Exception("Failed");
testCorrectness(total, valid, "sumReduction");
total = 0;
for (int j = 0; j < 2000; j++) {
total = sumReductionWithStoreImplement(a, b, c, d, total);
}
testCorrectness(total, valid, "sumReductionWithStore");
}
public static void sumReductionInit(
@ -108,7 +87,29 @@ public class SumRed_Double {
}
}
/* Vectorization is expected but not enabled.
A positive IR rule should be added later. */
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VD})
public static double sumReductionImplement(
double[] a,
double[] b,
double[] c,
double total) {
for (int i = 0; i < a.length; i++) {
total += (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VD})
@IR(applyIfCPUFeature = {"sse2", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.ADD_REDUCTION_VD, ">= 1"})
public static double sumReductionWithStoreImplement(
double[] a,
double[] b,
double[] c,
@ -121,4 +122,15 @@ public class SumRed_Double {
return total;
}
public static void testCorrectness(
double total,
double valid,
String op) throws Exception {
if (total != valid) {
throw new Exception(
"Invalid total: " + total + " " +
"Expected value = " + valid + " " + op + ": Failed");
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -25,66 +25,44 @@
* @test
* @bug 8074981
* @summary Add C2 x86 Superword support for scalar sum reduction optimizations : float test
* @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64" | os.arch=="riscv64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRed_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRed_Float
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRed_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRed_Float
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRed_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRed_Float
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRed_Float
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRed_Float
* @library /test/lib /
* @run driver compiler.loopopts.superword.SumRed_Float
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class SumRed_Float {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"sumReductionImplement"},
mode = RunMode.STANDALONE)
public static void runTests() throws Exception {
float[] a = new float[256 * 1024];
float[] b = new float[256 * 1024];
float[] c = new float[256 * 1024];
float[] d = new float[256 * 1024];
sumReductionInit(a, b, c);
float total = 0;
float valid = (float) 4.611686E18;
for (int j = 0; j < 2000; j++) {
total = sumReductionImplement(a, b, c, d, total);
total = sumReductionImplement(a, b, c, total);
}
if (total == valid) {
System.out.println("Success");
@ -108,15 +86,19 @@ public class SumRed_Float {
}
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VF})
@IR(applyIfCPUFeature = {"sse2", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.ADD_REDUCTION_VF, ">= 1"})
public static float sumReductionImplement(
float[] a,
float[] b,
float[] c,
float[] d,
float total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total += d[i];
total += (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -25,66 +25,44 @@
* @test
* @bug 8074981
* @summary Add C2 x86 Superword support for scalar sum reduction optimizations : int test
* @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64" | os.arch=="aarch64" | os.arch=="riscv64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRed_Int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=2
* compiler.loopopts.superword.SumRed_Int
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRed_Int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRed_Int
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRed_Int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRed_Int
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRed_Int
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=16
* compiler.loopopts.superword.SumRed_Int
* @library /test/lib /
* @run driver compiler.loopopts.superword.SumRed_Int
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class SumRed_Int {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[6];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8, 16}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"sumReductionImplement"},
mode = RunMode.STANDALONE)
public static void runTests() throws Exception {
int[] a = new int[256 * 1024];
int[] b = new int[256 * 1024];
int[] c = new int[256 * 1024];
int[] d = new int[256 * 1024];
sumReductionInit(a, b, c);
int total = 0;
int valid = 262144000;
for (int j = 0; j < 2000; j++) {
total = sumReductionImplement(a, b, c, d, total);
total = sumReductionImplement(a, b, c, total);
}
if (total == valid) {
System.out.println("Success");
@ -108,15 +86,19 @@ public class SumRed_Int {
}
}
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VI})
@IR(applyIfCPUFeature = {"sse4.1", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.ADD_REDUCTION_VI, ">= 1"})
public static int sumReductionImplement(
int[] a,
int[] b,
int[] c,
int[] d,
int total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total += d[i];
total += (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2023, 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
@ -25,44 +25,45 @@
* @test
* @bug 8076276
* @summary Add C2 x86 Superword support for scalar sum reduction optimizations : long test
* @requires os.arch=="x86" | os.arch=="i386" | os.arch=="amd64" | os.arch=="x86_64"
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRed_Long
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=4
* compiler.loopopts.superword.SumRed_Long
*
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:+SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRed_Long
* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:LoopUnrollLimit=250
* -XX:CompileThresholdScaling=0.1
* -XX:-SuperWordReductions
* -XX:LoopMaxUnroll=8
* compiler.loopopts.superword.SumRed_Long
* @requires vm.bits == "64"
* @library /test/lib /
* @run driver compiler.loopopts.superword.SumRed_Long
*/
package compiler.loopopts.superword;
import compiler.lib.ir_framework.*;
public class SumRed_Long {
public static void main(String[] args) throws Exception {
TestFramework framework = new TestFramework();
framework.addFlags("-XX:+IgnoreUnrecognizedVMOptions",
"-XX:LoopUnrollLimit=250",
"-XX:CompileThresholdScaling=0.1");
int i = 0;
Scenario[] scenarios = new Scenario[4];
for (String reductionSign : new String[] {"+", "-"}) {
for (int maxUnroll : new int[] {4, 8}) {
scenarios[i] = new Scenario(i, "-XX:" + reductionSign + "SuperWordReductions",
"-XX:LoopMaxUnroll=" + maxUnroll);
i++;
}
}
framework.addScenarios(scenarios);
framework.start();
}
@Run(test = {"sumReductionImplement"},
mode = RunMode.STANDALONE)
public static void runTests() throws Exception {
long[] a = new long[256 * 1024];
long[] b = new long[256 * 1024];
long[] c = new long[256 * 1024];
long[] d = new long[256 * 1024];
sumReductionInit(a, b, c);
long total = 0;
long valid = 262144000;
for (int j = 0; j < 2000; j++) {
total = sumReductionImplement(a, b, c, d, total);
total = sumReductionImplement(a, b, c, total);
}
total = (int) total;
if (total == valid) {
@ -87,15 +88,21 @@ public class SumRed_Long {
}
}
/* Require avx2 due to filtering out small vector lengths
for long and int (SuperWord::implemented). */
@Test
@IR(applyIf = {"SuperWordReductions", "false"},
failOn = {IRNode.ADD_REDUCTION_VL})
@IR(applyIfCPUFeature = {"avx2", "true"},
applyIfAnd = {"SuperWordReductions", "true", "LoopMaxUnroll", ">= 8"},
counts = {IRNode.ADD_REDUCTION_VL, ">= 1"})
public static long sumReductionImplement(
long[] a,
long[] b,
long[] c,
long[] d,
long total) {
for (int i = 0; i < a.length; i++) {
d[i] = (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
total += d[i];
total += (a[i] * b[i]) + (a[i] * c[i]) + (b[i] * c[i]);
}
return total;
}