1# Copyright (C) 2018 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15.class public LSmaliTests2;
16.super Ljava/lang/Object;
17
18## CHECK-START: int SmaliTests2.$noinline$XorAllOnes(int) instruction_simplifier (before)
19## CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
20## CHECK-DAG:     <<ConstF:i\d+>>   IntConstant -1
21## CHECK-DAG:     <<Xor:i\d+>>      Xor [<<Arg>>,<<ConstF>>]
22## CHECK-DAG:                       Return [<<Xor>>]
23
24## CHECK-START: int SmaliTests2.$noinline$XorAllOnes(int) instruction_simplifier (after)
25## CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
26## CHECK-DAG:     <<Not:i\d+>>      Not [<<Arg>>]
27## CHECK-DAG:                       Return [<<Not>>]
28
29## CHECK-START: int SmaliTests2.$noinline$XorAllOnes(int) instruction_simplifier (after)
30## CHECK-NOT:                       Xor
31
32# Original java source:
33#
34#     return arg ^ -1;
35#
36.method public static $noinline$XorAllOnes(I)I
37    .registers 2
38    .param p0, "arg"    # I
39
40    .prologue
41    .line 658
42    xor-int/lit8 v0, p0, -0x1
43
44    return v0
45.end method
46
47# Test simplification of the `~~var` pattern.
48# The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`.
49
50## CHECK-START: long SmaliTests2.$noinline$NotNot1(long) instruction_simplifier (before)
51## CHECK-DAG:     <<Arg:j\d+>>       ParameterValue
52## CHECK-DAG:     <<ConstNeg1:j\d+>> LongConstant -1
53## CHECK-DAG:     <<Not1:j\d+>>      Xor [<<Arg>>,<<ConstNeg1>>]
54## CHECK-DAG:     <<Not2:j\d+>>      Xor [<<Not1>>,<<ConstNeg1>>]
55## CHECK-DAG:                        Return [<<Not2>>]
56
57## CHECK-START: long SmaliTests2.$noinline$NotNot1(long) instruction_simplifier (after)
58## CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
59## CHECK-DAG:                       Return [<<Arg>>]
60
61## CHECK-START: long SmaliTests2.$noinline$NotNot1(long) instruction_simplifier (after)
62## CHECK-NOT:                       Xor
63
64# Original java source:
65#
66#     return ~~arg;
67.method public static $noinline$NotNot1(J)J
68    .registers 6
69    .param p0, "arg"    # J
70
71    .prologue
72    const-wide/16 v2, -0x1
73
74    .line 1001
75    xor-long v0, p0, v2
76
77    xor-long/2addr v0, v2
78
79    return-wide v0
80.end method
81
82## CHECK-START: int SmaliTests2.$noinline$NotNot2(int) instruction_simplifier (before)
83## CHECK-DAG:     <<Arg:i\d+>>       ParameterValue
84## CHECK-DAG:     <<ConstNeg1:i\d+>> IntConstant -1
85## CHECK-DAG:     <<Not1:i\d+>>      Xor [<<Arg>>,<<ConstNeg1>>]
86## CHECK-DAG:     <<Not2:i\d+>>      Xor [<<Not1>>,<<ConstNeg1>>]
87## CHECK-DAG:     <<Add:i\d+>>       Add [<<Not2>>,<<Not1>>]
88## CHECK-DAG:                        Return [<<Add>>]
89
90## CHECK-START: int SmaliTests2.$noinline$NotNot2(int) instruction_simplifier (after)
91## CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
92## CHECK-DAG:     <<Not:i\d+>>      Not [<<Arg>>]
93## CHECK-DAG:     <<Add:i\d+>>      Add [<<Arg>>,<<Not>>]
94## CHECK-DAG:                       Return [<<Add>>]
95
96## CHECK-START: int SmaliTests2.$noinline$NotNot2(int) instruction_simplifier (after)
97## CHECK:                           Not
98## CHECK-NOT:                       Not
99
100## CHECK-START: int SmaliTests2.$noinline$NotNot2(int) instruction_simplifier (after)
101## CHECK-NOT:                       Xor
102
103# Original java source:
104#
105#     int temp = ~arg;
106#     return temp + ~temp;
107#
108.method public static $noinline$NotNot2(I)I
109    .registers 3
110    .param p0, "arg"    # I
111
112    .prologue
113    .line 1026
114    xor-int/lit8 v0, p0, -0x1
115
116    .line 1027
117    .local v0, "temp":I
118    xor-int/lit8 v1, v0, -0x1
119
120    add-int/2addr v1, v0
121
122    return v1
123.end method
124
125# Original java source:
126#
127#     return !arg;
128#
129.method public static NegateValue(Z)Z
130    .registers 2
131    .param p0, "arg"    # Z
132
133    .prologue
134    .line 1216
135    if-nez p0, :cond_4
136
137    const/4 v0, 0x1
138
139    :goto_3
140    return v0
141
142    :cond_4
143    const/4 v0, 0x0
144
145    goto :goto_3
146.end method
147
148# Test simplification of double Boolean negation. Note that sometimes
149# both negations can be removed but we only expect the simplifier to
150# remove the second.
151
152## CHECK-START: boolean SmaliTests2.$noinline$NotNotBool(boolean) instruction_simplifier (before)
153## CHECK-DAG:     <<Arg:z\d+>>       ParameterValue
154## CHECK-DAG:     <<Const1:i\d+>>    IntConstant 0
155## CHECK-DAG:     <<Result:z\d+>>    InvokeStaticOrDirect method_name:SmaliTests2.NegateValue
156## CHECK-DAG:     <<NotResult:z\d+>> NotEqual [<<Result>>,<<Const1>>]
157## CHECK-DAG:                        If [<<NotResult>>]
158
159## CHECK-START: boolean SmaliTests2.$noinline$NotNotBool(boolean) instruction_simplifier (after)
160## CHECK-NOT:                        NotEqual
161
162## CHECK-START: boolean SmaliTests2.$noinline$NotNotBool(boolean) instruction_simplifier (after)
163## CHECK-DAG:     <<Arg:z\d+>>       ParameterValue
164## CHECK-DAG:     <<Result:z\d+>>    InvokeStaticOrDirect method_name:SmaliTests2.NegateValue
165## CHECK-DAG:     <<Const0:i\d+>>    IntConstant 0
166## CHECK-DAG:     <<Const1:i\d+>>    IntConstant 1
167## CHECK-DAG:     <<Phi:i\d+>>       Phi [<<Const1>>,<<Const0>>]
168## CHECK-DAG:                        Return [<<Phi>>]
169
170## CHECK-START: boolean SmaliTests2.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before)
171## CHECK-DAG:     <<Arg:z\d+>>       ParameterValue
172## CHECK-DAG:     <<Const0:i\d+>>    IntConstant 0
173## CHECK-DAG:     <<Const1:i\d+>>    IntConstant 1
174## CHECK-DAG:                        If [<<Arg>>]
175## CHECK-DAG:     <<Phi:i\d+>>       Phi [<<Const1>>,<<Const0>>]
176## CHECK-DAG:                        Return [<<Phi>>]
177
178## CHECK-START: boolean SmaliTests2.$noinline$NotNotBool(boolean) instruction_simplifier$after_gvn (after)
179## CHECK-DAG:     <<Arg:z\d+>>       ParameterValue
180## CHECK-DAG:                        Return [<<Arg>>]
181
182# Original java source:
183#
184#     return !(NegateValue(arg));
185#
186.method public static $noinline$NotNotBool(Z)Z
187    .registers 2
188    .param p0, "arg"    # Z
189
190    .prologue
191    .line 1220
192    invoke-static {p0}, LSmaliTests2;->NegateValue(Z)Z
193
194    move-result v0
195
196    if-nez v0, :cond_8
197
198    const/4 v0, 0x1
199
200    :goto_7
201    return v0
202
203    :cond_8
204    const/4 v0, 0x0
205
206    goto :goto_7
207.end method
208
209## CHECK-START: int SmaliTests2.$noinline$bug68142795Short(short) instruction_simplifier (before)
210## CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
211## CHECK-DAG:      <<Const:i\d+>>    IntConstant 65535
212## CHECK-DAG:      <<And1:i\d+>>     And [<<Arg>>,<<Const>>]
213## CHECK-DAG:      <<And2:i\d+>>     And [<<And1>>,<<Const>>]
214## CHECK-DAG:      <<Conv:s\d+>>     TypeConversion [<<And2>>]
215## CHECK-DAG:                        Return [<<Conv>>]
216
217## CHECK-START: int SmaliTests2.$noinline$bug68142795Short(short) instruction_simplifier (after)
218## CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
219## CHECK-DAG:                        Return [<<Arg>>]
220
221# Original java source
222#
223#     return (short)(0xffff & (s & 0xffff));
224#
225.method public static $noinline$bug68142795Short(S)I
226    .registers 3
227    .param p0, "s"    # S
228
229    .prologue
230    const v1, 0xffff
231
232    .line 2562
233    and-int v0, p0, v1
234
235    and-int/2addr v0, v1
236
237    int-to-short v0, v0
238
239    return v0
240.end method
241
242# Original java source
243#
244#     return 255;
245#
246.method private static $inline$get255()I
247    .registers 1
248
249    .prologue
250    .line 2849
251    const/16 v0, 0xff
252
253    return v0
254.end method
255
256## CHECK-START: int SmaliTests2.$noinline$bug68142795Boolean(boolean) instruction_simplifier$after_inlining (before)
257## CHECK-DAG:      <<Arg:z\d+>>      ParameterValue
258## CHECK-DAG:      <<Const0:i\d+>>   IntConstant 0
259## CHECK-DAG:      <<Const1:i\d+>>   IntConstant 1
260## CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
261## CHECK-DAG:                        If [<<Arg>>]
262## CHECK-DAG:      <<Phi:i\d+>>      Phi [<<Const1>>,<<Const0>>]
263## CHECK-DAG:      <<And:i\d+>>      And [<<Const255>>,<<Phi>>]
264## CHECK-DAG:      <<Conv:b\d+>>     TypeConversion [<<And>>]
265## CHECK-DAG:                        Return [<<Conv>>]
266
267## CHECK-START: int SmaliTests2.$noinline$bug68142795Boolean(boolean) instruction_simplifier$after_gvn (after)
268## CHECK-DAG:      <<Arg:z\d+>>      ParameterValue
269## CHECK-DAG:                        Return [<<Arg>>]
270
271# Original java source
272#
273#     int v = b ? 1 : 0;  // Should be simplified to "b" after inlining.
274#     return (byte)($inline$get255() & v);
275#
276.method public static $noinline$bug68142795Boolean(Z)I
277    .registers 3
278    .param p0, "b"    # Z
279
280    .prologue
281    .line 2580
282    if-eqz p0, :cond_a
283
284    const/4 v0, 0x1
285
286    .line 2581
287    .local v0, "v":I
288    :goto_3
289    invoke-static {}, LSmaliTests2;->$inline$get255()I
290
291    move-result v1
292
293    and-int/2addr v1, v0
294
295    int-to-byte v1, v1
296
297    return v1
298
299    .line 2580
300    .end local v0    # "v":I
301    :cond_a
302    const/4 v0, 0x0
303
304    goto :goto_3
305.end method
306