Exploit NE/EQ tests on array length in BCE.
BUG=28585870
Change-Id: I382ffaf80dfb861f66eb0bfb6508e7d946a07e14
diff --git a/test/449-checker-bce/src/Main.java b/test/449-checker-bce/src/Main.java
index 66e1d92..41771b5 100644
--- a/test/449-checker-bce/src/Main.java
+++ b/test/449-checker-bce/src/Main.java
@@ -927,6 +927,32 @@
}
}
+ /// CHECK-START: void Main.nonzeroLength(int[]) BCE (before)
+ /// CHECK-DAG: BoundsCheck
+ //
+ /// CHECK-START: void Main.nonzeroLength(int[]) BCE (after)
+ /// CHECK-NOT: BoundsCheck
+ /// CHECK-NOT: Deoptimize
+ public static void nonzeroLength(int[] a) {
+ if (a.length != 0) {
+ a[0] = 112;
+ }
+ }
+
+ /// CHECK-START: void Main.knownLength(int[]) BCE (before)
+ /// CHECK-DAG: BoundsCheck
+ /// CHECK-DAG: BoundsCheck
+ //
+ /// CHECK-START: void Main.knownLength(int[]) BCE (after)
+ /// CHECK-NOT: BoundsCheck
+ /// CHECK-NOT: Deoptimize
+ public static void knownLength(int[] a) {
+ if (a.length == 2) {
+ a[0] = -1;
+ a[1] = -2;
+ }
+ }
+
static int[][] mA;
/// CHECK-START: void Main.dynamicBCEAndIntrinsic(int) BCE (before)
@@ -1586,6 +1612,26 @@
}
}
+ nonzeroLength(array);
+ if (array[0] != 112) {
+ System.out.println("nonzero length failed!");
+ }
+
+ knownLength(array);
+ if (array[0] != 112 || array[1] != 1) {
+ System.out.println("nonzero length failed!");
+ }
+ array = new int[2];
+ knownLength(array);
+ if (array[0] != -1 || array[1] != -2) {
+ System.out.println("nonzero length failed!");
+ }
+
+ // Zero length array does not break.
+ array = new int[0];
+ nonzeroLength(array);
+ knownLength(array);
+
mA = new int[4][4];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
diff --git a/test/530-checker-loops2/src/Main.java b/test/530-checker-loops2/src/Main.java
index c644692..b12fbd6 100644
--- a/test/530-checker-loops2/src/Main.java
+++ b/test/530-checker-loops2/src/Main.java
@@ -710,8 +710,8 @@
// making them a candidate for deoptimization based on constant indices.
// Compiler should ensure the array loads are not subsequently hoisted
// "above" the deoptimization "barrier" on the bounds.
- a[0][i] = 1;
- a[1][i] = 2;
+ a[1][i] = 1;
+ a[2][i] = 2;
a[99][i] = 3;
}
}
@@ -1042,11 +1042,11 @@
a = new int[100][10];
expectEquals(55, dynamicBCEAndConstantIndices(x, a, 0, 10));
for (int i = 0; i < 10; i++) {
- expectEquals((i % 10) != 0 ? 1 : 0, a[0][i]);
- expectEquals((i % 10) != 0 ? 2 : 0, a[1][i]);
+ expectEquals((i % 10) != 0 ? 1 : 0, a[1][i]);
+ expectEquals((i % 10) != 0 ? 2 : 0, a[2][i]);
expectEquals((i % 10) != 0 ? 3 : 0, a[99][i]);
}
- a = new int[2][10];
+ a = new int[3][10];
sResult = 0;
try {
expectEquals(55, dynamicBCEAndConstantIndices(x, a, 0, 10));
@@ -1054,8 +1054,8 @@
sResult = 1;
}
expectEquals(1, sResult);
- expectEquals(a[0][1], 1);
- expectEquals(a[1][1], 2);
+ expectEquals(a[1][1], 1);
+ expectEquals(a[2][1], 2);
// Dynamic BCE combined with constant indices of all types.
boolean[] x1 = { true };