/** *Testsonboundscheckeliminationinloopsthatuseintrinsics. *Allboundschecksbelowshouldbestaticallyeliminated.
*/ publicclass Main {
/// CHECK-START: int Main.oneArray(int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none // /// CHECK-START: int Main.oneArray(int[]) BCE (after) /// CHECK-NOT: BoundsCheck /// CHECK-NOT: Deoptimize staticint oneArray(int[] a) { int x = 0; for (int i = 0; i < a.length; i++) {
x += a[i];
} return x;
}
/// CHECK-START: int Main.oneArrayAbs(int[], int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none // /// CHECK-START: int Main.oneArrayAbs(int[], int[]) BCE (after) /// CHECK-NOT: BoundsCheck /// CHECK-NOT: Deoptimize staticint oneArrayAbs(int[] a, int[] b) { int x = 0; for (int i = Math.abs(b.length); i < a.length; i++) {
x += a[i];
} return x;
}
/// CHECK-START: int Main.twoArrays(int[], int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop>> outer_loop:none // /// CHECK-START: int Main.twoArrays(int[], int[]) BCE (after) /// CHECK-NOT: BoundsCheck /// CHECK-NOT: Deoptimize staticint twoArrays(int[] a, int[] b) { int x = 0; for (int i = 0; i < Math.min(a.length, b.length); i++) {
x += a[i] + b[i];
} return x;
}
/// CHECK-START: int Main.threeArrays(int[], int[], int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop>> outer_loop:none // /// CHECK-START: int Main.threeArrays(int[], int[], int[]) BCE (after) /// CHECK-NOT: BoundsCheck /// CHECK-NOT: Deoptimize staticint threeArrays(int[] a, int[] b, int[] c) { int x = 0; for (int i = 0; i < Math.min(Math.min(a.length, b.length), c.length); i++) {
x += a[i] + b[i] + c[i];
} return x;
}
/// CHECK-START: int Main.fourArrays(int[], int[], int[], int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop>> outer_loop:none // /// CHECK-START: int Main.fourArrays(int[], int[], int[], int[]) BCE (after) /// CHECK-NOT: BoundsCheck /// CHECK-NOT: Deoptimize staticint fourArrays(int[] a, int[] b, int[] c, int[] d) { int x = 0; for (int i = 0; i < Math.min(Math.min(a.length, b.length), Math.min(c.length, d.length)); i++) {
x += a[i] + b[i] + c[i] + d[i];
} return x;
}
/// CHECK-START: int Main.oneArrayWithCleanup(int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop1:B\d+>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop2:B\d+>> outer_loop:none // /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" // /// CHECK-START: int Main.oneArrayWithCleanup(int[]) BCE (after) /// CHECK-NOT: BoundsCheck /// CHECK-NOT: Deoptimize staticint oneArrayWithCleanup(int[] a) { int x = 0; int n = Math.min(4, a.length); for (int i = 0; i < n; i++) {
x += a[i];
} for (int i = n; i < a.length; i++) {
x += a[i] * 10;
} return x;
}
/// CHECK-START: int Main.twoArraysWithCleanup(int[], int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop1:B\d+>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop1>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop2:B\d+>> outer_loop:none // /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" // /// CHECK-START: int Main.twoArraysWithCleanup(int[], int[]) BCE (after) /// CHECK-NOT: BoundsCheck /// CHECK-NOT: Deoptimize staticint twoArraysWithCleanup(int[] a, int[] b) { int x = 0; int n = Math.min(a.length, b.length); for (int i = n - 1; i >= 0; i--) {
x += a[i] + b[i];
} for (int i = n; i < a.length; i++) {
x += a[i];
} return x;
}
/// CHECK-START: int Main.threeArraysWithCleanup(int[], int[], int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop1:B\d+>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop1>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop1>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop2:B\d+>> outer_loop:none // /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" // /// CHECK-START: int Main.threeArraysWithCleanup(int[], int[], int[]) BCE (after) /// CHECK-NOT: BoundsCheck /// CHECK-NOT: Deoptimize staticint threeArraysWithCleanup(int[] a, int[] b, int[] c) { int x = 0; int n = Math.min(a.length, Math.min(b.length, c.length)); for (int i = n - 1; i >= 0; i--) {
x += a[i] + b[i] + c[i];
} for (int i = n; i < a.length; i++) {
x += a[i];
} return x;
}
/// CHECK-START: int Main.altLoopLogic(int[], int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop>> outer_loop:none // /// CHECK-START: int Main.altLoopLogic(int[], int[]) BCE (after) /// CHECK-NOT: BoundsCheck /// CHECK-NOT: Deoptimize staticint altLoopLogic(int[] a, int[] b) { int x = 0; int n = Math.min(a.length, b.length); for (int i = n; i-- > 0;) {
x += a[i] + b[i];
} return x;
}
/// CHECK-START: int Main.hiddenMin(int[], int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop:B\d+>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop>> outer_loop:none // /// CHECK-START: int Main.hiddenMin(int[], int[]) BCE (after) // // TODO: make this so staticint hiddenMin(int[] a, int[] b) { int x = 0; for (int i = 0; i < a.length && i < b.length; i++) {
x += a[i] + b[i];
} return x;
}
/// CHECK-START: int Main.hiddenMinWithCleanup(int[], int[]) BCE (before) /// CHECK-DAG: BoundsCheck loop:<<Loop1:B\d+>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop1>> outer_loop:none /// CHECK-DAG: BoundsCheck loop:<<Loop2:B\d+>> outer_loop:none // /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" // /// CHECK-START: int Main.hiddenMinWithCleanup(int[], int[]) BCE (after) // // TODO: make this so staticint hiddenMinWithCleanup(int[] a, int[] b) { int x = 0; int i = 0; for (; i < a.length && i < b.length; i++) {
x += a[i] + b[i];
} for (; i < a.length; i++) {
x += a[i];
} return x;
}
publicstaticvoid main(String[] args) { int[] a = { 1, 2, 3, 4, 5 }; int[] b = { 6, 7, 8, 9, 4, 2 }; int[] c = { 1, 2, 3 }; int[] d = { 8, 5, 3, 2 }; int[] e = { };
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.