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 LMain2;
16.super Ljava/lang/Object;
17.source "Main2.java"
18
19
20# direct methods
21.method constructor <init>()V
22    .registers 1
23
24    .prologue
25    .line 17
26    invoke-direct {p0}, Ljava/lang/Object;-><init>()V
27
28    return-void
29.end method
30
31# Elementary test negating a boolean. Verifies that blocks are merged and
32# empty branches removed.
33
34## CHECK-START: boolean Main2.BooleanNot(boolean) select_generator (before)
35## CHECK-DAG:     <<Param:z\d+>>    ParameterValue
36## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
37## CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
38## CHECK-DAG:                       If [<<Param>>]
39## CHECK-DAG:     <<Phi:i\d+>>      Phi [<<Const1>>,<<Const0>>]
40## CHECK-DAG:                       Return [<<Phi>>]
41
42## CHECK-START: boolean Main2.BooleanNot(boolean) select_generator (before)
43## CHECK:                           Goto
44## CHECK:                           Goto
45## CHECK:                           Goto
46## CHECK-NOT:                       Goto
47
48## CHECK-START: boolean Main2.BooleanNot(boolean) select_generator (after)
49## CHECK-DAG:     <<Param:z\d+>>    ParameterValue
50## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
51## CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
52## CHECK-DAG:     <<NotParam:i\d+>> Select [<<Const1>>,<<Const0>>,<<Param>>]
53## CHECK-DAG:                       Return [<<NotParam>>]
54
55## CHECK-START: boolean Main2.BooleanNot(boolean) select_generator (after)
56## CHECK-NOT:                       If
57## CHECK-NOT:                       Phi
58
59## CHECK-START: boolean Main2.BooleanNot(boolean) select_generator (after)
60## CHECK:                           Goto
61## CHECK-NOT:                       Goto
62
63# The original java source of this method:
64#
65#     return !x;
66#
67.method public static BooleanNot(Z)Z
68    .registers 2
69    .param p0, "x"    # Z
70
71    .prologue
72    .line 70
73    if-nez p0, :cond_4
74
75    const/4 v0, 0x1
76
77    :goto_3
78    return v0
79
80    :cond_4
81    const/4 v0, 0x0
82
83    goto :goto_3
84.end method
85
86# Program which further uses negated conditions.
87# Note that Phis are discovered retrospectively.
88
89## CHECK-START: boolean Main2.ValuesOrdered(int, int, int) select_generator (before)
90## CHECK-DAG:     <<ParamX:i\d+>>   ParameterValue
91## CHECK-DAG:     <<ParamY:i\d+>>   ParameterValue
92## CHECK-DAG:     <<ParamZ:i\d+>>   ParameterValue
93## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
94## CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
95## CHECK-DAG:     <<CondXY:z\d+>>   GreaterThan [<<ParamX>>,<<ParamY>>]
96## CHECK-DAG:                       If [<<CondXY>>]
97## CHECK-DAG:     <<CondYZ:z\d+>>   GreaterThan [<<ParamY>>,<<ParamZ>>]
98## CHECK-DAG:                       If [<<CondYZ>>]
99## CHECK-DAG:     <<CondXYZ:z\d+>>  NotEqual [<<PhiXY:i\d+>>,<<PhiYZ:i\d+>>]
100## CHECK-DAG:                       If [<<CondXYZ>>]
101## CHECK-DAG:                       Return [<<PhiXYZ:i\d+>>]
102## CHECK-DAG:     <<PhiXY>>         Phi [<<Const1>>,<<Const0>>]
103## CHECK-DAG:     <<PhiYZ>>         Phi [<<Const1>>,<<Const0>>]
104## CHECK-DAG:     <<PhiXYZ>>        Phi [<<Const1>>,<<Const0>>]
105
106## CHECK-START: boolean Main2.ValuesOrdered(int, int, int) select_generator (after)
107## CHECK-DAG:     <<ParamX:i\d+>>   ParameterValue
108## CHECK-DAG:     <<ParamY:i\d+>>   ParameterValue
109## CHECK-DAG:     <<ParamZ:i\d+>>   ParameterValue
110## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
111## CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
112## CHECK-DAG:     <<CmpXY:z\d+>>    GreaterThan [<<ParamX>>,<<ParamY>>]
113## CHECK-DAG:     <<SelXY:i\d+>>    Select [<<Const1>>,<<Const0>>,<<CmpXY>>]
114## CHECK-DAG:     <<CmpYZ:z\d+>>    GreaterThan [<<ParamY>>,<<ParamZ>>]
115## CHECK-DAG:     <<SelYZ:i\d+>>    Select [<<Const1>>,<<Const0>>,<<CmpYZ>>]
116## CHECK-DAG:     <<CmpXYZ:z\d+>>   NotEqual [<<SelXY>>,<<SelYZ>>]
117## CHECK-DAG:     <<SelXYZ:i\d+>>   Select [<<Const1>>,<<Const0>>,<<CmpXYZ>>]
118## CHECK-DAG:                       Return [<<SelXYZ>>]
119
120# The original java source of this method:
121#
122#     return (x <= y) == (y <= z);
123#
124.method public static ValuesOrdered(III)Z
125    .registers 7
126    .param p0, "x"    # I
127    .param p1, "y"    # I
128    .param p2, "z"    # I
129
130    .prologue
131    const/4 v0, 0x1
132
133    const/4 v1, 0x0
134
135    .line 166
136    if-gt p0, p1, :cond_b
137
138    move v3, v0
139
140    :goto_5
141    if-gt p1, p2, :cond_d
142
143    move v2, v0
144
145    :goto_8
146    if-ne v3, v2, :cond_f
147
148    :goto_a
149    return v0
150
151    :cond_b
152    move v3, v1
153
154    goto :goto_5
155
156    :cond_d
157    move v2, v1
158
159    goto :goto_8
160
161    :cond_f
162    move v0, v1
163
164    goto :goto_a
165.end method
166
167## CHECK-START: int Main2.NegatedCondition(boolean) select_generator (before)
168## CHECK-DAG:     <<Param:z\d+>>    ParameterValue
169## CHECK-DAG:     <<Const42:i\d+>>  IntConstant 42
170## CHECK-DAG:     <<Const43:i\d+>>  IntConstant 43
171## CHECK-DAG:                       If [<<Param>>]
172## CHECK-DAG:     <<Phi:i\d+>>      Phi [<<Const42>>,<<Const43>>]
173## CHECK-DAG:                       Return [<<Phi>>]
174
175## CHECK-START: int Main2.NegatedCondition(boolean) select_generator (after)
176## CHECK-DAG:     <<Param:z\d+>>    ParameterValue
177## CHECK-DAG:     <<Const42:i\d+>>  IntConstant 42
178## CHECK-DAG:     <<Const43:i\d+>>  IntConstant 43
179## CHECK-DAG:     <<Select:i\d+>>   Select [<<Const43>>,<<Const42>>,<<Param>>]
180## CHECK-DAG:                       Return [<<Select>>]
181
182## CHECK-START: int Main2.NegatedCondition(boolean) select_generator (after)
183## CHECK-NOT:                       BooleanNot
184
185# The original java source of this method:
186#
187#     if (x != false) {
188#       return 42;
189#     } else {
190#       return 43;
191#     }
192#
193.method public static NegatedCondition(Z)I
194    .registers 2
195    .param p0, "x"    # Z
196
197    .prologue
198    .line 188
199    if-eqz p0, :cond_5
200
201    .line 189
202    const/16 v0, 0x2a
203
204    .line 191
205    :goto_4
206    return v0
207
208    :cond_5
209    const/16 v0, 0x2b
210
211    goto :goto_4
212.end method
213
214## CHECK-START: int Main2.MultiplePhis() select_generator (before)
215## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
216## CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
217## CHECK-DAG:     <<Const13:i\d+>>  IntConstant 13
218## CHECK-DAG:     <<Const42:i\d+>>  IntConstant 42
219## CHECK-DAG:     <<PhiX:i\d+>>     Phi [<<Const0>>,<<Const13>>,<<Const42>>]
220## CHECK-DAG:     <<PhiY:i\d+>>     Phi [<<Const1>>,<<Add:i\d+>>,<<Add>>]
221## CHECK-DAG:     <<Add>>           Add [<<PhiY>>,<<Const1>>]
222## CHECK-DAG:     <<Cond:z\d+>>     LessThanOrEqual [<<Add>>,<<Const1>>]
223## CHECK-DAG:                       If [<<Cond>>]
224## CHECK-DAG:                       Return [<<PhiX>>]
225
226## CHECK-START: int Main2.MultiplePhis() select_generator (after)
227## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
228## CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
229## CHECK-DAG:     <<Const13:i\d+>>  IntConstant 13
230## CHECK-DAG:     <<Const42:i\d+>>  IntConstant 42
231## CHECK-DAG:     <<PhiX:i\d+>>     Phi [<<Const0>>,<<Select:i\d+>>]
232## CHECK-DAG:     <<PhiY:i\d+>>     Phi [<<Const1>>,<<Add:i\d+>>]
233## CHECK-DAG:     <<Add>>           Add [<<PhiY>>,<<Const1>>]
234## CHECK-DAG:     <<Cond:z\d+>>     LessThanOrEqual [<<Add>>,<<Const1>>]
235## CHECK-DAG:     <<Select>>        Select [<<Const13>>,<<Const42>>,<<Cond>>]
236## CHECK-DAG:                       Return [<<PhiX>>]
237
238# The original java source of this method:
239#
240#     int x = 0;
241#     int y = 1;
242#     while (y++ < 10) {
243#       if (y > 1) {
244#         x = 13;
245#       } else {
246#         x = 42;
247#       }
248#     }
249#     return x;
250#
251.method public static MultiplePhis()I
252    .registers 4
253
254    .prologue
255    .line 290
256    const/4 v0, 0x0
257
258    .line 291
259    .local v0, "x":I
260    const/4 v1, 0x1
261
262    .local v1, "y":I
263    move v2, v1
264
265    .line 292
266    .end local v1    # "y":I
267    .local v2, "y":I
268    :goto_3
269    add-int/lit8 v1, v2, 0x1
270
271    .end local v2    # "y":I
272    .restart local v1    # "y":I
273    const/16 v3, 0xa
274
275    if-ge v2, v3, :cond_14
276
277    .line 293
278    const/4 v3, 0x1
279
280    if-le v1, v3, :cond_10
281
282    .line 294
283    const/16 v0, 0xd
284
285    move v2, v1
286
287    .end local v1    # "y":I
288    .restart local v2    # "y":I
289    goto :goto_3
290
291    .line 296
292    .end local v2    # "y":I
293    .restart local v1    # "y":I
294    :cond_10
295    const/16 v0, 0x2a
296
297    move v2, v1
298
299    .end local v1    # "y":I
300    .restart local v2    # "y":I
301    goto :goto_3
302
303    .line 299
304    .end local v2    # "y":I
305    .restart local v1    # "y":I
306    :cond_14
307    return v0
308.end method
309