1# Copyright (C) 2015 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 LTestCmp;
16
17.super Ljava/lang/Object;
18
19
20## CHECK-START: int TestCmp.$opt$CmpLongConstants() constant_folding (before)
21## CHECK-DAG:     <<Const13:j\d+>>  LongConstant 13
22## CHECK-DAG:     <<Const7:j\d+>>   LongConstant 7
23## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const13>>,<<Const7>>]
24## CHECK-DAG:                       Return [<<Cmp>>]
25
26## CHECK-START: int TestCmp.$opt$CmpLongConstants() constant_folding (after)
27## CHECK-DAG:                       LongConstant 13
28## CHECK-DAG:                       LongConstant 7
29## CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
30## CHECK-DAG:                       Return [<<Const1>>]
31
32## CHECK-START: int TestCmp.$opt$CmpLongConstants() constant_folding (after)
33## CHECK-NOT:                       Compare
34
35.method public static $opt$CmpLongConstants()I
36   .registers 5
37   const-wide v1, 13
38   const-wide v3, 7
39   cmp-long v0, v1, v3
40   return v0
41.end method
42
43## CHECK-START: int TestCmp.$opt$CmpGtFloatConstants() constant_folding (before)
44## CHECK-DAG:     <<Const11:f\d+>>  FloatConstant 11
45## CHECK-DAG:     <<Const22:f\d+>>  FloatConstant 22
46## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const11>>,<<Const22>>] bias:gt
47## CHECK-DAG:                       Return [<<Cmp>>]
48
49## CHECK-START: int TestCmp.$opt$CmpGtFloatConstants() constant_folding (after)
50## CHECK-DAG:                       FloatConstant 11
51## CHECK-DAG:                       FloatConstant 22
52## CHECK-DAG:     <<ConstM1:i\d+>>  IntConstant -1
53## CHECK-DAG:                       Return [<<ConstM1>>]
54
55## CHECK-START: int TestCmp.$opt$CmpGtFloatConstants() constant_folding (after)
56## CHECK-NOT:                       Compare
57
58.method public static $opt$CmpGtFloatConstants()I
59   .registers 3
60   const v1, 11.f
61   const v2, 22.f
62   cmpg-float v0, v1, v2
63   return v0
64.end method
65
66## CHECK-START: int TestCmp.$opt$CmpLtFloatConstants() constant_folding (before)
67## CHECK-DAG:     <<Const33:f\d+>>  FloatConstant 33
68## CHECK-DAG:     <<Const44:f\d+>>  FloatConstant 44
69## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const33>>,<<Const44>>] bias:lt
70## CHECK-DAG:                       Return [<<Cmp>>]
71
72## CHECK-START: int TestCmp.$opt$CmpLtFloatConstants() constant_folding (after)
73## CHECK-DAG:                       FloatConstant 33
74## CHECK-DAG:                       FloatConstant 44
75## CHECK-DAG:     <<ConstM1:i\d+>>  IntConstant -1
76## CHECK-DAG:                       Return [<<ConstM1>>]
77
78## CHECK-START: int TestCmp.$opt$CmpLtFloatConstants() constant_folding (after)
79## CHECK-NOT:                       Compare
80
81.method public static $opt$CmpLtFloatConstants()I
82   .registers 3
83   const v1, 33.f
84   const v2, 44.f
85   cmpl-float v0, v1, v2
86   return v0
87.end method
88
89## CHECK-START: int TestCmp.$opt$CmpGtDoubleConstants() constant_folding (before)
90## CHECK-DAG:     <<Const55:d\d+>>  DoubleConstant 55
91## CHECK-DAG:     <<Const66:d\d+>>  DoubleConstant 66
92## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const55>>,<<Const66>>] bias:gt
93## CHECK-DAG:                       Return [<<Cmp>>]
94
95## CHECK-START: int TestCmp.$opt$CmpGtDoubleConstants() constant_folding (after)
96## CHECK-DAG:                       DoubleConstant 55
97## CHECK-DAG:                       DoubleConstant 66
98## CHECK-DAG:     <<ConstM1:i\d+>>  IntConstant -1
99## CHECK-DAG:                       Return [<<ConstM1>>]
100
101## CHECK-START: int TestCmp.$opt$CmpGtDoubleConstants() constant_folding (after)
102## CHECK-NOT:                       Compare
103
104.method public static $opt$CmpGtDoubleConstants()I
105   .registers 5
106   const-wide v1, 55.
107   const-wide v3, 66.
108   cmpg-double v0, v1, v3
109   return v0
110.end method
111
112## CHECK-START: int TestCmp.$opt$CmpLtDoubleConstants() constant_folding (before)
113## CHECK-DAG:     <<Const77:d\d+>>  DoubleConstant 77
114## CHECK-DAG:     <<Const88:d\d+>>  DoubleConstant 88
115## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const77>>,<<Const88>>] bias:lt
116## CHECK-DAG:                       Return [<<Cmp>>]
117
118## CHECK-START: int TestCmp.$opt$CmpLtDoubleConstants() constant_folding (after)
119## CHECK-DAG:                       DoubleConstant 77
120## CHECK-DAG:                       DoubleConstant 88
121## CHECK-DAG:     <<ConstM1:i\d+>>  IntConstant -1
122## CHECK-DAG:                       Return [<<ConstM1>>]
123
124## CHECK-START: int TestCmp.$opt$CmpLtDoubleConstants() constant_folding (after)
125## CHECK-NOT:                       Compare
126
127.method public static $opt$CmpLtDoubleConstants()I
128   .registers 5
129   const-wide v1, 77.
130   const-wide v3, 88.
131   cmpl-double v0, v1, v3
132   return v0
133.end method
134
135
136## CHECK-START: int TestCmp.$opt$CmpLongSameConstant() constant_folding (before)
137## CHECK-DAG:     <<Const100:j\d+>> LongConstant 100
138## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const100>>,<<Const100>>]
139## CHECK-DAG:                       Return [<<Cmp>>]
140
141## CHECK-START: int TestCmp.$opt$CmpLongSameConstant() constant_folding (after)
142## CHECK-DAG:                       LongConstant 100
143## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
144## CHECK-DAG:                       Return [<<Const0>>]
145
146## CHECK-START: int TestCmp.$opt$CmpLongSameConstant() constant_folding (after)
147## CHECK-NOT:                       Compare
148
149.method public static $opt$CmpLongSameConstant()I
150   .registers 5
151   const-wide v1, 100
152   const-wide v3, 100
153   cmp-long v0, v1, v3
154   return v0
155.end method
156
157## CHECK-START: int TestCmp.$opt$CmpGtFloatSameConstant() constant_folding (before)
158## CHECK-DAG:     <<Const200:f\d+>> FloatConstant 200
159## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const200>>,<<Const200>>] bias:gt
160## CHECK-DAG:                       Return [<<Cmp>>]
161
162## CHECK-START: int TestCmp.$opt$CmpGtFloatSameConstant() constant_folding (after)
163## CHECK-DAG:                       FloatConstant 200
164## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
165## CHECK-DAG:                       Return [<<Const0>>]
166
167## CHECK-START: int TestCmp.$opt$CmpGtFloatSameConstant() constant_folding (after)
168## CHECK-NOT:                       Compare
169
170.method public static $opt$CmpGtFloatSameConstant()I
171   .registers 3
172   const v1, 200.f
173   const v2, 200.f
174   cmpg-float v0, v1, v2
175   return v0
176.end method
177
178## CHECK-START: int TestCmp.$opt$CmpLtFloatSameConstant() constant_folding (before)
179## CHECK-DAG:     <<Const300:f\d+>> FloatConstant 300
180## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const300>>,<<Const300>>] bias:lt
181## CHECK-DAG:                       Return [<<Cmp>>]
182
183## CHECK-START: int TestCmp.$opt$CmpLtFloatSameConstant() constant_folding (after)
184## CHECK-DAG:                       FloatConstant 300
185## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
186## CHECK-DAG:                       Return [<<Const0>>]
187
188## CHECK-START: int TestCmp.$opt$CmpLtFloatSameConstant() constant_folding (after)
189## CHECK-NOT:                       Compare
190
191.method public static $opt$CmpLtFloatSameConstant()I
192   .registers 3
193   const v1, 300.f
194   const v2, 300.f
195   cmpl-float v0, v1, v2
196   return v0
197.end method
198
199## CHECK-START: int TestCmp.$opt$CmpGtDoubleSameConstant() constant_folding (before)
200## CHECK-DAG:     <<Const400:d\d+>> DoubleConstant 400
201## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const400>>,<<Const400>>] bias:gt
202## CHECK-DAG:                       Return [<<Cmp>>]
203
204## CHECK-START: int TestCmp.$opt$CmpGtDoubleSameConstant() constant_folding (after)
205## CHECK-DAG:                       DoubleConstant 400
206## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
207## CHECK-DAG:                       Return [<<Const0>>]
208
209## CHECK-START: int TestCmp.$opt$CmpGtDoubleSameConstant() constant_folding (after)
210## CHECK-NOT:                       Compare
211
212.method public static $opt$CmpGtDoubleSameConstant()I
213   .registers 5
214   const-wide v1, 400.
215   const-wide v3, 400.
216   cmpg-double v0, v1, v3
217   return v0
218.end method
219
220## CHECK-START: int TestCmp.$opt$CmpLtDoubleSameConstant() constant_folding (before)
221## CHECK-DAG:     <<Const500:d\d+>> DoubleConstant 500
222## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const500>>,<<Const500>>] bias:lt
223## CHECK-DAG:                       Return [<<Cmp>>]
224
225## CHECK-START: int TestCmp.$opt$CmpLtDoubleSameConstant() constant_folding (after)
226## CHECK-DAG:                       DoubleConstant 500
227## CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
228## CHECK-DAG:                       Return [<<Const0>>]
229
230## CHECK-START: int TestCmp.$opt$CmpLtDoubleSameConstant() constant_folding (after)
231## CHECK-NOT:                       Compare
232
233.method public static $opt$CmpLtDoubleSameConstant()I
234   .registers 5
235   const-wide v1, 500.
236   const-wide v3, 500.
237   cmpl-double v0, v1, v3
238   return v0
239.end method
240
241
242## CHECK-START: int TestCmp.$opt$CmpGtFloatConstantWithNaN() constant_folding (before)
243## CHECK-DAG:     <<Const44:f\d+>>  FloatConstant 44
244## CHECK-DAG:     <<ConstNan:f\d+>> FloatConstant nan
245## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const44>>,<<ConstNan>>] bias:gt
246## CHECK-DAG:                       Return [<<Cmp>>]
247
248## CHECK-START: int TestCmp.$opt$CmpGtFloatConstantWithNaN() constant_folding (after)
249## CHECK-DAG:                       FloatConstant 44
250## CHECK-DAG:                       FloatConstant nan
251## CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
252## CHECK-DAG:                       Return [<<Const1>>]
253
254## CHECK-START: int TestCmp.$opt$CmpGtFloatConstantWithNaN() constant_folding (after)
255## CHECK-NOT:                       Compare
256
257.method public static $opt$CmpGtFloatConstantWithNaN()I
258   .registers 3
259   const v1, 44.f
260   const v2, NaNf
261   cmpg-float v0, v1, v2
262   return v0
263.end method
264
265## CHECK-START: int TestCmp.$opt$CmpLtFloatConstantWithNaN() constant_folding (before)
266## CHECK-DAG:     <<Const44:f\d+>>  FloatConstant 44
267## CHECK-DAG:     <<ConstNan:f\d+>> FloatConstant nan
268## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const44>>,<<ConstNan>>] bias:lt
269## CHECK-DAG:                       Return [<<Cmp>>]
270
271## CHECK-START: int TestCmp.$opt$CmpLtFloatConstantWithNaN() constant_folding (after)
272## CHECK-DAG:                       FloatConstant 44
273## CHECK-DAG:                       FloatConstant nan
274## CHECK-DAG:     <<ConstM1:i\d+>>  IntConstant -1
275## CHECK-DAG:                       Return [<<ConstM1>>]
276
277## CHECK-START: int TestCmp.$opt$CmpLtFloatConstantWithNaN() constant_folding (after)
278## CHECK-NOT:                       Compare
279
280.method public static $opt$CmpLtFloatConstantWithNaN()I
281   .registers 3
282   const v1, 44.f
283   const v2, NaNf
284   cmpl-float v0, v1, v2
285   return v0
286.end method
287
288## CHECK-START: int TestCmp.$opt$CmpGtDoubleConstantWithNaN() constant_folding (before)
289## CHECK-DAG:     <<Const45:d\d+>>  DoubleConstant 45
290## CHECK-DAG:     <<ConstNan:d\d+>> DoubleConstant nan
291## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const45>>,<<ConstNan>>] bias:gt
292## CHECK-DAG:                       Return [<<Cmp>>]
293
294## CHECK-START: int TestCmp.$opt$CmpGtDoubleConstantWithNaN() constant_folding (after)
295## CHECK-DAG:                       DoubleConstant 45
296## CHECK-DAG:                       DoubleConstant nan
297## CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
298## CHECK-DAG:                       Return [<<Const1>>]
299
300## CHECK-START: int TestCmp.$opt$CmpGtDoubleConstantWithNaN() constant_folding (after)
301## CHECK-NOT:                       Compare
302
303.method public static $opt$CmpGtDoubleConstantWithNaN()I
304   .registers 5
305   const-wide v1, 45.
306   const-wide v3, NaN
307   cmpg-double v0, v1, v3
308   return v0
309.end method
310
311## CHECK-START: int TestCmp.$opt$CmpLtDoubleConstantWithNaN() constant_folding (before)
312## CHECK-DAG:     <<Const46:d\d+>>  DoubleConstant 46
313## CHECK-DAG:     <<ConstNan:d\d+>> DoubleConstant nan
314## CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Const46>>,<<ConstNan>>] bias:lt
315## CHECK-DAG:                       Return [<<Cmp>>]
316
317## CHECK-START: int TestCmp.$opt$CmpLtDoubleConstantWithNaN() constant_folding (after)
318## CHECK-DAG:                       DoubleConstant 46
319## CHECK-DAG:                       DoubleConstant nan
320## CHECK-DAG:     <<ConstM1:i\d+>>  IntConstant -1
321## CHECK-DAG:                       Return [<<ConstM1>>]
322
323## CHECK-START: int TestCmp.$opt$CmpLtDoubleConstantWithNaN() constant_folding (after)
324## CHECK-NOT:                       Compare
325
326.method public static $opt$CmpLtDoubleConstantWithNaN()I
327   .registers 5
328   const-wide v1, 46.
329   const-wide v3, NaN
330   cmpl-double v0, v1, v3
331   return v0
332.end method
333
334
335##  CHECK-START: int TestCmp.IntAddition2() constant_folding (before)
336##  CHECK-DAG:     <<Const1:i\d+>>  IntConstant 1
337##  CHECK-DAG:     <<Const2:i\d+>>  IntConstant 2
338##  CHECK-DAG:     <<Const5:i\d+>>  IntConstant 5
339##  CHECK-DAG:     <<Const6:i\d+>>  IntConstant 6
340##  CHECK-DAG:     <<Add1:i\d+>>    Add [<<Const1>>,<<Const2>>]
341##  CHECK-DAG:     <<Add2:i\d+>>    Add [<<Const5>>,<<Const6>>]
342##  CHECK-DAG:     <<Add3:i\d+>>    Add [<<Add1>>,<<Add2>>]
343##  CHECK-DAG:                      Return [<<Add3>>]
344
345##  CHECK-START: int TestCmp.IntAddition2() constant_folding (after)
346##  CHECK-DAG:     <<Const14:i\d+>> IntConstant 14
347##  CHECK-DAG:                      Return [<<Const14>>]
348
349##  CHECK-START: int TestCmp.IntAddition2() constant_folding (after)
350##  CHECK-NOT:                      Add
351.method public static IntAddition2()I
352    # A more direct translation from Java.
353
354    # int a, b, c;
355    .registers 3
356
357    # a = 1;
358    const/4 v0, 1
359    # b = 2;
360    const/4 v1, 2
361
362    # a += b;
363    add-int/2addr v0, v1
364
365    # b = 5;
366    const/4 v1, 5
367    # c = 6;
368    const/4 v2, 6
369
370    # b += c;
371    add-int/2addr v1, v2
372    # c = a + b;
373    add-int v2, v0, v1
374
375    # return c;
376    return v2
377.end method
378
379
380##  CHECK-START: int TestCmp.IntAddition2AddAndMove() constant_folding (before)
381##  CHECK-DAG:     <<Const1:i\d+>>  IntConstant 1
382##  CHECK-DAG:     <<Const2:i\d+>>  IntConstant 2
383##  CHECK-DAG:     <<Const5:i\d+>>  IntConstant 5
384##  CHECK-DAG:     <<Const6:i\d+>>  IntConstant 6
385##  CHECK-DAG:     <<Add1:i\d+>>    Add [<<Const1>>,<<Const2>>]
386##  CHECK-DAG:     <<Add2:i\d+>>    Add [<<Const5>>,<<Const6>>]
387##  CHECK-DAG:     <<Add3:i\d+>>    Add [<<Add1>>,<<Add2>>]
388##  CHECK-DAG:                      Return [<<Add3>>]
389
390##  CHECK-START: int TestCmp.IntAddition2AddAndMove() constant_folding (after)
391##  CHECK-DAG:     <<Const14:i\d+>> IntConstant 14
392##  CHECK-DAG:                      Return [<<Const14>>]
393
394##  CHECK-START: int TestCmp.IntAddition2AddAndMove() constant_folding (after)
395##  CHECK-NOT:                      Add
396
397#   D8 uses 3 registers for += when local variable info is presented.
398.method public static IntAddition2AddAndMove()I
399    .registers 4
400
401    # a = 1;
402    const/4 v0, 1
403    # b = 2;
404    const/4 v1, 2
405
406    # a += b;
407    add-int v2, v0, v1
408    move v0, v2
409
410    # b = 5;
411    const/4 v2, 5
412    move v1, v2
413
414    # c = 6;
415    const/4 v2, 6
416
417    # b += c;
418    add-int v3, v1, v2
419    move v1, v3
420
421    # c = a + b;
422    add-int v3, v0, v1
423    move v2, v3
424
425    # return c;
426    return v2
427.end method
428
429
430## CHECK-START: int TestCmp.JumpsAndConditionals(boolean) constant_folding (before)
431## CHECK-DAG:     <<Const2:i\d+>>  IntConstant 2
432## CHECK-DAG:     <<Const5:i\d+>>  IntConstant 5
433## CHECK-DAG:     <<Add:i\d+>>     Add [<<Const5>>,<<Const2>>]
434## CHECK-DAG:     <<Sub:i\d+>>     Sub [<<Const5>>,<<Const2>>]
435## CHECK-DAG:     <<Phi:i\d+>>     Phi [<<Add>>,<<Sub>>]
436## CHECK-DAG:                      Return [<<Phi>>]
437
438## CHECK-START: int TestCmp.JumpsAndConditionals(boolean) constant_folding (after)
439## CHECK-DAG:     <<Const3:i\d+>>  IntConstant 3
440## CHECK-DAG:     <<Const7:i\d+>>  IntConstant 7
441## CHECK-DAG:     <<Phi:i\d+>>     Phi [<<Const7>>,<<Const3>>]
442## CHECK-DAG:                      Return [<<Phi>>]
443
444## CHECK-START: int TestCmp.JumpsAndConditionals(boolean) constant_folding (after)
445## CHECK-NOT:                      Add
446## CHECK-NOT:                      Sub
447.method public static JumpsAndConditionals(Z)I
448    # int a, b, c;
449    # a = 5;
450    # b = 2;
451    # if (cond)
452    #   c = a + b;
453    # else
454    #   c = a - b;
455    # return c;
456    .registers 4
457
458    const/4 v0, 5
459    const/4 v1, 2
460
461    if-eqz p0, :cond_7
462    add-int v2, v0, v1
463
464    :goto_6
465    return v2
466
467    :cond_7
468    sub-int v2, v0, v1
469    goto :goto_6
470.end method
471