diff options
| author | 2017-09-19 12:56:00 +0000 | |
|---|---|---|
| committer | 2017-09-19 12:56:00 +0000 | |
| commit | a62747766bd1ec719e812eecc66bc519ff058c3b (patch) | |
| tree | 29d3bfa02b37d31eb8c8821c5a405184064cbaed | |
| parent | e1fe6a98d43118fe0698b5122339c7af072fc418 (diff) | |
| parent | 75b4e1274fbf8973a9b484771c6a6601b48a03e1 (diff) | |
Merge "Make 567-checker-compare less Dex-sensitive."
| -rw-r--r-- | test/567-checker-compare/smali/Smali.smali | 92 | ||||
| -rw-r--r-- | test/567-checker-compare/src/Main.java | 46 |
2 files changed, 106 insertions, 32 deletions
diff --git a/test/567-checker-compare/smali/Smali.smali b/test/567-checker-compare/smali/Smali.smali new file mode 100644 index 0000000000..8fc39f1acd --- /dev/null +++ b/test/567-checker-compare/smali/Smali.smali @@ -0,0 +1,92 @@ +# 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: int Smali.compareBooleans(boolean, 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: <<PhiX:i\d+>> Phi [<<One>>,<<Zero>>] +## CHECK-DAG: <<PhiY:i\d+>> Phi [<<One>>,<<Zero>>] +## CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect [<<PhiX>>,<<PhiY>>,<<Method>>] intrinsic:IntegerCompare +## CHECK-DAG: Return [<<Result>>] + +## CHECK-START: int Smali.compareBooleans(boolean, boolean) instruction_simplifier (after) +## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 +## CHECK-DAG: <<One:i\d+>> IntConstant 1 +## CHECK-DAG: <<PhiX:i\d+>> Phi [<<One>>,<<Zero>>] +## CHECK-DAG: <<PhiY:i\d+>> Phi [<<One>>,<<Zero>>] +## CHECK-DAG: <<Result:i\d+>> Compare [<<PhiX>>,<<PhiY>>] +## CHECK-DAG: Return [<<Result>>] + +## CHECK-START: int Smali.compareBooleans(boolean, boolean) instruction_simplifier (after) +## CHECK-NOT: InvokeStaticOrDirect + +## CHECK-START: int Smali.compareBooleans(boolean, boolean) select_generator (after) +## CHECK: <<ArgX:z\d+>> ParameterValue +## CHECK: <<ArgY:z\d+>> ParameterValue +## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 +## CHECK-DAG: <<One:i\d+>> IntConstant 1 +## CHECK-DAG: <<SelX:i\d+>> Select [<<Zero>>,<<One>>,<<ArgX>>] +## CHECK-DAG: <<SelY:i\d+>> Select [<<Zero>>,<<One>>,<<ArgY>>] +## CHECK-DAG: <<Result:i\d+>> Compare [<<SelX>>,<<SelY>>] +## CHECK-DAG: Return [<<Result>>] + +## CHECK-START: int Smali.compareBooleans(boolean, boolean) select_generator (after) +## CHECK-NOT: Phi + +## CHECK-START: int Smali.compareBooleans(boolean, boolean) instruction_simplifier$after_bce (after) +## CHECK: <<ArgX:z\d+>> ParameterValue +## CHECK: <<ArgY:z\d+>> ParameterValue +## CHECK-DAG: <<Result:i\d+>> Compare [<<ArgX>>,<<ArgY>>] +## CHECK-DAG: Return [<<Result>>] + +## CHECK-START: int Smali.compareBooleans(boolean, boolean) instruction_simplifier$after_bce (after) +## CHECK-NOT: Select + +# Note: This test has been written in smali (in addition to the source version) because Dexers +# such as D8 can perform the same type of intrinsic replacements. +.method public static compareBooleans(ZZ)I + # return Integer.compare((x ? 1 : 0), (y ? 1 : 0)); + .registers 5 + const/4 v0, 0x1 + + const/4 v1, 0x0 + + if-eqz p0, :cond_c + + move v2, v0 + + :goto_5 + if-eqz p1, :cond_e + + :goto_7 + invoke-static {v2, v0}, Ljava/lang/Integer;->compare(II)I + + move-result v0 + + return v0 + + :cond_c + move v2, v1 + + goto :goto_5 + + :cond_e + move v0, v1 + + goto :goto_7 +.end method diff --git a/test/567-checker-compare/src/Main.java b/test/567-checker-compare/src/Main.java index a05bb60fad..abfaf9f146 100644 --- a/test/567-checker-compare/src/Main.java +++ b/test/567-checker-compare/src/Main.java @@ -14,6 +14,8 @@ * limitations under the License. */ +import java.lang.reflect.Method; + public class Main { public static boolean doThrow = false; @@ -42,36 +44,6 @@ public class Main { } } - /// CHECK-START: int Main.compareBooleans(boolean, 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: <<PhiX:i\d+>> Phi [<<One>>,<<Zero>>] - /// CHECK-DAG: <<PhiY:i\d+>> Phi [<<One>>,<<Zero>>] - /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect [<<PhiX>>,<<PhiY>>,<<Method>>] intrinsic:IntegerCompare - /// CHECK-DAG: Return [<<Result>>] - - /// CHECK-START: int Main.compareBooleans(boolean, boolean) instruction_simplifier (after) - /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 - /// CHECK-DAG: <<One:i\d+>> IntConstant 1 - /// CHECK-DAG: <<PhiX:i\d+>> Phi [<<One>>,<<Zero>>] - /// CHECK-DAG: <<PhiY:i\d+>> Phi [<<One>>,<<Zero>>] - /// CHECK-DAG: <<Result:i\d+>> Compare [<<PhiX>>,<<PhiY>>] - /// CHECK-DAG: Return [<<Result>>] - - /// CHECK-START: int Main.compareBooleans(boolean, boolean) instruction_simplifier (after) - /// CHECK-NOT: InvokeStaticOrDirect - - /// CHECK-START: int Main.compareBooleans(boolean, boolean) select_generator (after) - /// CHECK: <<ArgX:z\d+>> ParameterValue - /// CHECK: <<ArgY:z\d+>> ParameterValue - /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0 - /// CHECK-DAG: <<One:i\d+>> IntConstant 1 - /// CHECK-DAG: <<SelX:i\d+>> Select [<<Zero>>,<<One>>,<<ArgX>>] - /// CHECK-DAG: <<SelY:i\d+>> Select [<<Zero>>,<<One>>,<<ArgY>>] - /// CHECK-DAG: <<Result:i\d+>> Compare [<<SelX>>,<<SelY>>] - /// CHECK-DAG: Return [<<Result>>] - /// CHECK-START: int Main.compareBooleans(boolean, boolean) select_generator (after) /// CHECK-NOT: Phi @@ -88,6 +60,12 @@ public class Main { return Integer.compare((x ? 1 : 0), (y ? 1 : 0)); } + private static int compareBooleansSmali(boolean x, boolean y) throws Exception { + Class<?> c = Class.forName("Smali"); + Method m = c.getMethod("compareBooleans", boolean.class, boolean.class); + return (Integer) m.invoke(null, x, y); + } + /// CHECK-START: int Main.compareBytes(byte, byte) intrinsics_recognition (after) /// CHECK-DAG: <<Result:i\d+>> InvokeStaticOrDirect intrinsic:IntegerCompare /// CHECK-DAG: Return [<<Result>>] @@ -348,13 +326,17 @@ public class Main { } - public static void testCompareBooleans() { + public static void testCompareBooleans() throws Exception { expectEquals(-1, compareBooleans(false, true)); + expectEquals(-1, compareBooleansSmali(false, true)); expectEquals(0, compareBooleans(false, false)); expectEquals(0, compareBooleans(true, true)); + expectEquals(0, compareBooleansSmali(false, false)); + expectEquals(0, compareBooleansSmali(true, true)); expectEquals(1, compareBooleans(true, false)); + expectEquals(1, compareBooleansSmali(true, false)); } public static void testCompareBytes() { @@ -915,7 +897,7 @@ public class Main { } - public static void main(String args[]) { + public static void main(String args[]) throws Exception { $opt$noinline$testReplaceInputWithItself(42); testCompareBooleans(); |