Make test 656-checker-simd-opt pass on RI.

Move the smali code to Java. Use inlining to expose the
optimization opportunity to ART while hiding it from D8.
Also extend the tests to x86-64.

Test: testrunner.py --host --optimizing --jvm -t 656-checker-simd-opt
Test: testrunner.py --target --optimizing -t 656-checker-simd-opt
Bug: 65168732
Bug: 73888836
Change-Id: Ia883f1157382216617a4de9422b3b3d96043f12c
diff --git a/test/656-checker-simd-opt/smali/Smali.smali b/test/656-checker-simd-opt/smali/Smali.smali
deleted file mode 100644
index 802bcab..0000000
--- a/test/656-checker-simd-opt/smali/Smali.smali
+++ /dev/null
@@ -1,121 +0,0 @@
-# Copyright (C) 2017 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-.class public LSmali;
-.super Ljava/lang/Object;
-
-## CHECK-START: void Smali.stencilSubInt(int[], int[], int) loop_optimization (before)
-## CHECK-DAG: <<PAR3:i\d+>>  ParameterValue                       loop:none
-## CHECK-DAG: <<CP1:i\d+>>   IntConstant 1                        loop:none
-## CHECK-DAG: <<Sub1:i\d+>>  Sub [<<PAR3>>,<<CP1>>]               loop:none
-## CHECK-DAG: <<Phi:i\d+>>   Phi                                  loop:<<Loop:B\d+>> outer_loop:none
-## CHECK-DAG: <<Sub2:i\d+>>  Sub [<<Phi>>,<<CP1>>]                loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get1:i\d+>>  ArrayGet [{{l\d+}},<<Sub2>>]         loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get2:i\d+>>  ArrayGet [{{l\d+}},<<Phi>>]          loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add1:i\d+>>  Add [<<Get1>>,<<Get2>>]              loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add2:i\d+>>  Add [<<Phi>>,<<CP1>>]                loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get3:i\d+>>  ArrayGet [{{l\d+}},<<Add2>>]         loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add3:i\d+>>  Add [<<Add1>>,<<Get3>>]              loop:<<Loop>>      outer_loop:none
-## CHECK-DAG:                ArraySet [{{l\d+}},<<Phi>>,<<Add3>>] loop:<<Loop>>      outer_loop:none
-
-## CHECK-START-ARM64: void Smali.stencilSubInt(int[], int[], int) loop_optimization (after)
-## CHECK-DAG: <<CP1:i\d+>>   IntConstant 1                         loop:none
-## CHECK-DAG: <<CP2:i\d+>>   IntConstant 2                         loop:none
-## CHECK-DAG: <<Phi:i\d+>>   Phi                                   loop:<<Loop:B\d+>> outer_loop:none
-## CHECK-DAG: <<Add1:i\d+>>  Add [<<Phi>>,<<CP1>>]                 loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get1:d\d+>>  VecLoad [{{l\d+}},<<Phi>>]            loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get2:d\d+>>  VecLoad [{{l\d+}},<<Add1>>]           loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add2:d\d+>>  VecAdd [<<Get1>>,<<Get2>>]            loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add3:i\d+>>  Add [<<Phi>>,<<CP2>>]                 loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get3:d\d+>>  VecLoad [{{l\d+}},<<Add3>>]           loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add4:d\d+>>  VecAdd [<<Add2>>,<<Get3>>]            loop:<<Loop>>      outer_loop:none
-## CHECK-DAG:                VecStore [{{l\d+}},<<Add1>>,<<Add4>>] loop:<<Loop>>      outer_loop:none
-.method public static stencilSubInt([I[II)V
-    .registers 7
-
-    const/4 v0, 0x1
-
-    move v1, v0
-
-    :goto_2
-    sub-int v2, p2, v0
-
-    if-ge v1, v2, :cond_17
-
-    sub-int v2, v1, v0
-    aget v2, p1, v2
-    aget v3, p1, v1
-    add-int/2addr v2, v3
-    add-int v3, v1, v0
-    aget v3, p1, v3
-    add-int/2addr v2, v3
-    aput v2, p0, v1
-    add-int/lit8 v1, v1, 0x1
-
-    goto :goto_2
-
-    :cond_17
-    return-void
-.end method
-
-## CHECK-START: void Smali.stencilAddInt(int[], int[], int) loop_optimization (before)
-## CHECK-DAG: <<CP1:i\d+>>   IntConstant 1                        loop:none
-## CHECK-DAG: <<CM1:i\d+>>   IntConstant -1                       loop:none
-## CHECK-DAG: <<Phi:i\d+>>   Phi                                  loop:<<Loop:B\d+>> outer_loop:none
-## CHECK-DAG: <<Add1:i\d+>>  Add [<<Phi>>,<<CM1>>]                loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get1:i\d+>>  ArrayGet [{{l\d+}},<<Add1>>]         loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get2:i\d+>>  ArrayGet [{{l\d+}},<<Phi>>]          loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add2:i\d+>>  Add [<<Get1>>,<<Get2>>]              loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add3:i\d+>>  Add [<<Phi>>,<<CP1>>]                loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get3:i\d+>>  ArrayGet [{{l\d+}},<<Add3>>]         loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add4:i\d+>>  Add [<<Add2>>,<<Get3>>]              loop:<<Loop>>      outer_loop:none
-## CHECK-DAG:                ArraySet [{{l\d+}},<<Phi>>,<<Add4>>] loop:<<Loop>>      outer_loop:none
-
-## CHECK-START-ARM64: void Smali.stencilAddInt(int[], int[], int) loop_optimization (after)
-## CHECK-DAG: <<CP1:i\d+>>   IntConstant 1                         loop:none
-## CHECK-DAG: <<CP2:i\d+>>   IntConstant 2                         loop:none
-## CHECK-DAG: <<Phi:i\d+>>   Phi                                   loop:<<Loop:B\d+>> outer_loop:none
-## CHECK-DAG: <<Add1:i\d+>>  Add [<<Phi>>,<<CP1>>]                 loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get1:d\d+>>  VecLoad [{{l\d+}},<<Phi>>]            loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get2:d\d+>>  VecLoad [{{l\d+}},<<Add1>>]           loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add2:d\d+>>  VecAdd [<<Get1>>,<<Get2>>]            loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add3:i\d+>>  Add [<<Phi>>,<<CP2>>]                 loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Get3:d\d+>>  VecLoad [{{l\d+}},<<Add3>>]           loop:<<Loop>>      outer_loop:none
-## CHECK-DAG: <<Add4:d\d+>>  VecAdd [<<Add2>>,<<Get3>>]            loop:<<Loop>>      outer_loop:none
-## CHECK-DAG:                VecStore [{{l\d+}},<<Add1>>,<<Add4>>] loop:<<Loop>>      outer_loop:none
-.method public static stencilAddInt([I[II)V
-    .registers 6
-
-    const/4 v0, 0x1
-
-    :goto_1
-    add-int/lit8 v1, p2, -0x1
-
-    if-ge v0, v1, :cond_16
-
-    add-int/lit8 v1, v0, -0x1
-    aget v1, p1, v1
-    aget v2, p1, v0
-    add-int/2addr v1, v2
-    add-int/lit8 v2, v0, 0x1
-    aget v2, p1, v2
-    add-int/2addr v1, v2
-    aput v1, p0, v0
-    add-int/lit8 v0, v0, 0x1
-
-    goto :goto_1
-
-    :cond_16
-    return-void
-.end method
diff --git a/test/656-checker-simd-opt/src/Main.java b/test/656-checker-simd-opt/src/Main.java
index 39a126f..d632fd2 100644
--- a/test/656-checker-simd-opt/src/Main.java
+++ b/test/656-checker-simd-opt/src/Main.java
@@ -66,32 +66,79 @@
     }
   }
 
+  /// CHECK-START: void Main.stencilAddInt(int[], int[], int) loop_optimization (before)
+  /// CHECK-DAG: <<CP1:i\d+>>   IntConstant 1                        loop:none
+  /// CHECK-DAG: <<CM1:i\d+>>   IntConstant -1                       loop:none
+  /// CHECK-DAG: <<Phi:i\d+>>   Phi                                  loop:<<Loop:B\d+>> outer_loop:none
+  /// CHECK-DAG: <<Add1:i\d+>>  Add [<<Phi>>,<<CM1>>]                loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get1:i\d+>>  ArrayGet [{{l\d+}},<<Add1>>]         loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get2:i\d+>>  ArrayGet [{{l\d+}},<<Phi>>]          loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add2:i\d+>>  Add [<<Get1>>,<<Get2>>]              loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add3:i\d+>>  Add [<<Phi>>,<<CP1>>]                loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get3:i\d+>>  ArrayGet [{{l\d+}},<<Add3>>]         loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add4:i\d+>>  Add [<<Add2>>,<<Get3>>]              loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG:                ArraySet [{{l\d+}},<<Phi>>,<<Add4>>] loop:<<Loop>>      outer_loop:none
+
+  /// CHECK-START-{X86_64,ARM64}: void Main.stencilAddInt(int[], int[], int) loop_optimization (after)
+  /// CHECK-DAG: <<CP1:i\d+>>   IntConstant 1                         loop:none
+  /// CHECK-DAG: <<CP2:i\d+>>   IntConstant 2                         loop:none
+  /// CHECK-DAG: <<Phi:i\d+>>   Phi                                   loop:<<Loop:B\d+>> outer_loop:none
+  /// CHECK-DAG: <<Add1:i\d+>>  Add [<<Phi>>,<<CP1>>]                 loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get1:d\d+>>  VecLoad [{{l\d+}},<<Phi>>]            loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get2:d\d+>>  VecLoad [{{l\d+}},<<Add1>>]           loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add2:d\d+>>  VecAdd [<<Get1>>,<<Get2>>]            loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add3:i\d+>>  Add [<<Phi>>,<<CP2>>]                 loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get3:d\d+>>  VecLoad [{{l\d+}},<<Add3>>]           loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add4:d\d+>>  VecAdd [<<Add2>>,<<Get3>>]            loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG:                VecStore [{{l\d+}},<<Add1>>,<<Add4>>] loop:<<Loop>>      outer_loop:none
   private static void stencilAddInt(int[] a, int[] b, int n) {
-    try {
-      Class<?> c = Class.forName("Smali");
-      Method m = c.getMethod("stencilAddInt",
-          Array.newInstance(int.class, 1).getClass(),
-          Array.newInstance(int.class, 1).getClass(),
-          int.class);
-      m.invoke(null, a, b, n);
-    } catch (Exception ex) {
-      throw new Error(ex);
+    int minus1 = $inline$constMinus1();
+    for (int i = 1; i < n + minus1; i++) {
+      a[i] = b[i + minus1] + b[i] + b[i + 1];
     }
   }
 
+  private static int $inline$constMinus1() {
+    return -1;
+  }
+
+  /// CHECK-START: void Main.stencilSubInt(int[], int[], int) loop_optimization (before)
+  /// CHECK-DAG: <<PAR3:i\d+>>  ParameterValue                       loop:none
+  /// CHECK-DAG: <<CP1:i\d+>>   IntConstant 1                        loop:none
+  /// CHECK-DAG: <<Sub1:i\d+>>  Sub [<<PAR3>>,<<CP1>>]               loop:none
+  /// CHECK-DAG: <<Phi:i\d+>>   Phi                                  loop:<<Loop:B\d+>> outer_loop:none
+  /// CHECK-DAG: <<Sub2:i\d+>>  Sub [<<Phi>>,<<CP1>>]                loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get1:i\d+>>  ArrayGet [{{l\d+}},<<Sub2>>]         loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get2:i\d+>>  ArrayGet [{{l\d+}},<<Phi>>]          loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add1:i\d+>>  Add [<<Get1>>,<<Get2>>]              loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add2:i\d+>>  Add [<<Phi>>,<<CP1>>]                loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get3:i\d+>>  ArrayGet [{{l\d+}},<<Add2>>]         loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add3:i\d+>>  Add [<<Add1>>,<<Get3>>]              loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG:                ArraySet [{{l\d+}},<<Phi>>,<<Add3>>] loop:<<Loop>>      outer_loop:none
+
+  /// CHECK-START-{X86_64,ARM64}: void Main.stencilSubInt(int[], int[], int) loop_optimization (after)
+  /// CHECK-DAG: <<CP1:i\d+>>   IntConstant 1                         loop:none
+  /// CHECK-DAG: <<CP2:i\d+>>   IntConstant 2                         loop:none
+  /// CHECK-DAG: <<Phi:i\d+>>   Phi                                   loop:<<Loop:B\d+>> outer_loop:none
+  /// CHECK-DAG: <<Add1:i\d+>>  Add [<<Phi>>,<<CP1>>]                 loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get1:d\d+>>  VecLoad [{{l\d+}},<<Phi>>]            loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get2:d\d+>>  VecLoad [{{l\d+}},<<Add1>>]           loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add2:d\d+>>  VecAdd [<<Get1>>,<<Get2>>]            loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add3:i\d+>>  Add [<<Phi>>,<<CP2>>]                 loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Get3:d\d+>>  VecLoad [{{l\d+}},<<Add3>>]           loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG: <<Add4:d\d+>>  VecAdd [<<Add2>>,<<Get3>>]            loop:<<Loop>>      outer_loop:none
+  /// CHECK-DAG:                VecStore [{{l\d+}},<<Add1>>,<<Add4>>] loop:<<Loop>>      outer_loop:none
   private static void stencilSubInt(int[] a, int[] b, int n) {
-    try {
-      Class<?> c = Class.forName("Smali");
-      Method m = c.getMethod("stencilSubInt",
-          Array.newInstance(int.class, 1).getClass(),
-          Array.newInstance(int.class, 1).getClass(),
-          int.class);
-      m.invoke(null, a, b, n);
-    } catch (Exception ex) {
-      throw new Error(ex);
+    int plus1 = $inline$constPlus1();
+    for (int i = 1; i < n - plus1; i++) {
+      a[i] = b[i - plus1] + b[i] + b[i + 1];
     }
   }
 
+  private static int $inline$constPlus1() {
+    return 1;
+  }
+
   /// 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
diff --git a/test/knownfailures.json b/test/knownfailures.json
index b33828d..fc6feaa 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -995,7 +995,6 @@
           "649-vdex-duplicate-method",
           "652-deopt-intrinsic",
           "656-annotation-lookup-generic-jni",
-          "656-checker-simd-opt",
           "659-unpadded-array",
           "660-clinit",
           "660-store-8-16",