ART-tests: remove DX-dependency from 566-checker-signum
One test case converts a boolean to 0/1 with a conditional. This construct
is optimized away by D8. This CL moves this test case to smali and enables
D8.
Test: art/test.py -b -r --host -t 566-checker-signum
Tested locally with --target/--gcstress
Bug: 65168732
Change-Id: Ic1f901dea486692174d38281413fe06539a41a34
diff --git a/test/566-checker-signum/build b/test/566-checker-signum/build
deleted file mode 100644
index 10ffcc5..0000000
--- a/test/566-checker-signum/build
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/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.
-
-# See b/65168732
-export USE_D8=false
-
-./default-build "$@"
diff --git a/test/566-checker-signum/smali/Main2.smali b/test/566-checker-signum/smali/Main2.smali
new file mode 100644
index 0000000..d99ad86
--- /dev/null
+++ b/test/566-checker-signum/smali/Main2.smali
@@ -0,0 +1,83 @@
+# Copyright (C) 2016 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 LMain2;
+.super Ljava/lang/Object;
+
+## CHECK-START: int Main2.signBoolean(boolean) intrinsics_recognition (after)
+## CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod
+## CHECK-DAG: <<Zero:i\d+>> IntConstant 0
+## CHECK-DAG: <<One:i\d+>> IntConstant 1
+## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>]
+## CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect [<<Phi>>,<<Method>>] intrinsic:IntegerSignum
+## CHECK-DAG: Return [<<Result>>]
+
+## CHECK-START: int Main2.signBoolean(boolean) instruction_simplifier (after)
+## CHECK-DAG: <<Zero:i\d+>> IntConstant 0
+## CHECK-DAG: <<One:i\d+>> IntConstant 1
+## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>]
+## CHECK-DAG: <<Result:i\d+>> Compare [<<Phi>>,<<Zero>>]
+## CHECK-DAG: Return [<<Result>>]
+
+## CHECK-START: int Main2.signBoolean(boolean) instruction_simplifier (after)
+## CHECK-NOT: InvokeStaticOrDirect
+
+## CHECK-START: int Main2.signBoolean(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: <<Result:i\d+>> Compare [<<Sel>>,<<Zero>>]
+## CHECK-DAG: Return [<<Result>>]
+
+## CHECK-START: int Main2.signBoolean(boolean) select_generator (after)
+## CHECK-NOT: Phi
+
+## CHECK-START: int Main2.signBoolean(boolean) instruction_simplifier$after_bce (after)
+## CHECK-DAG: <<Arg:z\d+>> ParameterValue
+## CHECK-DAG: <<Zero:i\d+>> IntConstant 0
+## CHECK-DAG: <<Result:i\d+>> Compare [<<Arg>>,<<Zero>>]
+## CHECK-DAG: Return [<<Result>>]
+
+## CHECK-START: int Main2.signBoolean(boolean) instruction_simplifier$after_bce (after)
+## CHECK-NOT: Select
+
+# Original java source:
+#
+# private static int signBoolean(boolean x) {
+# return Integer.signum(x ? 1 : 0);
+# }
+
+.method public static signBoolean(Z)I
+ .registers 2
+ .param p0, "x" # Z
+
+ .prologue
+ .line 58
+ if-eqz p0, :cond_8
+
+ const/4 v0, 0x1
+
+ :goto_3
+ invoke-static {v0}, Ljava/lang/Integer;->signum(I)I
+
+ move-result v0
+
+ return v0
+
+ :cond_8
+ const/4 v0, 0x0
+
+ goto :goto_3
+.end method
diff --git a/test/566-checker-signum/src-art/Main.java b/test/566-checker-signum/src-art/Main.java
new file mode 100644
index 0000000..f1e1e1b
--- /dev/null
+++ b/test/566-checker-signum/src-art/Main.java
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+import java.lang.reflect.Method;
+
+public class Main {
+
+ /// CHECK-START: int Main.signByte(byte) intrinsics_recognition (after)
+ /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerSignum
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signByte(byte) instruction_simplifier (after)
+ /// CHECK-DAG: <<Result:i\d+>> Compare
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signByte(byte) instruction_simplifier (after)
+ /// CHECK-NOT: InvokeStaticOrDirect
+
+ private static int signByte(byte x) {
+ return Integer.signum(x);
+ }
+
+ /// CHECK-START: int Main.signShort(short) intrinsics_recognition (after)
+ /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerSignum
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signShort(short) instruction_simplifier (after)
+ /// CHECK-DAG: <<Result:i\d+>> Compare
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signShort(short) instruction_simplifier (after)
+ /// CHECK-NOT: InvokeStaticOrDirect
+
+ private static int signShort(short x) {
+ return Integer.signum(x);
+ }
+
+ /// CHECK-START: int Main.signChar(char) intrinsics_recognition (after)
+ /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerSignum
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signChar(char) instruction_simplifier (after)
+ /// CHECK-DAG: <<Result:i\d+>> Compare
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signChar(char) instruction_simplifier (after)
+ /// CHECK-NOT: InvokeStaticOrDirect
+
+ private static int signChar(char x) {
+ return Integer.signum(x);
+ }
+
+ /// CHECK-START: int Main.signInt(int) intrinsics_recognition (after)
+ /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerSignum
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signInt(int) instruction_simplifier (after)
+ /// CHECK-DAG: <<Result:i\d+>> Compare
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signInt(int) instruction_simplifier (after)
+ /// CHECK-NOT: InvokeStaticOrDirect
+
+ private static int signInt(int x) {
+ return Integer.signum(x);
+ }
+
+ /// CHECK-START: int Main.signLong(long) intrinsics_recognition (after)
+ /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:LongSignum
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signLong(long) instruction_simplifier (after)
+ /// CHECK-DAG: <<Result:i\d+>> Compare
+ /// CHECK-DAG: Return [<<Result>>]
+
+ /// CHECK-START: int Main.signLong(long) instruction_simplifier (after)
+ /// CHECK-NOT: InvokeStaticOrDirect
+
+ private static int signLong(long x) {
+ return Long.signum(x);
+ }
+
+
+ public static void testSignBoolean() throws Exception {
+ Method signBoolean = Class.forName("Main2").getMethod("signBoolean", boolean.class);
+ expectEquals(0, (int)signBoolean.invoke(null, false));
+ expectEquals(1, (int)signBoolean.invoke(null, true));
+ }
+
+ public static void testSignByte() {
+ expectEquals(-1, signByte((byte)Byte.MIN_VALUE));
+ expectEquals(-1, signByte((byte)-64));
+ expectEquals(-1, signByte((byte)-1));
+ expectEquals(0, signByte((byte)0));
+ expectEquals(1, signByte((byte)1));
+ expectEquals(1, signByte((byte)64));
+ expectEquals(1, signByte((byte)Byte.MAX_VALUE));
+ }
+
+ public static void testSignShort() {
+ expectEquals(-1, signShort((short)Short.MIN_VALUE));
+ expectEquals(-1, signShort((short)-12345));
+ expectEquals(-1, signShort((short)-1));
+ expectEquals(0, signShort((short)0));
+ expectEquals(1, signShort((short)1));
+ expectEquals(1, signShort((short)12345));
+ expectEquals(1, signShort((short)Short.MAX_VALUE));
+ }
+
+ public static void testSignChar() {
+ expectEquals(0, signChar((char)0));
+ expectEquals(1, signChar((char)1));
+ expectEquals(1, signChar((char)12345));
+ expectEquals(1, signChar((char)Character.MAX_VALUE));
+ }
+
+ public static void testSignInt() {
+ expectEquals(-1, signInt(Integer.MIN_VALUE));
+ expectEquals(-1, signInt(-12345));
+ expectEquals(-1, signInt(-1));
+ expectEquals(0, signInt(0));
+ expectEquals(1, signInt(1));
+ expectEquals(1, signInt(12345));
+ expectEquals(1, signInt(Integer.MAX_VALUE));
+
+ for (int i = -11; i <= 11; i++) {
+ int expected = 0;
+ if (i < 0) expected = -1;
+ else if (i > 0) expected = 1;
+ expectEquals(expected, signInt(i));
+ }
+ }
+
+ public static void testSignLong() {
+ expectEquals(-1, signLong(Long.MIN_VALUE));
+ expectEquals(-1, signLong(-12345L));
+ expectEquals(-1, signLong(-1L));
+ expectEquals(0, signLong(0L));
+ expectEquals(1, signLong(1L));
+ expectEquals(1, signLong(12345L));
+ expectEquals(1, signLong(Long.MAX_VALUE));
+
+ expectEquals(-1, signLong(0x800000007FFFFFFFL));
+ expectEquals(-1, signLong(0x80000000FFFFFFFFL));
+ expectEquals(1, signLong(0x000000007FFFFFFFL));
+ expectEquals(1, signLong(0x00000000FFFFFFFFL));
+ expectEquals(1, signLong(0x7FFFFFFF7FFFFFFFL));
+ expectEquals(1, signLong(0x7FFFFFFFFFFFFFFFL));
+
+ for (long i = -11L; i <= 11L; i++) {
+ int expected = 0;
+ if (i < 0) expected = -1;
+ else if (i > 0) expected = 1;
+ expectEquals(expected, signLong(i));
+ }
+
+ for (long i = Long.MIN_VALUE; i <= Long.MIN_VALUE + 11L; i++) {
+ expectEquals(-1, signLong(i));
+ }
+
+ for (long i = Long.MAX_VALUE; i >= Long.MAX_VALUE - 11L; i--) {
+ expectEquals(1, signLong(i));
+ }
+ }
+
+
+ public static void main(String args[]) throws Exception {
+ testSignBoolean();
+ testSignByte();
+ testSignShort();
+ testSignChar();
+ testSignInt();
+ testSignLong();
+
+ System.out.println("passed");
+ }
+
+ private static void expectEquals(int expected, int result) {
+ if (expected != result) {
+ throw new Error("Expected: " + expected + ", found: " + result);
+ }
+ }
+}
diff --git a/test/566-checker-signum/src/Main.java b/test/566-checker-signum/src/Main.java
index 7fc9e84..fa8e5cd 100644
--- a/test/566-checker-signum/src/Main.java
+++ b/test/566-checker-signum/src/Main.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 The Android Open Source Project
+ * Copyright (C) 2018 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.
@@ -14,222 +14,9 @@
* limitations under the License.
*/
+// This file is just for running on the RI as the test is ART specific.
public class Main {
-
- /// CHECK-START: int Main.signBoolean(boolean) intrinsics_recognition (after)
- /// CHECK-DAG: <<Method:[ij]\d+>> CurrentMethod
- /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0
- /// CHECK-DAG: <<One:i\d+>> IntConstant 1
- /// CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>]
- /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect [<<Phi>>,<<Method>>] intrinsic:IntegerSignum
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signBoolean(boolean) instruction_simplifier (after)
- /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0
- /// CHECK-DAG: <<One:i\d+>> IntConstant 1
- /// CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>]
- /// CHECK-DAG: <<Result:i\d+>> Compare [<<Phi>>,<<Zero>>]
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signBoolean(boolean) instruction_simplifier (after)
- /// CHECK-NOT: InvokeStaticOrDirect
-
- /// CHECK-START: int Main.signBoolean(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: <<Result:i\d+>> Compare [<<Sel>>,<<Zero>>]
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signBoolean(boolean) select_generator (after)
- /// CHECK-NOT: Phi
-
- /// CHECK-START: int Main.signBoolean(boolean) instruction_simplifier$after_bce (after)
- /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
- /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0
- /// CHECK-DAG: <<Result:i\d+>> Compare [<<Arg>>,<<Zero>>]
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signBoolean(boolean) instruction_simplifier$after_bce (after)
- /// CHECK-NOT: Select
-
- private static int signBoolean(boolean x) {
- return Integer.signum(x ? 1 : 0);
- }
-
- /// CHECK-START: int Main.signByte(byte) intrinsics_recognition (after)
- /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerSignum
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signByte(byte) instruction_simplifier (after)
- /// CHECK-DAG: <<Result:i\d+>> Compare
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signByte(byte) instruction_simplifier (after)
- /// CHECK-NOT: InvokeStaticOrDirect
-
- private static int signByte(byte x) {
- return Integer.signum(x);
- }
-
- /// CHECK-START: int Main.signShort(short) intrinsics_recognition (after)
- /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerSignum
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signShort(short) instruction_simplifier (after)
- /// CHECK-DAG: <<Result:i\d+>> Compare
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signShort(short) instruction_simplifier (after)
- /// CHECK-NOT: InvokeStaticOrDirect
-
- private static int signShort(short x) {
- return Integer.signum(x);
- }
-
- /// CHECK-START: int Main.signChar(char) intrinsics_recognition (after)
- /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerSignum
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signChar(char) instruction_simplifier (after)
- /// CHECK-DAG: <<Result:i\d+>> Compare
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signChar(char) instruction_simplifier (after)
- /// CHECK-NOT: InvokeStaticOrDirect
-
- private static int signChar(char x) {
- return Integer.signum(x);
- }
-
- /// CHECK-START: int Main.signInt(int) intrinsics_recognition (after)
- /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerSignum
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signInt(int) instruction_simplifier (after)
- /// CHECK-DAG: <<Result:i\d+>> Compare
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signInt(int) instruction_simplifier (after)
- /// CHECK-NOT: InvokeStaticOrDirect
-
- private static int signInt(int x) {
- return Integer.signum(x);
- }
-
- /// CHECK-START: int Main.signLong(long) intrinsics_recognition (after)
- /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:LongSignum
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signLong(long) instruction_simplifier (after)
- /// CHECK-DAG: <<Result:i\d+>> Compare
- /// CHECK-DAG: Return [<<Result>>]
-
- /// CHECK-START: int Main.signLong(long) instruction_simplifier (after)
- /// CHECK-NOT: InvokeStaticOrDirect
-
- private static int signLong(long x) {
- return Long.signum(x);
- }
-
-
- public static void testSignBoolean() {
- expectEquals(0, signBoolean(false));
- expectEquals(1, signBoolean(true));
- }
-
- public static void testSignByte() {
- expectEquals(-1, signByte((byte)Byte.MIN_VALUE));
- expectEquals(-1, signByte((byte)-64));
- expectEquals(-1, signByte((byte)-1));
- expectEquals(0, signByte((byte)0));
- expectEquals(1, signByte((byte)1));
- expectEquals(1, signByte((byte)64));
- expectEquals(1, signByte((byte)Byte.MAX_VALUE));
- }
-
- public static void testSignShort() {
- expectEquals(-1, signShort((short)Short.MIN_VALUE));
- expectEquals(-1, signShort((short)-12345));
- expectEquals(-1, signShort((short)-1));
- expectEquals(0, signShort((short)0));
- expectEquals(1, signShort((short)1));
- expectEquals(1, signShort((short)12345));
- expectEquals(1, signShort((short)Short.MAX_VALUE));
- }
-
- public static void testSignChar() {
- expectEquals(0, signChar((char)0));
- expectEquals(1, signChar((char)1));
- expectEquals(1, signChar((char)12345));
- expectEquals(1, signChar((char)Character.MAX_VALUE));
- }
-
- public static void testSignInt() {
- expectEquals(-1, signInt(Integer.MIN_VALUE));
- expectEquals(-1, signInt(-12345));
- expectEquals(-1, signInt(-1));
- expectEquals(0, signInt(0));
- expectEquals(1, signInt(1));
- expectEquals(1, signInt(12345));
- expectEquals(1, signInt(Integer.MAX_VALUE));
-
- for (int i = -11; i <= 11; i++) {
- int expected = 0;
- if (i < 0) expected = -1;
- else if (i > 0) expected = 1;
- expectEquals(expected, signInt(i));
- }
- }
-
- public static void testSignLong() {
- expectEquals(-1, signLong(Long.MIN_VALUE));
- expectEquals(-1, signLong(-12345L));
- expectEquals(-1, signLong(-1L));
- expectEquals(0, signLong(0L));
- expectEquals(1, signLong(1L));
- expectEquals(1, signLong(12345L));
- expectEquals(1, signLong(Long.MAX_VALUE));
-
- expectEquals(-1, signLong(0x800000007FFFFFFFL));
- expectEquals(-1, signLong(0x80000000FFFFFFFFL));
- expectEquals(1, signLong(0x000000007FFFFFFFL));
- expectEquals(1, signLong(0x00000000FFFFFFFFL));
- expectEquals(1, signLong(0x7FFFFFFF7FFFFFFFL));
- expectEquals(1, signLong(0x7FFFFFFFFFFFFFFFL));
-
- for (long i = -11L; i <= 11L; i++) {
- int expected = 0;
- if (i < 0) expected = -1;
- else if (i > 0) expected = 1;
- expectEquals(expected, signLong(i));
- }
-
- for (long i = Long.MIN_VALUE; i <= Long.MIN_VALUE + 11L; i++) {
- expectEquals(-1, signLong(i));
- }
-
- for (long i = Long.MAX_VALUE; i >= Long.MAX_VALUE - 11L; i--) {
- expectEquals(1, signLong(i));
- }
- }
-
-
- public static void main(String args[]) {
- testSignBoolean();
- testSignByte();
- testSignShort();
- testSignChar();
- testSignInt();
- testSignLong();
-
+ public static void main(String[] args) {
System.out.println("passed");
}
-
- private static void expectEquals(int expected, int result) {
- if (expected != result) {
- throw new Error("Expected: " + expected + ", found: " + result);
- }
- }
}