// // Test on loop optimizations, in particular with try catches. // publicclass Main { // Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo1(int) loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$geo1(int) loop_optimization (before) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Mul loop:<<Loop>>
/// CHECK-START: int Main.$noinline$geo1(int) loop_optimization (after) /// CHECK-NOT: Phi privatestaticint $noinline$geo1(int a) { for (int i = 0; i < 10; i++) {
a *= 10;
}
// Outer try catch does not block loop optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
} return a;
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo1_Blocking(int) loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$geo1_Blocking(int) loop_optimization (before) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Mul loop:<<Loop>>
/// CHECK-START: int Main.$noinline$geo1_Blocking(int) loop_optimization (after) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Mul loop:<<Loop>> privatestaticint $noinline$geo1_Blocking(int a) { for (int i = 0; i < 10; i++) {
a *= 10;
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo2(int) loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$geo2(int) loop_optimization (after) /// CHECK-NOT: Phi privatestaticint $noinline$geo2(int a) { for (int i = 0; i < 10; i++) {
a <<= 1;
}
// Outer try catch does not block loop optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
} return a;
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo2_Blocking(int) loop_optimization (before) /// CHECK: TryBoundary
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo3(int) loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$geo3(int) loop_optimization (before) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Div loop:<<Loop>>
/// CHECK-START: int Main.$noinline$geo3(int) loop_optimization (after) /// CHECK-NOT: Phi privatestaticint $noinline$geo3(int a) { for (int i = 0; i < 10; i++) {
a /= 3;
}
// Outer try catch does not block loop optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
} return a;
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo3_Blocking(int) loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$geo3_Blocking(int) loop_optimization (before) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Div loop:<<Loop>>
/// CHECK-START: int Main.$noinline$geo3_Blocking(int) loop_optimization (after) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Div loop:<<Loop>> privatestaticint $noinline$geo3_Blocking(int a) { for (int i = 0; i < 10; i++) {
a /= 3;
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo4(int) loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$geo4(int) loop_optimization (before) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Rem loop:<<Loop>>
/// CHECK-START: int Main.$noinline$geo4(int) loop_optimization (after) /// CHECK-NOT: Phi privatestaticint $noinline$geo4(int a) { for (int i = 0; i < 10; i++) {
a %= 7; // a wrap-around induction
}
// Outer try catch does not block loop optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
} return a;
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo4_Blocking(int) loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$geo4_Blocking(int) loop_optimization (before) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Rem loop:<<Loop>>
/// CHECK-START: int Main.$noinline$geo4_Blocking(int) loop_optimization (after) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Rem loop:<<Loop>> privatestaticint $noinline$geo4_Blocking(int a) { for (int i = 0; i < 10; i++) {
a %= 7; // a wrap-around induction
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo5() loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$geo5() loop_optimization (after) /// CHECK-NOT: Phi privatestaticint $noinline$geo5() { int a = 0x7fffffff; for (int i = 0; i < 10; i++) {
a >>= 1;
}
// Outer try catch does not block loop optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
} return a;
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$geo5_Blocking() loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$geo5_Blocking() loop_optimization (after) /// CHECK-DAG: Phi loop:<<Loop:B\d+>> /// CHECK-DAG: Shr loop:<<Loop>> privatestaticint $noinline$geo5_Blocking() { int a = 0x7fffffff; for (int i = 0; i < 10; i++) {
a >>= 1;
// Tests taken from 530-checker-loops4 privatestaticvoid $noinline$loops4Tests() { int m = 1410065408; for (int i = -100; i <= 100; i++) {
expectEquals(m * i, $noinline$geo1(i));
expectEquals(m * i, $noinline$geo1_Blocking(i));
} for (int i = 1; i <= 1000000000; i *= 10) {
expectEquals(m * i, $noinline$geo1(i));
expectEquals(m * i, $noinline$geo1_Blocking(i));
expectEquals(-m * i, $noinline$geo1(-i));
expectEquals(-m * i, $noinline$geo1_Blocking(-i));
}
for (int i = -100; i <= 100; i++) {
expectEquals(i << 10, $noinline$geo2(i));
expectEquals(i << 10, $noinline$geo2_Blocking(i));
} for (int i = 0; i < 22; i++) {
expectEquals(1 << (i + 10), $noinline$geo2(1 << i));
expectEquals(1 << (i + 10), $noinline$geo2_Blocking(1 << i));
}
expectEquals(0x80000400, $noinline$geo2(0x00200001));
expectEquals(0x80000400, $noinline$geo2_Blocking(0x00200001));
expectEquals(0x00000000, $noinline$geo2(0x00400000));
expectEquals(0x00000000, $noinline$geo2_Blocking(0x00400000));
expectEquals(0x00000400, $noinline$geo2(0x00400001));
expectEquals(0x00000400, $noinline$geo2_Blocking(0x00400001));
int d = 59049; for (int i = -100; i <= 100; i++) {
expectEquals(0, $noinline$geo3(i));
expectEquals(0, $noinline$geo3_Blocking(i));
} for (int i = 1; i <= 100; i++) {
expectEquals(i, $noinline$geo3(i * d));
expectEquals(i, $noinline$geo3_Blocking(i * d));
expectEquals(i, $noinline$geo3(i * d + 1));
expectEquals(i, $noinline$geo3_Blocking(i * d + 1));
expectEquals(-i, $noinline$geo3(-i * d));
expectEquals(-i, $noinline$geo3_Blocking(-i * d));
expectEquals(-i, $noinline$geo3(-i * d - 1));
expectEquals(-i, $noinline$geo3_Blocking(-i * d - 1));
}
for (int i = -100; i <= 100; i++) {
expectEquals(i % 7, $noinline$geo4(i));
expectEquals(i % 7, $noinline$geo4_Blocking(i));
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$poly1() loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$poly1() loop_optimization (after) /// CHECK-NOT: Phi privatestaticint $noinline$poly1() { int a = 0; for (int i = 0; i <= 10; i++) {
a += i;
}
// Outer try catch does not block loop optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
}
return a;
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$poly1_Blocking() loop_optimization (before) /// CHECK: TryBoundary
// Multiplication in linear induction has been optimized earlier, // but that does not stop the induction variable recognition // and loop optimizer. // // Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$poly2(int) loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$poly2(int) loop_optimization (after) /// CHECK-NOT: Phi privatestaticint $noinline$poly2(int a) { for (int i = 0; i < 10; i++) { int k = 3 * i + 5;
a += k;
}
// Outer try catch does not block loop optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
} return a;
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$poly2_Blocking(int) loop_optimization (before) /// CHECK: TryBoundary
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$poly3() loop_optimization (before) /// CHECK: TryBoundary
/// CHECK-START: int Main.$noinline$poly3() loop_optimization (after) /// CHECK-NOT: Phi privatestaticint $noinline$poly3() { int a = 12345; for (int i = 0; i <= 10; i++) {
a += (2147483646 * i + 67890);
}
// Outer try catch does not block loop optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
} return a;
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: int Main.$noinline$poly3_Blocking() loop_optimization (before) /// CHECK: TryBoundary
// Constants used for peel unroll tests. privatestaticfinalint LENGTH = 4 * 1024; privatestaticfinalint RESULT_POS = 4;
privatestaticfinalvoid initIntArray(int[] a) { for (int i = 0; i < a.length; i++) {
a[i] = i % 4;
}
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: void Main.$noinline$unrollingLoadStoreElimination(int[]) loop_optimization (after) /// CHECK: TryBoundary
/// CHECK-START: void Main.$noinline$unrollingLoadStoreElimination(int[]) loop_optimization (after) /// CHECK: ArraySet /// CHECK: ArraySet /// CHECK-NOT: ArraySet privatestaticfinalvoid $noinline$unrollingLoadStoreElimination(int[] a) { for (int i = 0; i < LENGTH - 2; i++) {
a[i] += a[i + 1];
}
// Outer try catch does not block loop optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
}
}
// Consistency check to see we haven't eliminated the try/catch. /// CHECK-START: void Main.$noinline$unrollingLoadStoreElimination_Blocking(int[]) loop_optimization (after) /// CHECK: TryBoundary
// Each one of the three `for` loops has an `if`. The try catch has the 4th `if`. /// CHECK-START: void Main.$noinline$unrollingInTheNest(int[], int[], int) loop_optimization (before) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// Loop unrolling adds a 5th `if`. It is the one with `Const0` above. /// CHECK-START: void Main.$noinline$unrollingInTheNest(int[], int[], int) loop_optimization (after) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// Each one of the three `for` loops has an `if`. The try catch has the 4th `if`. /// CHECK-START: void Main.$noinline$unrollingInTheNest_Blocking(int[], int[], int) loop_optimization (before) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
/// CHECK-START: void Main.$noinline$unrollingInTheNest_Blocking(int[], int[], int) loop_optimization (after) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// Each one of the three `for` loops has an `if`. The try catch has the 4th `if`. /// CHECK-START: void Main.$noinline$unrollingInTheNest_TryCatchNotBlocking(int[], int[], int) loop_optimization (before) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// Loop unrolling adds a 5th `if`. It is the one with `Const0` above. /// CHECK-START: void Main.$noinline$unrollingInTheNest_TryCatchNotBlocking(int[], int[], int) loop_optimization (after) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// Each one of the three `for` loops has an `if`. Plus an `if` inside the outer `for`. The try catch has the 5th `if`. /// CHECK-START: void Main.$noinline$unrollingTwoLoopsInTheNest(int[], int[], int) loop_optimization (before) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// LoopOptimization adds two `if`s. One for each loop unrolling. /// CHECK-START: void Main.$noinline$unrollingTwoLoopsInTheNest(int[], int[], int) loop_optimization (after) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// Each one of the three `for` loops has an `if`. Plus an `if` inside the outer `for`. The try catch has the 5th `if`. /// CHECK-START: void Main.$noinline$unrollingTwoLoopsInTheNest_OneBlocking(int[], int[], int) loop_optimization (before) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// LoopOptimization adds two `if`s. One for each loop unrolling. /// CHECK-START: void Main.$noinline$unrollingTwoLoopsInTheNest_OneBlocking(int[], int[], int) loop_optimization (after) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// Each one of the three `for` loops has an `if`. Plus an `if` inside the outer `for`. The try catch has the 5th `if`. /// CHECK-START: void Main.$noinline$unrollingTwoLoopsInTheNest_OtherBlocking(int[], int[], int) loop_optimization (before) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// LoopOptimization adds two `if`s. One for each loop unrolling. /// CHECK-START: void Main.$noinline$unrollingTwoLoopsInTheNest_OtherBlocking(int[], int[], int) loop_optimization (after) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
// Each one of the three `for` loops has an `if`. Plus an `if` inside the outer `for`. The try catchs have the 5th and 6th `if`. /// CHECK-START: void Main.$noinline$unrollingTwoLoopsInTheNest_BothBlocking(int[], int[], int) loop_optimization (before) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
/// CHECK-START: void Main.$noinline$unrollingTwoLoopsInTheNest_BothBlocking(int[], int[], int) loop_optimization (after) /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK: If /// CHECK-NOT: If
/// CHECK-START: void Main.$noinline$unrollingTwoLoopsInTheNest_BothBlocking(int[], int[], int) loop_optimization (after) /// CHECK: ArraySet /// CHECK: ArraySet /// CHECK-NOT: ArraySet privatestaticfinalvoid $noinline$unrollingTwoLoopsInTheNest_BothBlocking(int[] a, int[] b, int x) { for (int k = 0; k < 128; k++) { if (x > 100) { for (int j = 0; j < 128; j++) {
a[x]++; // Try catch blocks optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
}
}
} else { for (int i = 0; i < 128; i++) {
b[x]++; // Try catch blocks optimizations. try { if (doThrow) {
$noinline$unreachable();
}
} catch (Error e) {
System.out.println("Not expected");
}
}
}
}
}
// Tests taken from 530-checker-peel-unroll privatestaticvoid $noinline$peelUnrollTests() { int[] a = newint[LENGTH]; int[] b = newint[LENGTH];
initIntArray(a);
initIntArray(b);
publicstaticvoid main(String[] args) { // Use existing tests to show that the difference between having a try catch inside or outside // the loop.
$noinline$loops4Tests();
$noinline$loops5Tests();
$noinline$peelUnrollTests();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.