test: Modify 593-checker-boolean-2-integral-conv for javac/dx

Previously 3 of the methods were failing checker with javac/dx.
Move their old bytecode to a smali file to retain testing of those
optimizations.

Rewrite the checker tests in Main.java to use the javac/dx-generated
bytecode.

Test: art/test/run-test --64 --host --optimizing --build-with-javac-dx 593-checker-boolean-2-integral-conv
Bug: 63064517
Bug: 62950048
Bug: 36902714
Change-Id: I17de11318c1b1c8bcb0749429c5c80754cc03989
diff --git a/test/593-checker-boolean-2-integral-conv/build b/test/593-checker-boolean-2-integral-conv/build
new file mode 100755
index 0000000..49292c9
--- /dev/null
+++ b/test/593-checker-boolean-2-integral-conv/build
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# Copyright 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.
+
+# This checker test is incompatible with jack bytecode output,
+# so force it to use javac/dx.
+export USE_JACK=false
+# Also disable desugar because it is missing in jack platform builds.
+export DESUGAR=false
+
+./default-build "$@"
diff --git a/test/593-checker-boolean-2-integral-conv/smali/SmaliTests.smali b/test/593-checker-boolean-2-integral-conv/smali/SmaliTests.smali
new file mode 100644
index 0000000..00ebaaf
--- /dev/null
+++ b/test/593-checker-boolean-2-integral-conv/smali/SmaliTests.smali
@@ -0,0 +1,119 @@
+# 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 LSmaliTests;
+.super Ljava/lang/Object;
+
+# static fields
+.field public static booleanField:Z
+
+.method static constructor <clinit>()V
+    .registers 1
+
+    .prologue
+    const/4 v0, 0x1
+
+    # booleanField = true
+    sput-boolean v0, LSmaliTests;->booleanField:Z
+
+    return-void
+.end method
+
+## CHECK-START: long SmaliTests.booleanToLong(boolean) builder (after)
+## CHECK-DAG:     <<Arg:z\d+>>           ParameterValue
+## CHECK-DAG:     <<Zero:i\d+>>          IntConstant 0
+## CHECK-DAG:     <<One:i\d+>>           IntConstant 1
+## CHECK-DAG:     <<Cond:z\d+>>          Equal [<<Arg>>,<<Zero>>]
+## CHECK-DAG:                            If [<<Cond>>]
+## CHECK-DAG:     <<Phi:i\d+>>           Phi [<<One>>,<<Zero>>]
+## CHECK-DAG:     <<IToJ:j\d+>>          TypeConversion [<<Phi>>]
+## CHECK-DAG:                            Return [<<IToJ>>]
+
+## CHECK-START: long SmaliTests.booleanToLong(boolean) select_generator (after)
+## CHECK-DAG:     <<Arg:z\d+>>           ParameterValue
+## CHECK-DAG:     <<Zero:i\d+>>          IntConstant 0
+## CHECK-DAG:     <<One:i\d+>>           IntConstant 1
+## CHECK-DAG:     <<Sel:i\d+>>           Select [<<Zero>>,<<One>>,<<Arg>>]
+## CHECK-DAG:     <<IToJ:j\d+>>          TypeConversion [<<Sel>>]
+## CHECK-DAG:                            Return [<<IToJ>>]
+
+## CHECK-START: long SmaliTests.booleanToLong(boolean) instruction_simplifier$after_bce (after)
+## CHECK-DAG:     <<Arg:z\d+>>           ParameterValue
+## CHECK-DAG:     <<ZToJ:j\d+>>          TypeConversion [<<Arg>>]
+## CHECK-DAG:                            Return [<<ZToJ>>]
+.method public static booleanToLong(Z)J
+    .registers 3
+    .param p0, "b"    # Z
+    .prologue
+
+    # return b ? 1 : 0;
+    if-eqz p0, :b_is_zero
+
+# :b_is_one
+    const/4 v0, 0x1
+
+  :l_return
+    int-to-long v0, v0
+    return-wide v0
+
+  :b_is_zero
+    const/4 v0, 0x0
+    goto :l_return
+.end method
+
+## CHECK-START: int SmaliTests.longToIntOfBoolean() builder (after)
+## CHECK-DAG:     <<Method:[ij]\d+>>     CurrentMethod
+## CHECK-DAG:     <<Sget:z\d+>>          StaticFieldGet
+## CHECK-DAG:     <<ZToJ:j\d+>>          InvokeStaticOrDirect [<<Sget>>,<<Method>>]
+## CHECK-DAG:     <<JToI:i\d+>>          TypeConversion [<<ZToJ>>]
+## CHECK-DAG:                            Return [<<JToI>>]
+
+## CHECK-START: int SmaliTests.longToIntOfBoolean() inliner (after)
+## CHECK-DAG:     <<Method:[ij]\d+>>     CurrentMethod
+## CHECK-DAG:     <<Zero:i\d+>>          IntConstant 0
+## CHECK-DAG:     <<One:i\d+>>           IntConstant 1
+## CHECK-DAG:     <<Sget:z\d+>>          StaticFieldGet
+## CHECK-DAG:                            If [<<Sget>>]
+## CHECK-DAG:     <<Phi:i\d+>>           Phi [<<One>>,<<Zero>>]
+## CHECK-DAG:     <<IToJ:j\d+>>          TypeConversion [<<Phi>>]
+## CHECK-DAG:     <<JToI:i\d+>>          TypeConversion [<<IToJ>>]
+## CHECK-DAG:                            Return [<<JToI>>]
+
+## CHECK-START: int SmaliTests.longToIntOfBoolean() select_generator (after)
+## CHECK-DAG:     <<Method:[ij]\d+>>     CurrentMethod
+## CHECK-DAG:     <<Zero:i\d+>>          IntConstant 0
+## CHECK-DAG:     <<One:i\d+>>           IntConstant 1
+## CHECK-DAG:     <<Sget:z\d+>>          StaticFieldGet
+## CHECK-DAG:     <<Sel:i\d+>>           Select [<<Zero>>,<<One>>,<<Sget>>]
+## CHECK-DAG:     <<IToJ:j\d+>>          TypeConversion [<<Sel>>]
+## CHECK-DAG:     <<JToI:i\d+>>          TypeConversion [<<IToJ>>]
+## CHECK-DAG:                            Return [<<JToI>>]
+
+## CHECK-START: int SmaliTests.longToIntOfBoolean() instruction_simplifier$after_bce (after)
+## CHECK-DAG:     <<Method:[ij]\d+>>     CurrentMethod
+## CHECK-DAG:     <<Sget:z\d+>>          StaticFieldGet
+## CHECK-DAG:                            Return [<<Sget>>]
+.method public static longToIntOfBoolean()I
+    .registers 3
+    .prologue
+
+    # long l = booleanToLong(booleanField);
+    sget-boolean v2, LSmaliTests;->booleanField:Z
+    invoke-static {v2}, LSmaliTests;->booleanToLong(Z)J
+    move-result-wide v0
+
+    # return (int) l;
+    long-to-int v2, v0
+    return v2
+.end method
diff --git a/test/593-checker-boolean-2-integral-conv/src/Main.java b/test/593-checker-boolean-2-integral-conv/src/Main.java
index b4c91c8..3503b2e 100644
--- a/test/593-checker-boolean-2-integral-conv/src/Main.java
+++ b/test/593-checker-boolean-2-integral-conv/src/Main.java
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+import java.lang.reflect.Method;
+
 public class Main {
 
   public static void main(String args[]) {
@@ -22,8 +24,10 @@
     expectEqualsChar((char)1, booleanToChar(true));
     expectEqualsInt(1, booleanToInt(true));
     expectEqualsLong(1L, booleanToLong(true));
+    expectEqualsLong(1L, $noinline$runSmaliTest("booleanToLong", true));
 
     expectEqualsInt(1, longToIntOfBoolean());
+    expectEqualsInt(1, $noinline$runSmaliTest("longToIntOfBoolean"));
 
     System.out.println("passed");
   }
@@ -132,26 +136,34 @@
 
   /// CHECK-START: long Main.booleanToLong(boolean) builder (after)
   /// CHECK:         <<Arg:z\d+>>           ParameterValue
-  /// CHECK-DAG:     <<Zero:i\d+>>          IntConstant 0
-  /// CHECK-DAG:     <<One:i\d+>>           IntConstant 1
-  /// CHECK-DAG:     <<Cond:z\d+>>          Equal [<<Arg>>,<<Zero>>]
+  /// CHECK-DAG:     <<IZero:i\d+>>         IntConstant 0
+  /// CHECK-DAG:     <<Zero:j\d+>>          LongConstant 0
+  /// CHECK-DAG:     <<One:j\d+>>           LongConstant 1
+  /// CHECK-DAG:     <<Cond:z\d+>>          Equal [<<Arg>>,<<IZero>>]
   /// CHECK-DAG:                            If [<<Cond>>]
-  /// CHECK-DAG:     <<Phi:i\d+>>           Phi [<<One>>,<<Zero>>]
-  /// CHECK-DAG:     <<IToJ:j\d+>>          TypeConversion [<<Phi>>]
-  /// CHECK-DAG:                            Return [<<IToJ>>]
+  /// CHECK-DAG:     <<Phi:j\d+>>           Phi [<<One>>,<<Zero>>]
+  /// CHECK-DAG:                            Return [<<Phi>>]
+
+  /// CHECK-START: long Main.booleanToLong(boolean) select_generator (after)
+  /// CHECK-NOT:                            IntConstant
+  /// CHECK-NOT:                            Equal
+  /// CHECK-NOT:                            If
+  /// CHECK-NOT:                            Phi
 
   /// CHECK-START: long Main.booleanToLong(boolean) select_generator (after)
   /// CHECK:         <<Arg:z\d+>>           ParameterValue
-  /// CHECK-DAG:     <<Zero:i\d+>>          IntConstant 0
-  /// CHECK-DAG:     <<One:i\d+>>           IntConstant 1
-  /// CHECK-DAG:     <<Sel:i\d+>>           Select [<<Zero>>,<<One>>,<<Arg>>]
-  /// CHECK-DAG:     <<IToJ:j\d+>>          TypeConversion [<<Sel>>]
-  /// CHECK-DAG:                            Return [<<IToJ>>]
+  /// CHECK-DAG:     <<Zero:j\d+>>          LongConstant 0
+  /// CHECK-DAG:     <<One:j\d+>>           LongConstant 1
+  /// CHECK-DAG:     <<Sel:j\d+>>           Select [<<Zero>>,<<One>>,<<Arg>>]
+  /// CHECK-DAG:                            Return [<<Sel>>]
 
-  /// CHECK-START: long Main.booleanToLong(boolean) instruction_simplifier$after_bce (after)
-  /// CHECK:         <<Arg:z\d+>>           ParameterValue
-  /// CHECK-DAG:     <<ZToJ:j\d+>>          TypeConversion [<<Arg>>]
-  /// CHECK-DAG:                            Return [<<ZToJ>>]
+  // As of now, the code is not optimized any further than the above.
+  // TODO: Re-enable checks below after simplifier is updated to handle this pattern: b/63064517
+
+  // CHECK-START: long Main.booleanToLong(boolean) instruction_simplifier$after_bce (after)
+  // CHECK:         <<Arg:z\d+>>           ParameterValue
+  // CHECK-DAG:     <<ZToJ:j\d+>>          TypeConversion [<<Arg>>]
+  // CHECK-DAG:                            Return [<<ZToJ>>]
 
   static long booleanToLong(boolean b) {
     return b ? 1 : 0;
@@ -166,29 +178,36 @@
 
   /// CHECK-START: int Main.longToIntOfBoolean() inliner (after)
   /// CHECK-DAG:     <<Method:[ij]\d+>>     CurrentMethod
-  /// CHECK-DAG:     <<Zero:i\d+>>          IntConstant 0
-  /// CHECK-DAG:     <<One:i\d+>>           IntConstant 1
+  /// CHECK-DAG:     <<Zero:j\d+>>          LongConstant 0
+  /// CHECK-DAG:     <<One:j\d+>>           LongConstant 1
   /// CHECK-DAG:     <<Sget:z\d+>>          StaticFieldGet
   /// CHECK-DAG:                            If [<<Sget>>]
-  /// CHECK-DAG:     <<Phi:i\d+>>           Phi [<<One>>,<<Zero>>]
-  /// CHECK-DAG:     <<IToJ:j\d+>>          TypeConversion [<<Phi>>]
-  /// CHECK-DAG:     <<JToI:i\d+>>          TypeConversion [<<IToJ>>]
+  /// CHECK-DAG:     <<Phi:j\d+>>           Phi [<<One>>,<<Zero>>]
+  /// CHECK-DAG:     <<JToI:i\d+>>          TypeConversion [<<Phi>>]
   /// CHECK-DAG:                            Return [<<JToI>>]
 
+  /// CHECK-START: long Main.booleanToLong(boolean) select_generator (after)
+  /// CHECK-NOT:                            IntConstant
+  /// CHECK-NOT:                            Equal
+  /// CHECK-NOT:                            If
+  /// CHECK-NOT:                            Phi
+
   /// CHECK-START: int Main.longToIntOfBoolean() select_generator (after)
   /// CHECK-DAG:     <<Method:[ij]\d+>>     CurrentMethod
-  /// CHECK-DAG:     <<Zero:i\d+>>          IntConstant 0
-  /// CHECK-DAG:     <<One:i\d+>>           IntConstant 1
+  /// CHECK-DAG:     <<Zero:j\d+>>          LongConstant 0
+  /// CHECK-DAG:     <<One:j\d+>>           LongConstant 1
   /// CHECK-DAG:     <<Sget:z\d+>>          StaticFieldGet
-  /// CHECK-DAG:     <<Sel:i\d+>>           Select [<<Zero>>,<<One>>,<<Sget>>]
-  /// CHECK-DAG:     <<IToJ:j\d+>>          TypeConversion [<<Sel>>]
-  /// CHECK-DAG:     <<JToI:i\d+>>          TypeConversion [<<IToJ>>]
+  /// CHECK-DAG:     <<Sel:j\d+>>           Select [<<Zero>>,<<One>>,<<Sget>>]
+  /// CHECK-DAG:     <<JToI:i\d+>>          TypeConversion [<<Sel>>]
   /// CHECK-DAG:                            Return [<<JToI>>]
 
-  /// CHECK-START: int Main.longToIntOfBoolean() instruction_simplifier$after_bce (after)
-  /// CHECK-DAG:     <<Method:[ij]\d+>>     CurrentMethod
-  /// CHECK-DAG:     <<Sget:z\d+>>          StaticFieldGet
-  /// CHECK-DAG:                            Return [<<Sget>>]
+  // As of now, the code is not optimized any further than the above.
+  // TODO: Re-enable checks below after simplifier is updated to handle this pattern: b/63064517
+
+  // CHECK-START: int Main.longToIntOfBoolean() instruction_simplifier$after_bce (after)
+  // CHECK-DAG:     <<Method:[ij]\d+>>     CurrentMethod
+  // CHECK-DAG:     <<Sget:z\d+>>          StaticFieldGet
+  // CHECK-DAG:                            Return [<<Sget>>]
 
   static int longToIntOfBoolean() {
     long l = booleanToLong(booleanField);
@@ -226,6 +245,26 @@
     }
   }
 
+  public static long $noinline$runSmaliTest(String name, boolean input) {
+    try {
+      Class<?> c = Class.forName("SmaliTests");
+      Method m = c.getMethod(name, boolean.class);
+      return (Long) m.invoke(null, input);
+    } catch (Exception ex) {
+      throw new Error(ex);
+    }
+  }
+
+  public static int $noinline$runSmaliTest(String name) {
+    try {
+      Class<?> c = Class.forName("SmaliTests");
+      Method m = c.getMethod(name);
+      return (Integer) m.invoke(null);
+    } catch (Exception ex) {
+      throw new Error(ex);
+    }
+  }
+
 
   public static boolean booleanField = true;
 
diff --git a/test/knownfailures.json b/test/knownfailures.json
index a21c97c..4ac1287 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -606,7 +606,6 @@
             "565-checker-doublenegbitwise",
             "567-checker-compare",
             "586-checker-null-array-get",
-            "593-checker-boolean-2-integral-conv",
             "633-checker-rtp-getclass"
         ],
         "description": "Checker tests failing when run with --build-with-javac-dx.",