# 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 LSmaliTests; .super Ljava/lang/Object; ## CHECK-START: int SmaliTests.EqualTrueRhs(boolean) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 1 ## CHECK-DAG: <> Equal [<>,<>] ## CHECK-DAG: If [<>] ## CHECK-START: int SmaliTests.EqualTrueRhs(boolean) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: If [<>] .method public static EqualTrueRhs(Z)I .registers 3 const v0, 0x1 const v1, 0x5 if-eq p0, v0, :return const v1, 0x3 :return return v1 .end method ## CHECK-START: int SmaliTests.EqualTrueLhs(boolean) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 1 ## CHECK-DAG: <> Equal [<>,<>] ## CHECK-DAG: If [<>] ## CHECK-START: int SmaliTests.EqualTrueLhs(boolean) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: If [<>] .method public static EqualTrueLhs(Z)I .registers 3 const v0, 0x1 const v1, 0x5 if-eq v0, p0, :return const v1, 0x3 :return return v1 .end method ## CHECK-START: int SmaliTests.EqualFalseRhs(boolean) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 0 ## CHECK-DAG: <> Equal [<>,<>] ## CHECK-DAG: If [<>] ## CHECK-START: int SmaliTests.EqualFalseRhs(boolean) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: If [<>] .method public static EqualFalseRhs(Z)I .registers 3 const v0, 0x0 const v1, 0x3 if-eq p0, v0, :return const v1, 0x5 :return return v1 .end method ## CHECK-START: int SmaliTests.EqualFalseLhs(boolean) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 0 ## CHECK-DAG: <> Equal [<>,<>] ## CHECK-DAG: If [<>] ## CHECK-START: int SmaliTests.EqualFalseLhs(boolean) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: If [<>] .method public static EqualFalseLhs(Z)I .registers 3 const v0, 0x0 const v1, 0x3 if-eq v0, p0, :return const v1, 0x5 :return return v1 .end method ## CHECK-START: int SmaliTests.NotEqualTrueRhs(boolean) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 1 ## CHECK-DAG: <> NotEqual [<>,<>] ## CHECK-DAG: If [<>] ## CHECK-START: int SmaliTests.NotEqualTrueRhs(boolean) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: If [<>] .method public static NotEqualTrueRhs(Z)I .registers 3 const v0, 0x1 const v1, 0x3 if-ne p0, v0, :return const v1, 0x5 :return return v1 .end method ## CHECK-START: int SmaliTests.NotEqualTrueLhs(boolean) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 1 ## CHECK-DAG: <> NotEqual [<>,<>] ## CHECK-DAG: If [<>] ## CHECK-START: int SmaliTests.NotEqualTrueLhs(boolean) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: If [<>] .method public static NotEqualTrueLhs(Z)I .registers 3 const v0, 0x1 const v1, 0x3 if-ne v0, p0, :return const v1, 0x5 :return return v1 .end method ## CHECK-START: int SmaliTests.NotEqualFalseRhs(boolean) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 0 ## CHECK-DAG: <> NotEqual [<>,<>] ## CHECK-DAG: If [<>] ## CHECK-START: int SmaliTests.NotEqualFalseRhs(boolean) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: If [<>] .method public static NotEqualFalseRhs(Z)I .registers 3 const v0, 0x0 const v1, 0x5 if-ne p0, v0, :return const v1, 0x3 :return return v1 .end method ## CHECK-START: int SmaliTests.NotEqualFalseLhs(boolean) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 0 ## CHECK-DAG: <> NotEqual [<>,<>] ## CHECK-DAG: If [<>] ## CHECK-START: int SmaliTests.NotEqualFalseLhs(boolean) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: If [<>] .method public static NotEqualFalseLhs(Z)I .registers 3 const v0, 0x0 const v1, 0x5 if-ne v0, p0, :return const v1, 0x3 :return return v1 .end method ## CHECK-START: int SmaliTests.AddSubConst(int) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 7 ## CHECK-DAG: <> IntConstant 8 ## CHECK-DAG: <> Add [<>,<>] ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: Return [<>] ## CHECK-START: int SmaliTests.AddSubConst(int) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant -1 ## CHECK-DAG: <> Add [<>,<>] ## CHECK-DAG: Return [<>] .method public static AddSubConst(I)I .registers 3 .prologue add-int/lit8 v0, p0, 7 const/16 v1, 8 sub-int v0, v0, v1 return v0 .end method ## CHECK-START: int SmaliTests.SubAddConst(int) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 3 ## CHECK-DAG: <> IntConstant 4 ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: <> Add [<>,<>] ## CHECK-DAG: Return [<>] ## CHECK-START: int SmaliTests.SubAddConst(int) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 1 ## CHECK-DAG: <> Add [<>,<>] ## CHECK-DAG: Return [<>] .method public static SubAddConst(I)I .registers 2 .prologue const/4 v0, 3 sub-int v0, p0, v0 add-int/lit8 v0, v0, 4 return v0 .end method ## CHECK-START: int SmaliTests.SubSubConst1(int) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 9 ## CHECK-DAG: <> IntConstant 10 ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: Return [<>] ## CHECK-START: int SmaliTests.SubSubConst1(int) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant -19 ## CHECK-DAG: <> Add [<>,<>] ## CHECK-DAG: Return [<>] .method public static SubSubConst1(I)I .registers 3 .prologue const/16 v1, 9 sub-int v0, p0, v1 const/16 v1, 10 sub-int v0, v0, v1 return v0 .end method ## CHECK-START: int SmaliTests.SubSubConst2(int) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 11 ## CHECK-DAG: <> IntConstant 12 ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: Return [<>] ## CHECK-START: int SmaliTests.SubSubConst2(int) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant -1 ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: Return [<>] .method public static SubSubConst2(I)I .registers 3 .prologue rsub-int/lit8 v0, p0, 11 const/16 v1, 12 sub-int v0, v0, v1 return v0 .end method ## CHECK-START: int SmaliTests.SubSubConst3(int) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 15 ## CHECK-DAG: <> IntConstant 16 ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: Return [<>] ## CHECK-START: int SmaliTests.SubSubConst3(int) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 31 ## CHECK-DAG: <> Sub [<>,<>] ## CHECK-DAG: Return [<>] .method public static SubSubConst3(I)I .registers 2 .prologue const/16 v0, 16 sub-int v0, p0, v0 rsub-int/lit8 v0, v0, 15 return v0 .end method # Test simplification of the `~~var` pattern. # The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`. ## CHECK-START: long SmaliTests.$noinline$NotNot1(long) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> Not [<>] ## CHECK-DAG: <> Not [<>] ## CHECK-DAG: Return [<>] ## CHECK-START: long SmaliTests.$noinline$NotNot1(long) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: Return [<>] ## CHECK-START: long SmaliTests.$noinline$NotNot1(long) instruction_simplifier (after) ## CHECK-NOT: Not .method public static $noinline$NotNot1(J)J .registers 4 .param p0, "arg" # J .prologue # return ~~arg not-long v0, p0 not-long v0, v0 return-wide v0 .end method ## CHECK-START: int SmaliTests.$noinline$NotNot2(int) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> Not [<>] ## CHECK-DAG: <> Not [<>] ## CHECK-DAG: <> Add [<>,<>] ## CHECK-DAG: Return [<>] ## CHECK-START: int SmaliTests.$noinline$NotNot2(int) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> Not [<>] ## CHECK-DAG: <> Add [<>,<>] ## CHECK-DAG: Return [<>] ## CHECK-START: int SmaliTests.$noinline$NotNot2(int) instruction_simplifier (after) ## CHECK: Not ## CHECK-NOT: Not .method public static $noinline$NotNot2(I)I .registers 3 .param p0, "arg" # I .prologue # temp = ~arg; return temp + ~temp; not-int v0, p0 not-int v1, v0 add-int/2addr v1, v0 return v1 .end method # Test simplification of double Boolean negation. Note that sometimes # both negations can be removed but we only expect the simplifier to # remove the second. ## CHECK-START: boolean SmaliTests.$noinline$NotNotBool(boolean) instruction_simplifier (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> IntConstant 1 ## CHECK-DAG: <> InvokeStaticOrDirect ## CHECK-DAG: <> Xor [<>,<>] ## CHECK-DAG: Return [<>] ## CHECK-START: boolean SmaliTests.$noinline$NotNotBool(boolean) instruction_simplifier (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> InvokeStaticOrDirect ## CHECK-DAG: <> BooleanNot [<>] ## CHECK-DAG: Return [<>] ## CHECK-START: boolean SmaliTests.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> BooleanNot [<>] ## CHECK-DAG: <> BooleanNot [<>] ## CHECK-DAG: Return [<>] ## CHECK-START: boolean SmaliTests.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: <> BooleanNot [<>] ## CHECK-DAG: Return [<>] ## CHECK-START: boolean SmaliTests.$noinline$NotNotBool(boolean) dead_code_elimination$final (after) ## CHECK-DAG: <> ParameterValue ## CHECK-DAG: Return [<>] .method public static NegateValue(Z)Z .registers 2 .param p0, "arg" # Z .prologue # return !arg xor-int/lit8 v0, p0, 0x1 return v0 .end method .method public static $noinline$NotNotBool(Z)Z .registers 2 .param p0, "arg" # Z .prologue # return !Negate(arg) invoke-static {p0}, LSmaliTests;->NegateValue(Z)Z move-result v0 xor-int/lit8 v0, v0, 0x1 return v0 .end method