diff options
Diffstat (limited to 'test/656-checker-simd-opt/src/Main.java')
-rw-r--r-- | test/656-checker-simd-opt/src/Main.java | 206 |
1 files changed, 164 insertions, 42 deletions
diff --git a/test/656-checker-simd-opt/src/Main.java b/test/656-checker-simd-opt/src/Main.java index 091633ff34..39a126f5d3 100644 --- a/test/656-checker-simd-opt/src/Main.java +++ b/test/656-checker-simd-opt/src/Main.java @@ -92,7 +92,91 @@ public class Main { } } - public static void main(String[] args) { + /// CHECK-START: long Main.longInductionReduction(long[]) loop_optimization (before) + /// CHECK-DAG: <<L0:j\d+>> LongConstant 0 loop:none + /// CHECK-DAG: <<L1:j\d+>> LongConstant 1 loop:none + /// CHECK-DAG: <<I0:i\d+>> IntConstant 0 loop:none + /// CHECK-DAG: <<Get:j\d+>> ArrayGet [{{l\d+}},<<I0>>] loop:none + /// CHECK-DAG: <<Phi1:j\d+>> Phi [<<L0>>,<<Add1:j\d+>>] loop:<<Loop:B\d+>> outer_loop:none + /// CHECK-DAG: <<Phi2:j\d+>> Phi [<<L1>>,<<Add2:j\d+>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Add2>> Add [<<Phi2>>,<<Get>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Add1>> Add [<<Phi1>>,<<L1>>] loop:<<Loop>> outer_loop:none + // + /// CHECK-START-ARM64: long Main.longInductionReduction(long[]) loop_optimization (after) + /// CHECK-DAG: <<L0:j\d+>> LongConstant 0 loop:none + /// CHECK-DAG: <<L1:j\d+>> LongConstant 1 loop:none + /// CHECK-DAG: <<L2:j\d+>> LongConstant 2 loop:none + /// CHECK-DAG: <<I0:i\d+>> IntConstant 0 loop:none + /// CHECK-DAG: <<Get:j\d+>> ArrayGet [{{l\d+}},<<I0>>] loop:none + /// CHECK-DAG: <<Rep:d\d+>> VecReplicateScalar [<<Get>>] loop:none + /// CHECK-DAG: <<Set:d\d+>> VecSetScalars [<<L1>>] loop:none + /// CHECK-DAG: <<Phi1:j\d+>> Phi [<<L0>>,{{j\d+}}] loop:<<Loop:B\d+>> outer_loop:none + /// CHECK-DAG: <<Phi2:d\d+>> Phi [<<Set>>,{{d\d+}}] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: VecAdd [<<Phi2>>,<<Rep>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: Add [<<Phi1>>,<<L2>>] loop:<<Loop>> outer_loop:none + static long longInductionReduction(long[] y) { + long x = 1; + for (long i = 0; i < 10; i++) { + x += y[0]; + } + return x; + } + + /// CHECK-START: void Main.intVectorLongInvariant(int[], long[]) loop_optimization (before) + /// CHECK-DAG: <<I0:i\d+>> IntConstant 0 loop:none + /// CHECK-DAG: <<I1:i\d+>> IntConstant 1 loop:none + /// CHECK-DAG: <<Get:j\d+>> ArrayGet [{{l\d+}},<<I0>>] loop:none + /// CHECK-DAG: <<Phi:i\d+>> Phi [<<I0>>,<<Add:i\d+>>] loop:<<Loop:B\d+>> outer_loop:none + /// CHECK-DAG: <<Cnv:i\d+>> TypeConversion [<<Get>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: ArraySet [{{l\d+}},<<Phi>>,<<Cnv>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Add>> Add [<<Phi>>,<<I1>>] loop:<<Loop>> outer_loop:none + // + /// CHECK-START-ARM64: void Main.intVectorLongInvariant(int[], long[]) loop_optimization (after) + /// CHECK-DAG: <<I0:i\d+>> IntConstant 0 loop:none + /// CHECK-DAG: <<I1:i\d+>> IntConstant 1 loop:none + /// CHECK-DAG: <<I4:i\d+>> IntConstant 4 loop:none + /// CHECK-DAG: <<Get:j\d+>> ArrayGet [{{l\d+}},<<I0>>] loop:none + /// CHECK-DAG: <<Cnv:i\d+>> TypeConversion [<<Get>>] loop:none + /// CHECK-DAG: <<Rep:d\d+>> VecReplicateScalar [<<Cnv>>] loop:none + /// CHECK-DAG: <<Phi:i\d+>> Phi [<<I0>>,{{i\d+}}] loop:<<Loop:B\d+>> outer_loop:none + /// CHECK-DAG: VecStore [{{l\d+}},<<Phi>>,<<Rep>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: Add [<<Phi>>,<<I4>>] loop:<<Loop>> outer_loop:none + static void intVectorLongInvariant(int[] x, long[] y) { + for (int i = 0; i < 100; i++) { + x[i] = (int) y[0]; + } + } + + /// CHECK-START: void Main.longCanBeDoneWithInt(int[], int[]) loop_optimization (before) + /// CHECK-DAG: <<I0:i\d+>> IntConstant 0 loop:none + /// CHECK-DAG: <<I1:i\d+>> IntConstant 1 loop:none + /// CHECK-DAG: <<L1:j\d+>> LongConstant 1 loop:none + /// CHECK-DAG: <<Phi:i\d+>> Phi [<<I0>>,<<Add:i\d+>>] loop:<<Loop:B\d+>> outer_loop:none + /// CHECK-DAG: <<Get:i\d+>> ArrayGet [{{l\d+}},<<Phi>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Cnv1:j\d+>> TypeConversion [<<Get>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<AddL:j\d+>> Add [<<Cnv1>>,<<L1>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Cnv2:i\d+>> TypeConversion [<<AddL>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: ArraySet [{{l\d+}},<<Phi>>,<<Cnv2>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Add>> Add [<<Phi>>,<<I1>>] loop:<<Loop>> outer_loop:none + // + /// CHECK-START-ARM64: void Main.longCanBeDoneWithInt(int[], int[]) loop_optimization (after) + /// CHECK-DAG: <<I0:i\d+>> IntConstant 0 loop:none + /// CHECK-DAG: <<I4:i\d+>> IntConstant 4 loop:none + /// CHECK-DAG: <<L1:j\d+>> LongConstant 1 loop:none + /// CHECK-DAG: <<Cnv:i\d+>> TypeConversion [<<L1>>] loop:none + /// CHECK-DAG: <<Rep:d\d+>> VecReplicateScalar [<<Cnv>>] loop:none + /// CHECK-DAG: <<Phi:i\d+>> Phi [<<I0>>,{{i\d+}}] loop:<<Loop:B\d+>> outer_loop:none + /// CHECK-DAG: <<Load:d\d+>> VecLoad [{{l\d+}},<<Phi>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: <<Add:d\d+>> VecAdd [<<Load>>,<<Rep>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: VecStore [{{l\d+}},<<Phi>>,<<Add>>] loop:<<Loop>> outer_loop:none + /// CHECK-DAG: Add [<<Phi>>,<<I4>>] loop:<<Loop>> outer_loop:none + static void longCanBeDoneWithInt(int[] x, int[] y) { + for (int i = 0; i < 100; i++) { + x[i] = (int) (y[i] + 1L); + } + } + + static void testUnroll() { float[] x = new float[100]; float[] y = new float[100]; for (int i = 0; i < 100; i++) { @@ -104,51 +188,89 @@ public class Main { expectEquals(5.0f, x[i]); expectEquals(2.0f, y[i]); } - { - int[] a = new int[100]; - int[] b = new int[100]; - for (int i = 0; i < 100; i++) { - a[i] = 0; - b[i] = i; - } - stencil(a, b, 100); - for (int i = 1; i < 99; i++) { - int e = i + i + i; - expectEquals(e, a[i]); - expectEquals(i, b[i]); - } - } - { - int[] a = new int[100]; - int[] b = new int[100]; - for (int i = 0; i < 100; i++) { - a[i] = 0; - b[i] = i; - } - stencilSubInt(a, b, 100); - for (int i = 1; i < 99; i++) { - int e = i + i + i; - expectEquals(e, a[i]); - expectEquals(i, b[i]); - } - } - { - int[] a = new int[100]; - int[] b = new int[100]; - for (int i = 0; i < 100; i++) { - a[i] = 0; - b[i] = i; - } - stencilAddInt(a, b, 100); - for (int i = 1; i < 99; i++) { - int e = i + i + i; - expectEquals(e, a[i]); - expectEquals(i, b[i]); - } + } + + static void testStencil1() { + int[] a = new int[100]; + int[] b = new int[100]; + for (int i = 0; i < 100; i++) { + a[i] = 0; + b[i] = i; + } + stencil(a, b, 100); + for (int i = 1; i < 99; i++) { + int e = i + i + i; + expectEquals(e, a[i]); + expectEquals(i, b[i]); + } + } + + static void testStencil2() { + int[] a = new int[100]; + int[] b = new int[100]; + for (int i = 0; i < 100; i++) { + a[i] = 0; + b[i] = i; + } + stencilSubInt(a, b, 100); + for (int i = 1; i < 99; i++) { + int e = i + i + i; + expectEquals(e, a[i]); + expectEquals(i, b[i]); } + } + + static void testStencil3() { + int[] a = new int[100]; + int[] b = new int[100]; + for (int i = 0; i < 100; i++) { + a[i] = 0; + b[i] = i; + } + stencilAddInt(a, b, 100); + for (int i = 1; i < 99; i++) { + int e = i + i + i; + expectEquals(e, a[i]); + expectEquals(i, b[i]); + } + } + + static void testTypes() { + int[] a = new int[100]; + int[] b = new int[100]; + long[] l = { 3 }; + expectEquals(31, longInductionReduction(l)); + intVectorLongInvariant(a, l); + for (int i = 0; i < 100; i++) { + expectEquals(3, a[i]); + } + longCanBeDoneWithInt(b, a); + for (int i = 0; i < 100; i++) { + expectEquals(4, b[i]); + } + } + + public static void main(String[] args) { + testUnroll(); + testStencil1(); + testStencil2(); + testStencil3(); + testTypes(); System.out.println("passed"); } + private static void expectEquals(int expected, int result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + + private static void expectEquals(long expected, long result) { + if (expected != result) { + throw new Error("Expected: " + expected + ", found: " + result); + } + } + private static void expectEquals(float expected, float result) { if (expected != result) { throw new Error("Expected: " + expected + ", found: " + result); |