1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import java.lang.reflect.Method;
18
19public class Main {
20
21  // Workaround for b/18051191.
22  class InnerClass {}
23
24  public static void assertFalse(boolean condition) {
25    if (condition) {
26      throw new Error();
27    }
28  }
29
30  public static void assertIntEquals(int expected, int result) {
31    if (expected != result) {
32      throw new Error("Expected: " + expected + ", found: " + result);
33    }
34  }
35
36  public static void assertLongEquals(long expected, long result) {
37    if (expected != result) {
38      throw new Error("Expected: " + expected + ", found: " + result);
39    }
40  }
41
42  public static void assertFloatEquals(float expected, float result) {
43    if (expected != result) {
44      throw new Error("Expected: " + expected + ", found: " + result);
45    }
46  }
47
48  public static void assertDoubleEquals(double expected, double result) {
49    if (expected != result) {
50      throw new Error("Expected: " + expected + ", found: " + result);
51    }
52  }
53
54
55  // Wrappers around methods located in file TestCmp.smali.
56
57  public int smaliCmpLongConstants() throws Exception {
58    Method m = testCmp.getMethod("$opt$CmpLongConstants");
59    return (Integer)m.invoke(null);
60  }
61  public int smaliCmpGtFloatConstants() throws Exception {
62    Method m = testCmp.getMethod("$opt$CmpGtFloatConstants");
63    return (Integer)m.invoke(null);
64  }
65  public int smaliCmpLtFloatConstants() throws Exception {
66    Method m = testCmp.getMethod("$opt$CmpLtFloatConstants");
67    return (Integer)m.invoke(null);
68  }
69  public int smaliCmpGtDoubleConstants() throws Exception {
70    Method m = testCmp.getMethod("$opt$CmpGtDoubleConstants");
71    return (Integer)m.invoke(null);
72  }
73  public int smaliCmpLtDoubleConstants() throws Exception {
74    Method m = testCmp.getMethod("$opt$CmpLtDoubleConstants");
75    return (Integer)m.invoke(null);
76  }
77
78  public int smaliCmpLongSameConstant() throws Exception {
79    Method m = testCmp.getMethod("$opt$CmpLongSameConstant");
80    return (Integer)m.invoke(null);
81  }
82  public int smaliCmpGtFloatSameConstant() throws Exception {
83    Method m = testCmp.getMethod("$opt$CmpGtFloatSameConstant");
84    return (Integer)m.invoke(null);
85  }
86  public int smaliCmpLtFloatSameConstant() throws Exception {
87    Method m = testCmp.getMethod("$opt$CmpLtFloatSameConstant");
88    return (Integer)m.invoke(null);
89  }
90  public int smaliCmpGtDoubleSameConstant() throws Exception {
91    Method m = testCmp.getMethod("$opt$CmpGtDoubleSameConstant");
92    return (Integer)m.invoke(null);
93  }
94  public int smaliCmpLtDoubleSameConstant() throws Exception {
95    Method m = testCmp.getMethod("$opt$CmpLtDoubleSameConstant");
96    return (Integer)m.invoke(null);
97  }
98
99  public int smaliCmpGtFloatConstantWithNaN() throws Exception {
100    Method m = testCmp.getMethod("$opt$CmpGtFloatConstantWithNaN");
101    return (Integer)m.invoke(null);
102  }
103  public int smaliCmpLtFloatConstantWithNaN() throws Exception {
104    Method m = testCmp.getMethod("$opt$CmpLtFloatConstantWithNaN");
105    return (Integer)m.invoke(null);
106  }
107  public int smaliCmpGtDoubleConstantWithNaN() throws Exception {
108    Method m = testCmp.getMethod("$opt$CmpGtDoubleConstantWithNaN");
109    return (Integer)m.invoke(null);
110  }
111  public int smaliCmpLtDoubleConstantWithNaN() throws Exception {
112    Method m = testCmp.getMethod("$opt$CmpLtDoubleConstantWithNaN");
113    return (Integer)m.invoke(null);
114  }
115
116  public static int smaliIntAddition2() throws Exception {
117    Method m = Class.forName("TestCmp").getMethod("IntAddition2");
118    return (Integer)m.invoke(null);
119  }
120  public static int smaliIntAddition2AddAndMove() throws Exception {
121    Method m = Class.forName("TestCmp").getMethod("IntAddition2AddAndMove");
122    return (Integer)m.invoke(null);
123  }
124  public static int smaliJumpsAndConditionals(boolean cond) throws Exception {
125    Method m = Class.forName("TestCmp").getMethod("JumpsAndConditionals", boolean.class);
126    return (Integer)m.invoke(null, cond);
127  }
128
129
130  /**
131   * Exercise constant folding on negation.
132   */
133
134  /// CHECK-START: int Main.IntNegation() constant_folding (before)
135  /// CHECK-DAG:     <<Const42:i\d+>>  IntConstant 42
136  /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Const42>>]
137  /// CHECK-DAG:                       Return [<<Neg>>]
138
139  /// CHECK-START: int Main.IntNegation() constant_folding (after)
140  /// CHECK-DAG:     <<ConstN42:i\d+>> IntConstant -42
141  /// CHECK-DAG:                       Return [<<ConstN42>>]
142
143  /// CHECK-START: int Main.IntNegation() constant_folding (after)
144  /// CHECK-NOT:                       Neg
145
146  public static int IntNegation() {
147    int x, y;
148    x = 42;
149    y = -x;
150    return y;
151  }
152
153  /// CHECK-START: long Main.LongNegation() constant_folding (before)
154  /// CHECK-DAG:     <<Const42:j\d+>>  LongConstant 42
155  /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Const42>>]
156  /// CHECK-DAG:                       Return [<<Neg>>]
157
158  /// CHECK-START: long Main.LongNegation() constant_folding (after)
159  /// CHECK-DAG:     <<ConstN42:j\d+>> LongConstant -42
160  /// CHECK-DAG:                       Return [<<ConstN42>>]
161
162  /// CHECK-START: long Main.LongNegation() constant_folding (after)
163  /// CHECK-NOT:                       Neg
164
165  public static long LongNegation() {
166    long x, y;
167    x = 42L;
168    y = -x;
169    return y;
170  }
171
172  /// CHECK-START: float Main.FloatNegation() constant_folding (before)
173  /// CHECK-DAG:     <<Const42:f\d+>>  FloatConstant 42
174  /// CHECK-DAG:     <<Neg:f\d+>>      Neg [<<Const42>>]
175  /// CHECK-DAG:                       Return [<<Neg>>]
176
177  /// CHECK-START: float Main.FloatNegation() constant_folding (after)
178  /// CHECK-DAG:     <<ConstN42:f\d+>> FloatConstant -42
179  /// CHECK-DAG:                       Return [<<ConstN42>>]
180
181  /// CHECK-START: float Main.FloatNegation() constant_folding (after)
182  /// CHECK-NOT:                       Neg
183
184  public static float FloatNegation() {
185    float x, y;
186    x = 42F;
187    y = -x;
188    return y;
189  }
190
191  /// CHECK-START: double Main.DoubleNegation() constant_folding (before)
192  /// CHECK-DAG:     <<Const42:d\d+>>  DoubleConstant 42
193  /// CHECK-DAG:     <<Neg:d\d+>>      Neg [<<Const42>>]
194  /// CHECK-DAG:                       Return [<<Neg>>]
195
196  /// CHECK-START: double Main.DoubleNegation() constant_folding (after)
197  /// CHECK-DAG:     <<ConstN42:d\d+>> DoubleConstant -42
198  /// CHECK-DAG:                       Return [<<ConstN42>>]
199
200  /// CHECK-START: double Main.DoubleNegation() constant_folding (after)
201  /// CHECK-NOT:                       Neg
202
203  public static double DoubleNegation() {
204    double x, y;
205    x = 42D;
206    y = -x;
207    return y;
208  }
209
210
211  /**
212   * Exercise constant folding on addition.
213   */
214
215  /// CHECK-START: int Main.IntAddition1() constant_folding (before)
216  /// CHECK-DAG:     <<Const1:i\d+>>  IntConstant 1
217  /// CHECK-DAG:     <<Const2:i\d+>>  IntConstant 2
218  /// CHECK-DAG:     <<Add:i\d+>>     Add [<<Const1>>,<<Const2>>]
219  /// CHECK-DAG:                      Return [<<Add>>]
220
221  /// CHECK-START: int Main.IntAddition1() constant_folding (after)
222  /// CHECK-DAG:     <<Const3:i\d+>>  IntConstant 3
223  /// CHECK-DAG:                      Return [<<Const3>>]
224
225  /// CHECK-START: int Main.IntAddition1() constant_folding (after)
226  /// CHECK-NOT:                      Add
227
228  public static int IntAddition1() {
229    int a, b, c;
230    a = 1;
231    b = 2;
232    c = a + b;
233    return c;
234  }
235
236  /// CHECK-START: int Main.IntAddition2() constant_folding (before)
237  /// CHECK-DAG:     <<Const1:i\d+>>  IntConstant 1
238  /// CHECK-DAG:     <<Const2:i\d+>>  IntConstant 2
239  /// CHECK-DAG:     <<Const5:i\d+>>  IntConstant 5
240  /// CHECK-DAG:     <<Const6:i\d+>>  IntConstant 6
241  /// CHECK-DAG:     <<Add1:i\d+>>    Add [<<Const1>>,<<Const2>>]
242  /// CHECK-DAG:                      Add [<<Const5>>,<<Const6>>]
243
244  /// CHECK-START: int Main.IntAddition2() constant_folding (after)
245  /// CHECK-DAG:     <<Const14:i\d+>> IntConstant 14
246  /// CHECK-DAG:                      Return [<<Const14>>]
247
248  /// CHECK-START: int Main.IntAddition2() constant_folding (after)
249  /// CHECK-NOT:                      Add
250
251  public static int IntAddition2() {
252    int a, b, c;
253    a = 1;
254    b = 2;
255    a += b;
256    b = 5;
257    c = 6;
258    b += c;
259    c = a + b;
260    return c;
261  }
262
263  /// CHECK-START: long Main.LongAddition() constant_folding (before)
264  /// CHECK-DAG:     <<Const1:j\d+>>  LongConstant 1
265  /// CHECK-DAG:     <<Const2:j\d+>>  LongConstant 2
266  /// CHECK-DAG:     <<Add:j\d+>>     Add [<<Const1>>,<<Const2>>]
267  /// CHECK-DAG:                      Return [<<Add>>]
268
269  /// CHECK-START: long Main.LongAddition() constant_folding (after)
270  /// CHECK-DAG:     <<Const3:j\d+>>  LongConstant 3
271  /// CHECK-DAG:                      Return [<<Const3>>]
272
273  /// CHECK-START: long Main.LongAddition() constant_folding (after)
274  /// CHECK-NOT:                      Add
275
276  public static long LongAddition() {
277    long a, b, c;
278    a = 1L;
279    b = 2L;
280    c = a + b;
281    return c;
282  }
283
284  /// CHECK-START: float Main.FloatAddition() constant_folding (before)
285  /// CHECK-DAG:     <<Const1:f\d+>>  FloatConstant 1
286  /// CHECK-DAG:     <<Const2:f\d+>>  FloatConstant 2
287  /// CHECK-DAG:     <<Add:f\d+>>     Add [<<Const1>>,<<Const2>>]
288  /// CHECK-DAG:                      Return [<<Add>>]
289
290  /// CHECK-START: float Main.FloatAddition() constant_folding (after)
291  /// CHECK-DAG:     <<Const3:f\d+>>  FloatConstant 3
292  /// CHECK-DAG:                      Return [<<Const3>>]
293
294  /// CHECK-START: float Main.FloatAddition() constant_folding (after)
295  /// CHECK-NOT:                      Add
296
297  public static float FloatAddition() {
298    float a, b, c;
299    a = 1F;
300    b = 2F;
301    c = a + b;
302    return c;
303  }
304
305  /// CHECK-START: double Main.DoubleAddition() constant_folding (before)
306  /// CHECK-DAG:     <<Const1:d\d+>>  DoubleConstant 1
307  /// CHECK-DAG:     <<Const2:d\d+>>  DoubleConstant 2
308  /// CHECK-DAG:     <<Add:d\d+>>     Add [<<Const1>>,<<Const2>>]
309  /// CHECK-DAG:                      Return [<<Add>>]
310
311  /// CHECK-START: double Main.DoubleAddition() constant_folding (after)
312  /// CHECK-DAG:     <<Const3:d\d+>>  DoubleConstant 3
313  /// CHECK-DAG:                      Return [<<Const3>>]
314
315  /// CHECK-START: double Main.DoubleAddition() constant_folding (after)
316  /// CHECK-NOT:                      Add
317
318  public static double DoubleAddition() {
319    double a, b, c;
320    a = 1D;
321    b = 2D;
322    c = a + b;
323    return c;
324  }
325
326
327  /**
328   * Exercise constant folding on subtraction.
329   */
330
331  /// CHECK-START: int Main.IntSubtraction() constant_folding (before)
332  /// CHECK-DAG:     <<Const6:i\d+>>  IntConstant 6
333  /// CHECK-DAG:     <<Const2:i\d+>>  IntConstant 2
334  /// CHECK-DAG:     <<Sub:i\d+>>     Sub [<<Const6>>,<<Const2>>]
335  /// CHECK-DAG:                      Return [<<Sub>>]
336
337  /// CHECK-START: int Main.IntSubtraction() constant_folding (after)
338  /// CHECK-DAG:     <<Const4:i\d+>>  IntConstant 4
339  /// CHECK-DAG:                      Return [<<Const4>>]
340
341  /// CHECK-START: int Main.IntSubtraction() constant_folding (after)
342  /// CHECK-NOT:                      Sub
343
344  public static int IntSubtraction() {
345    int a, b, c;
346    a = 6;
347    b = 2;
348    c = a - b;
349    return c;
350  }
351
352  /// CHECK-START: long Main.LongSubtraction() constant_folding (before)
353  /// CHECK-DAG:     <<Const6:j\d+>>  LongConstant 6
354  /// CHECK-DAG:     <<Const2:j\d+>>  LongConstant 2
355  /// CHECK-DAG:     <<Sub:j\d+>>     Sub [<<Const6>>,<<Const2>>]
356  /// CHECK-DAG:                      Return [<<Sub>>]
357
358  /// CHECK-START: long Main.LongSubtraction() constant_folding (after)
359  /// CHECK-DAG:     <<Const4:j\d+>>  LongConstant 4
360  /// CHECK-DAG:                      Return [<<Const4>>]
361
362  /// CHECK-START: long Main.LongSubtraction() constant_folding (after)
363  /// CHECK-NOT:                      Sub
364
365  public static long LongSubtraction() {
366    long a, b, c;
367    a = 6L;
368    b = 2L;
369    c = a - b;
370    return c;
371  }
372
373  /// CHECK-START: float Main.FloatSubtraction() constant_folding (before)
374  /// CHECK-DAG:     <<Const6:f\d+>>  FloatConstant 6
375  /// CHECK-DAG:     <<Const2:f\d+>>  FloatConstant 2
376  /// CHECK-DAG:     <<Sub:f\d+>>     Sub [<<Const6>>,<<Const2>>]
377  /// CHECK-DAG:                      Return [<<Sub>>]
378
379  /// CHECK-START: float Main.FloatSubtraction() constant_folding (after)
380  /// CHECK-DAG:     <<Const4:f\d+>>  FloatConstant 4
381  /// CHECK-DAG:                      Return [<<Const4>>]
382
383  /// CHECK-START: float Main.FloatSubtraction() constant_folding (after)
384  /// CHECK-NOT:                      Sub
385
386  public static float FloatSubtraction() {
387    float a, b, c;
388    a = 6F;
389    b = 2F;
390    c = a - b;
391    return c;
392  }
393
394  /// CHECK-START: double Main.DoubleSubtraction() constant_folding (before)
395  /// CHECK-DAG:     <<Const6:d\d+>>  DoubleConstant 6
396  /// CHECK-DAG:     <<Const2:d\d+>>  DoubleConstant 2
397  /// CHECK-DAG:     <<Sub:d\d+>>     Sub [<<Const6>>,<<Const2>>]
398  /// CHECK-DAG:                      Return [<<Sub>>]
399
400  /// CHECK-START: double Main.DoubleSubtraction() constant_folding (after)
401  /// CHECK-DAG:     <<Const4:d\d+>>  DoubleConstant 4
402  /// CHECK-DAG:                      Return [<<Const4>>]
403
404  /// CHECK-START: double Main.DoubleSubtraction() constant_folding (after)
405  /// CHECK-NOT:                      Sub
406
407  public static double DoubleSubtraction() {
408    double a, b, c;
409    a = 6D;
410    b = 2D;
411    c = a - b;
412    return c;
413  }
414
415
416  /**
417   * Exercise constant folding on multiplication.
418   */
419
420  /// CHECK-START: int Main.IntMultiplication() constant_folding (before)
421  /// CHECK-DAG:     <<Const7:i\d+>>  IntConstant 7
422  /// CHECK-DAG:     <<Const3:i\d+>>  IntConstant 3
423  /// CHECK-DAG:     <<Mul:i\d+>>     Mul [<<Const7>>,<<Const3>>]
424  /// CHECK-DAG:                      Return [<<Mul>>]
425
426  /// CHECK-START: int Main.IntMultiplication() constant_folding (after)
427  /// CHECK-DAG:     <<Const21:i\d+>> IntConstant 21
428  /// CHECK-DAG:                      Return [<<Const21>>]
429
430  /// CHECK-START: int Main.IntMultiplication() constant_folding (after)
431  /// CHECK-NOT:                      Mul
432
433  public static int IntMultiplication() {
434    int a, b, c;
435    a = 7;
436    b = 3;
437    c = a * b;
438    return c;
439  }
440
441  /// CHECK-START: long Main.LongMultiplication() constant_folding (before)
442  /// CHECK-DAG:     <<Const7:j\d+>>  LongConstant 7
443  /// CHECK-DAG:     <<Const3:j\d+>>  LongConstant 3
444  /// CHECK-DAG:     <<Mul:j\d+>>     Mul [<<Const7>>,<<Const3>>]
445  /// CHECK-DAG:                      Return [<<Mul>>]
446
447  /// CHECK-START: long Main.LongMultiplication() constant_folding (after)
448  /// CHECK-DAG:     <<Const21:j\d+>> LongConstant 21
449  /// CHECK-DAG:                      Return [<<Const21>>]
450
451  /// CHECK-START: long Main.LongMultiplication() constant_folding (after)
452  /// CHECK-NOT:                      Mul
453
454  public static long LongMultiplication() {
455    long a, b, c;
456    a = 7L;
457    b = 3L;
458    c = a * b;
459    return c;
460  }
461
462  /// CHECK-START: float Main.FloatMultiplication() constant_folding (before)
463  /// CHECK-DAG:     <<Const7:f\d+>>  FloatConstant 7
464  /// CHECK-DAG:     <<Const3:f\d+>>  FloatConstant 3
465  /// CHECK-DAG:     <<Mul:f\d+>>     Mul [<<Const7>>,<<Const3>>]
466  /// CHECK-DAG:                      Return [<<Mul>>]
467
468  /// CHECK-START: float Main.FloatMultiplication() constant_folding (after)
469  /// CHECK-DAG:     <<Const21:f\d+>> FloatConstant 21
470  /// CHECK-DAG:                      Return [<<Const21>>]
471
472  /// CHECK-START: float Main.FloatMultiplication() constant_folding (after)
473  /// CHECK-NOT:                      Mul
474
475  public static float FloatMultiplication() {
476    float a, b, c;
477    a = 7F;
478    b = 3F;
479    c = a * b;
480    return c;
481  }
482
483  /// CHECK-START: double Main.DoubleMultiplication() constant_folding (before)
484  /// CHECK-DAG:     <<Const7:d\d+>>  DoubleConstant 7
485  /// CHECK-DAG:     <<Const3:d\d+>>  DoubleConstant 3
486  /// CHECK-DAG:     <<Mul:d\d+>>     Mul [<<Const7>>,<<Const3>>]
487  /// CHECK-DAG:                      Return [<<Mul>>]
488
489  /// CHECK-START: double Main.DoubleMultiplication() constant_folding (after)
490  /// CHECK-DAG:     <<Const21:d\d+>> DoubleConstant 21
491  /// CHECK-DAG:                      Return [<<Const21>>]
492
493  /// CHECK-START: double Main.DoubleMultiplication() constant_folding (after)
494  /// CHECK-NOT:                      Mul
495
496  public static double DoubleMultiplication() {
497    double a, b, c;
498    a = 7D;
499    b = 3D;
500    c = a * b;
501    return c;
502  }
503
504
505  /**
506   * Exercise constant folding on division.
507   */
508
509  /// CHECK-START: int Main.IntDivision() constant_folding (before)
510  /// CHECK-DAG:     <<Const8:i\d+>>   IntConstant 8
511  /// CHECK-DAG:     <<Const3:i\d+>>   IntConstant 3
512  /// CHECK-DAG:     <<Div0Chk:i\d+>>  DivZeroCheck [<<Const3>>]
513  /// CHECK-DAG:     <<Div:i\d+>>      Div [<<Const8>>,<<Div0Chk>>]
514  /// CHECK-DAG:                       Return [<<Div>>]
515
516  /// CHECK-START: int Main.IntDivision() constant_folding (after)
517  /// CHECK-DAG:     <<Const2:i\d+>>   IntConstant 2
518  /// CHECK-DAG:                       Return [<<Const2>>]
519
520  /// CHECK-START: int Main.IntDivision() constant_folding (after)
521  /// CHECK-NOT:                       DivZeroCheck
522  /// CHECK-NOT:                       Div
523
524  public static int IntDivision() {
525    int a, b, c;
526    a = 8;
527    b = 3;
528    c = a / b;
529    return c;
530  }
531
532  /// CHECK-START: long Main.LongDivision() constant_folding (before)
533  /// CHECK-DAG:     <<Const8:j\d+>>   LongConstant 8
534  /// CHECK-DAG:     <<Const3:j\d+>>   LongConstant 3
535  /// CHECK-DAG:     <<Div0Chk:j\d+>>  DivZeroCheck [<<Const3>>]
536  /// CHECK-DAG:     <<Div:j\d+>>      Div [<<Const8>>,<<Div0Chk>>]
537  /// CHECK-DAG:                       Return [<<Div>>]
538
539  /// CHECK-START: long Main.LongDivision() constant_folding (after)
540  /// CHECK-DAG:     <<Const2:j\d+>>   LongConstant 2
541  /// CHECK-DAG:                       Return [<<Const2>>]
542
543  /// CHECK-START: long Main.LongDivision() constant_folding (after)
544  /// CHECK-NOT:                       DivZeroCheck
545  /// CHECK-NOT:                       Div
546
547  public static long LongDivision() {
548    long a, b, c;
549    a = 8L;
550    b = 3L;
551    c = a / b;
552    return c;
553  }
554
555  /// CHECK-START: float Main.FloatDivision() constant_folding (before)
556  /// CHECK-DAG:     <<Const8:f\d+>>   FloatConstant 8
557  /// CHECK-DAG:     <<Const2P5:f\d+>> FloatConstant 2.5
558  /// CHECK-DAG:     <<Div:f\d+>>      Div [<<Const8>>,<<Const2P5>>]
559  /// CHECK-DAG:                       Return [<<Div>>]
560
561  /// CHECK-START: float Main.FloatDivision() constant_folding (after)
562  /// CHECK-DAG:     <<Const3P2:f\d+>> FloatConstant 3.2
563  /// CHECK-DAG:                       Return [<<Const3P2>>]
564
565  /// CHECK-START: float Main.FloatDivision() constant_folding (after)
566  /// CHECK-NOT:                       Div
567
568  public static float FloatDivision() {
569    float a, b, c;
570    a = 8F;
571    b = 2.5F;
572    c = a / b;
573    return c;
574  }
575
576  /// CHECK-START: double Main.DoubleDivision() constant_folding (before)
577  /// CHECK-DAG:     <<Const8:d\d+>>   DoubleConstant 8
578  /// CHECK-DAG:     <<Const2P5:d\d+>> DoubleConstant 2.5
579  /// CHECK-DAG:     <<Div:d\d+>>      Div [<<Const8>>,<<Const2P5>>]
580  /// CHECK-DAG:                       Return [<<Div>>]
581
582  /// CHECK-START: double Main.DoubleDivision() constant_folding (after)
583  /// CHECK-DAG:     <<Const3P2:d\d+>> DoubleConstant 3.2
584  /// CHECK-DAG:                       Return [<<Const3P2>>]
585
586  /// CHECK-START: double Main.DoubleDivision() constant_folding (after)
587  /// CHECK-NOT:                       Div
588
589  public static double DoubleDivision() {
590    double a, b, c;
591    a = 8D;
592    b = 2.5D;
593    c = a / b;
594    return c;
595  }
596
597
598  /**
599   * Exercise constant folding on remainder.
600   */
601
602  /// CHECK-START: int Main.IntRemainder() constant_folding (before)
603  /// CHECK-DAG:     <<Const8:i\d+>>   IntConstant 8
604  /// CHECK-DAG:     <<Const3:i\d+>>   IntConstant 3
605  /// CHECK-DAG:     <<Div0Chk:i\d+>>  DivZeroCheck [<<Const3>>]
606  /// CHECK-DAG:     <<Rem:i\d+>>      Rem [<<Const8>>,<<Div0Chk>>]
607  /// CHECK-DAG:                       Return [<<Rem>>]
608
609  /// CHECK-START: int Main.IntRemainder() constant_folding (after)
610  /// CHECK-DAG:     <<Const2:i\d+>>   IntConstant 2
611  /// CHECK-DAG:                       Return [<<Const2>>]
612
613  /// CHECK-START: int Main.IntRemainder() constant_folding (after)
614  /// CHECK-NOT:                       DivZeroCheck
615  /// CHECK-NOT:                       Rem
616
617  public static int IntRemainder() {
618    int a, b, c;
619    a = 8;
620    b = 3;
621    c = a % b;
622    return c;
623  }
624
625  /// CHECK-START: long Main.LongRemainder() constant_folding (before)
626  /// CHECK-DAG:     <<Const8:j\d+>>   LongConstant 8
627  /// CHECK-DAG:     <<Const3:j\d+>>   LongConstant 3
628  /// CHECK-DAG:     <<Div0Chk:j\d+>>  DivZeroCheck [<<Const3>>]
629  /// CHECK-DAG:     <<Rem:j\d+>>      Rem [<<Const8>>,<<Div0Chk>>]
630  /// CHECK-DAG:                       Return [<<Rem>>]
631
632  /// CHECK-START: long Main.LongRemainder() constant_folding (after)
633  /// CHECK-DAG:     <<Const2:j\d+>>   LongConstant 2
634  /// CHECK-DAG:                       Return [<<Const2>>]
635
636  /// CHECK-START: long Main.LongRemainder() constant_folding (after)
637  /// CHECK-NOT:                       DivZeroCheck
638  /// CHECK-NOT:                       Rem
639
640  public static long LongRemainder() {
641    long a, b, c;
642    a = 8L;
643    b = 3L;
644    c = a % b;
645    return c;
646  }
647
648  /// CHECK-START: float Main.FloatRemainder() constant_folding (before)
649  /// CHECK-DAG:     <<Const8:f\d+>>   FloatConstant 8
650  /// CHECK-DAG:     <<Const2P5:f\d+>> FloatConstant 2.5
651  /// CHECK-DAG:     <<Rem:f\d+>>      Rem [<<Const8>>,<<Const2P5>>]
652  /// CHECK-DAG:                       Return [<<Rem>>]
653
654  /// CHECK-START: float Main.FloatRemainder() constant_folding (after)
655  /// CHECK-DAG:     <<Const0P5:f\d+>> FloatConstant 0.5
656  /// CHECK-DAG:                       Return [<<Const0P5>>]
657
658  /// CHECK-START: float Main.FloatRemainder() constant_folding (after)
659  /// CHECK-NOT:                       Rem
660
661  public static float FloatRemainder() {
662    float a, b, c;
663    a = 8F;
664    b = 2.5F;
665    c = a % b;
666    return c;
667  }
668
669  /// CHECK-START: double Main.DoubleRemainder() constant_folding (before)
670  /// CHECK-DAG:     <<Const8:d\d+>>   DoubleConstant 8
671  /// CHECK-DAG:     <<Const2P5:d\d+>> DoubleConstant 2.5
672  /// CHECK-DAG:     <<Rem:d\d+>>      Rem [<<Const8>>,<<Const2P5>>]
673  /// CHECK-DAG:                       Return [<<Rem>>]
674
675  /// CHECK-START: double Main.DoubleRemainder() constant_folding (after)
676  /// CHECK-DAG:     <<Const0P5:d\d+>> DoubleConstant 0.5
677  /// CHECK-DAG:                       Return [<<Const0P5>>]
678
679  /// CHECK-START: double Main.DoubleRemainder() constant_folding (after)
680  /// CHECK-NOT:                       Rem
681
682  public static double DoubleRemainder() {
683    double a, b, c;
684    a = 8D;
685    b = 2.5D;
686    c = a % b;
687    return c;
688  }
689
690
691  /**
692   * Exercise constant folding on left shift.
693   */
694
695  /// CHECK-START: int Main.ShlIntLong() constant_folding (before)
696  /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
697  /// CHECK-DAG:     <<Const2L:j\d+>>  LongConstant 2
698  /// CHECK-DAG:     <<TypeConv:i\d+>> TypeConversion [<<Const2L>>]
699  /// CHECK-DAG:     <<Shl:i\d+>>      Shl [<<Const1>>,<<TypeConv>>]
700  /// CHECK-DAG:                       Return [<<Shl>>]
701
702  /// CHECK-START: int Main.ShlIntLong() constant_folding (after)
703  /// CHECK-DAG:     <<Const4:i\d+>>   IntConstant 4
704  /// CHECK-DAG:                       Return [<<Const4>>]
705
706  /// CHECK-START: int Main.ShlIntLong() constant_folding (after)
707  /// CHECK-NOT:                       Shl
708
709  public static int ShlIntLong() {
710    int lhs = 1;
711    long rhs = 2;
712    return lhs << rhs;
713  }
714
715  /// CHECK-START: long Main.ShlLongInt() constant_folding (before)
716  /// CHECK-DAG:     <<Const3L:j\d+>>  LongConstant 3
717  /// CHECK-DAG:     <<Const2:i\d+>>   IntConstant 2
718  /// CHECK-DAG:     <<Shl:j\d+>>      Shl [<<Const3L>>,<<Const2>>]
719  /// CHECK-DAG:                       Return [<<Shl>>]
720
721  /// CHECK-START: long Main.ShlLongInt() constant_folding (after)
722  /// CHECK-DAG:     <<Const12L:j\d+>> LongConstant 12
723  /// CHECK-DAG:                       Return [<<Const12L>>]
724
725  /// CHECK-START: long Main.ShlLongInt() constant_folding (after)
726  /// CHECK-NOT:                       Shl
727
728  public static long ShlLongInt() {
729    long lhs = 3;
730    int rhs = 2;
731    return lhs << rhs;
732  }
733
734
735  /**
736   * Exercise constant folding on right shift.
737   */
738
739  /// CHECK-START: int Main.ShrIntLong() constant_folding (before)
740  /// CHECK-DAG:     <<Const7:i\d+>>   IntConstant 7
741  /// CHECK-DAG:     <<Const2L:j\d+>>  LongConstant 2
742  /// CHECK-DAG:     <<TypeConv:i\d+>> TypeConversion [<<Const2L>>]
743  /// CHECK-DAG:     <<Shr:i\d+>>      Shr [<<Const7>>,<<TypeConv>>]
744  /// CHECK-DAG:                       Return [<<Shr>>]
745
746  /// CHECK-START: int Main.ShrIntLong() constant_folding (after)
747  /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
748  /// CHECK-DAG:                       Return [<<Const1>>]
749
750  /// CHECK-START: int Main.ShrIntLong() constant_folding (after)
751  /// CHECK-NOT:                       Shr
752
753  public static int ShrIntLong() {
754    int lhs = 7;
755    long rhs = 2;
756    return lhs >> rhs;
757  }
758
759  /// CHECK-START: long Main.ShrLongInt() constant_folding (before)
760  /// CHECK-DAG:     <<Const9L:j\d+>>  LongConstant 9
761  /// CHECK-DAG:     <<Const2:i\d+>>   IntConstant 2
762  /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Const9L>>,<<Const2>>]
763  /// CHECK-DAG:                       Return [<<Shr>>]
764
765  /// CHECK-START: long Main.ShrLongInt() constant_folding (after)
766  /// CHECK-DAG:     <<Const2L:j\d+>>  LongConstant 2
767  /// CHECK-DAG:                       Return [<<Const2L>>]
768
769  /// CHECK-START: long Main.ShrLongInt() constant_folding (after)
770  /// CHECK-NOT:                       Shr
771
772  public static long ShrLongInt() {
773    long lhs = 9;
774    int rhs = 2;
775    return lhs >> rhs;
776  }
777
778
779  /**
780   * Exercise constant folding on unsigned right shift.
781   */
782
783  /// CHECK-START: int Main.UShrIntLong() constant_folding (before)
784  /// CHECK-DAG:     <<ConstM7:i\d+>>  IntConstant -7
785  /// CHECK-DAG:     <<Const2L:j\d+>>  LongConstant 2
786  /// CHECK-DAG:     <<TypeConv:i\d+>> TypeConversion [<<Const2L>>]
787  /// CHECK-DAG:     <<UShr:i\d+>>     UShr [<<ConstM7>>,<<TypeConv>>]
788  /// CHECK-DAG:                       Return [<<UShr>>]
789
790  /// CHECK-START: int Main.UShrIntLong() constant_folding (after)
791  /// CHECK-DAG:     <<ConstRes:i\d+>> IntConstant 1073741822
792  /// CHECK-DAG:                       Return [<<ConstRes>>]
793
794  /// CHECK-START: int Main.UShrIntLong() constant_folding (after)
795  /// CHECK-NOT:                       UShr
796
797  public static int UShrIntLong() {
798    int lhs = -7;
799    long rhs = 2;
800    return lhs >>> rhs;
801  }
802
803  /// CHECK-START: long Main.UShrLongInt() constant_folding (before)
804  /// CHECK-DAG:     <<ConstM9L:j\d+>> LongConstant -9
805  /// CHECK-DAG:     <<Const2:i\d+>>   IntConstant 2
806  /// CHECK-DAG:     <<UShr:j\d+>>     UShr [<<ConstM9L>>,<<Const2>>]
807  /// CHECK-DAG:                       Return [<<UShr>>]
808
809  /// CHECK-START: long Main.UShrLongInt() constant_folding (after)
810  /// CHECK-DAG:     <<ConstRes:j\d+>> LongConstant 4611686018427387901
811  /// CHECK-DAG:                       Return [<<ConstRes>>]
812
813  /// CHECK-START: long Main.UShrLongInt() constant_folding (after)
814  /// CHECK-NOT:                       UShr
815
816  public static long UShrLongInt() {
817    long lhs = -9;
818    int rhs = 2;
819    return lhs >>> rhs;
820  }
821
822
823  /**
824   * Exercise constant folding on logical and.
825   */
826
827  /// CHECK-START: long Main.AndIntLong() constant_folding (before)
828  /// CHECK-DAG:     <<Const10:i\d+>>  IntConstant 10
829  /// CHECK-DAG:     <<Const3L:j\d+>>  LongConstant 3
830  /// CHECK-DAG:     <<TypeConv:j\d+>> TypeConversion [<<Const10>>]
831  /// CHECK-DAG:     <<And:j\d+>>      And [<<TypeConv>>,<<Const3L>>]
832  /// CHECK-DAG:                       Return [<<And>>]
833
834  /// CHECK-START: long Main.AndIntLong() constant_folding (after)
835  /// CHECK-DAG:     <<Const2:j\d+>>   LongConstant 2
836  /// CHECK-DAG:                       Return [<<Const2>>]
837
838  /// CHECK-START: long Main.AndIntLong() constant_folding (after)
839  /// CHECK-NOT:                       And
840
841  public static long AndIntLong() {
842    int lhs = 10;
843    long rhs = 3;
844    return lhs & rhs;
845  }
846
847  /// CHECK-START: long Main.AndLongInt() constant_folding (before)
848  /// CHECK-DAG:     <<Const10L:j\d+>> LongConstant 10
849  /// CHECK-DAG:     <<Const3:i\d+>>   IntConstant 3
850  /// CHECK-DAG:     <<TypeConv:j\d+>> TypeConversion [<<Const3>>]
851  /// CHECK-DAG:     <<And:j\d+>>      And [<<TypeConv>>,<<Const10L>>]
852  /// CHECK-DAG:                       Return [<<And>>]
853
854  /// CHECK-START: long Main.AndLongInt() constant_folding (after)
855  /// CHECK-DAG:     <<Const2:j\d+>>   LongConstant 2
856  /// CHECK-DAG:                       Return [<<Const2>>]
857
858  /// CHECK-START: long Main.AndLongInt() constant_folding (after)
859  /// CHECK-NOT:                       And
860
861  public static long AndLongInt() {
862    long lhs = 10;
863    int rhs = 3;
864    return lhs & rhs;
865  }
866
867
868  /**
869   * Exercise constant folding on logical or.
870   */
871
872  /// CHECK-START: long Main.OrIntLong() constant_folding (before)
873  /// CHECK-DAG:     <<Const10:i\d+>>  IntConstant 10
874  /// CHECK-DAG:     <<Const3L:j\d+>>  LongConstant 3
875  /// CHECK-DAG:     <<TypeConv:j\d+>> TypeConversion [<<Const10>>]
876  /// CHECK-DAG:     <<Or:j\d+>>       Or [<<TypeConv>>,<<Const3L>>]
877  /// CHECK-DAG:                       Return [<<Or>>]
878
879  /// CHECK-START: long Main.OrIntLong() constant_folding (after)
880  /// CHECK-DAG:     <<Const11:j\d+>>  LongConstant 11
881  /// CHECK-DAG:                       Return [<<Const11>>]
882
883  /// CHECK-START: long Main.OrIntLong() constant_folding (after)
884  /// CHECK-NOT:                       Or
885
886  public static long OrIntLong() {
887    int lhs = 10;
888    long rhs = 3;
889    return lhs | rhs;
890  }
891
892  /// CHECK-START: long Main.OrLongInt() constant_folding (before)
893  /// CHECK-DAG:     <<Const10L:j\d+>> LongConstant 10
894  /// CHECK-DAG:     <<Const3:i\d+>>   IntConstant 3
895  /// CHECK-DAG:     <<TypeConv:j\d+>> TypeConversion [<<Const3>>]
896  /// CHECK-DAG:     <<Or:j\d+>>       Or [<<TypeConv>>,<<Const10L>>]
897  /// CHECK-DAG:                       Return [<<Or>>]
898
899  /// CHECK-START: long Main.OrLongInt() constant_folding (after)
900  /// CHECK-DAG:     <<Const11:j\d+>>  LongConstant 11
901  /// CHECK-DAG:                       Return [<<Const11>>]
902
903  /// CHECK-START: long Main.OrLongInt() constant_folding (after)
904  /// CHECK-NOT:                       Or
905
906  public static long OrLongInt() {
907    long lhs = 10;
908    int rhs = 3;
909    return lhs | rhs;
910  }
911
912
913  /**
914   * Exercise constant folding on logical exclusive or.
915   */
916
917  /// CHECK-START: long Main.XorIntLong() constant_folding (before)
918  /// CHECK-DAG:     <<Const10:i\d+>>  IntConstant 10
919  /// CHECK-DAG:     <<Const3L:j\d+>>  LongConstant 3
920  /// CHECK-DAG:     <<TypeConv:j\d+>> TypeConversion [<<Const10>>]
921  /// CHECK-DAG:     <<Xor:j\d+>>      Xor [<<TypeConv>>,<<Const3L>>]
922  /// CHECK-DAG:                       Return [<<Xor>>]
923
924  /// CHECK-START: long Main.XorIntLong() constant_folding (after)
925  /// CHECK-DAG:     <<Const9:j\d+>>   LongConstant 9
926  /// CHECK-DAG:                       Return [<<Const9>>]
927
928  /// CHECK-START: long Main.XorIntLong() constant_folding (after)
929  /// CHECK-NOT:                       Xor
930
931  public static long XorIntLong() {
932    int lhs = 10;
933    long rhs = 3;
934    return lhs ^ rhs;
935  }
936
937  /// CHECK-START: long Main.XorLongInt() constant_folding (before)
938  /// CHECK-DAG:     <<Const10L:j\d+>> LongConstant 10
939  /// CHECK-DAG:     <<Const3:i\d+>>   IntConstant 3
940  /// CHECK-DAG:     <<TypeConv:j\d+>> TypeConversion [<<Const3>>]
941  /// CHECK-DAG:     <<Xor:j\d+>>      Xor [<<TypeConv>>,<<Const10L>>]
942  /// CHECK-DAG:                       Return [<<Xor>>]
943
944  /// CHECK-START: long Main.XorLongInt() constant_folding (after)
945  /// CHECK-DAG:     <<Const9:j\d+>>   LongConstant 9
946  /// CHECK-DAG:                       Return [<<Const9>>]
947
948  /// CHECK-START: long Main.XorLongInt() constant_folding (after)
949  /// CHECK-NOT:                       Xor
950
951  public static long XorLongInt() {
952    long lhs = 10;
953    int rhs = 3;
954    return lhs ^ rhs;
955  }
956
957
958  /**
959   * Exercise constant folding on constant (static) condition.
960   */
961
962  /// CHECK-START: int Main.StaticCondition() constant_folding (before)
963  /// CHECK-DAG:     <<Const7:i\d+>>  IntConstant 7
964  /// CHECK-DAG:     <<Const2:i\d+>>  IntConstant 2
965  /// CHECK-DAG:     <<Cond:z\d+>>    GreaterThanOrEqual [<<Const7>>,<<Const2>>]
966  /// CHECK-DAG:                      If [<<Cond>>]
967
968  /// CHECK-START: int Main.StaticCondition() constant_folding (after)
969  /// CHECK-DAG:     <<Const1:i\d+>>  IntConstant 1
970  /// CHECK-DAG:                      If [<<Const1>>]
971
972  /// CHECK-START: int Main.StaticCondition() constant_folding (after)
973  /// CHECK-NOT:                      GreaterThanOrEqual
974
975  public static int StaticCondition() {
976    int a, b, c;
977    a = 7;
978    b = 2;
979    if (a < b)
980      c = a + b;
981    else
982      c = a - b;
983    return c;
984  }
985
986
987  /**
988   * Exercise constant folding on constant (static) condition for null references.
989   */
990
991  /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (before)
992  /// CHECK-DAG:     <<Null:l\d+>>    NullConstant
993  /// CHECK-DAG:     <<Cond:z\d+>>    NotEqual [<<Null>>,<<Null>>]
994  /// CHECK-DAG:                      Select [{{i\d+}},{{i\d+}},<<Cond>>]
995
996  /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (after)
997  /// CHECK-DAG:     <<Const0:i\d+>>  IntConstant 0
998  /// CHECK-DAG:                      Select [{{i\d+}},{{i\d+}},<<Const0>>]
999
1000  /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (after)
1001  /// CHECK-NOT:                      NotEqual
1002
1003  private static Object getNull() {
1004    return null;
1005  }
1006
1007  public static int StaticConditionNulls() {
1008    Object a = getNull();
1009    Object b = getNull();
1010    return (a == b) ? 5 : 2;
1011  }
1012
1013
1014  /**
1015   * Exercise constant folding on a program with condition
1016   * (i.e. jumps) leading to the creation of many blocks.
1017   *
1018   * The intent of this test is to ensure that all constant expressions
1019   * are actually evaluated at compile-time, thanks to the reverse
1020   * (forward) post-order traversal of the the dominator tree.
1021   */
1022
1023  /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (before)
1024  /// CHECK-DAG:     <<Const2:i\d+>>  IntConstant 2
1025  /// CHECK-DAG:     <<Const5:i\d+>>  IntConstant 5
1026  /// CHECK-DAG:     <<Add:i\d+>>     Add [<<Const5>>,<<Const2>>]
1027  /// CHECK-DAG:     <<Sub:i\d+>>     Sub [<<Const5>>,<<Const2>>]
1028  /// CHECK-DAG:     <<Phi:i\d+>>     Phi [<<Add>>,<<Sub>>]
1029  /// CHECK-DAG:                      Return [<<Phi>>]
1030
1031  /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after)
1032  /// CHECK-DAG:     <<Const3:i\d+>>  IntConstant 3
1033  /// CHECK-DAG:     <<Const7:i\d+>>  IntConstant 7
1034  /// CHECK-DAG:     <<Phi:i\d+>>     Phi [<<Const7>>,<<Const3>>]
1035  /// CHECK-DAG:                      Return [<<Phi>>]
1036
1037  /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after)
1038  /// CHECK-NOT:                      Add
1039  /// CHECK-NOT:                      Sub
1040
1041  public static int JumpsAndConditionals(boolean cond) {
1042    int a, b, c;
1043    a = 5;
1044    b = 2;
1045    if (cond)
1046      c = a + b;
1047    else
1048      c = a - b;
1049    return c;
1050  }
1051
1052
1053  /**
1054   * Test optimizations of arithmetic identities yielding a constant result.
1055   */
1056
1057  /// CHECK-START: int Main.And0(int) constant_folding (before)
1058  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1059  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1060  /// CHECK-DAG:     <<And:i\d+>>      And [<<Arg>>,<<Const0>>]
1061  /// CHECK-DAG:                       Return [<<And>>]
1062
1063  /// CHECK-START: int Main.And0(int) constant_folding (after)
1064  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1065  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1066  /// CHECK-DAG:                       Return [<<Const0>>]
1067
1068  /// CHECK-START: int Main.And0(int) constant_folding (after)
1069  /// CHECK-NOT:                       And
1070
1071  public static int And0(int arg) {
1072    return arg & 0;
1073  }
1074
1075  /// CHECK-START: long Main.Mul0(long) constant_folding (before)
1076  /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
1077  /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
1078  /// CHECK-DAG:     <<Mul:j\d+>>      Mul [<<Const0>>,<<Arg>>]
1079  /// CHECK-DAG:                       Return [<<Mul>>]
1080
1081  /// CHECK-START: long Main.Mul0(long) constant_folding (after)
1082  /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
1083  /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
1084  /// CHECK-DAG:                       Return [<<Const0>>]
1085
1086  /// CHECK-START: long Main.Mul0(long) constant_folding (after)
1087  /// CHECK-NOT:                       Mul
1088
1089  public static long Mul0(long arg) {
1090    return arg * 0;
1091  }
1092
1093  /// CHECK-START: int Main.OrAllOnes(int) constant_folding (before)
1094  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1095  /// CHECK-DAG:     <<ConstF:i\d+>>   IntConstant -1
1096  /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Arg>>,<<ConstF>>]
1097  /// CHECK-DAG:                       Return [<<Or>>]
1098
1099  /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
1100  /// CHECK-DAG:     <<ConstF:i\d+>>   IntConstant -1
1101  /// CHECK-DAG:                       Return [<<ConstF>>]
1102
1103  /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
1104  /// CHECK-NOT:                       Or
1105
1106  public static int OrAllOnes(int arg) {
1107    return arg | -1;
1108  }
1109
1110  /// CHECK-START: long Main.Rem0(long) constant_folding (before)
1111  /// CHECK-DAG:     <<Arg:j\d+>>           ParameterValue
1112  /// CHECK-DAG:     <<Const0:j\d+>>        LongConstant 0
1113  /// CHECK-DAG:     <<DivZeroCheck:j\d+>>  DivZeroCheck [<<Arg>>]
1114  /// CHECK-DAG:     <<Rem:j\d+>>           Rem [<<Const0>>,<<DivZeroCheck>>]
1115  /// CHECK-DAG:                            Return [<<Rem>>]
1116
1117  /// CHECK-START: long Main.Rem0(long) constant_folding (after)
1118  /// CHECK-DAG:     <<Const0:j\d+>>        LongConstant 0
1119  /// CHECK-DAG:                            Return [<<Const0>>]
1120
1121  /// CHECK-START: long Main.Rem0(long) constant_folding (after)
1122  /// CHECK-NOT:                            Rem
1123
1124  public static long Rem0(long arg) {
1125    return 0 % arg;
1126  }
1127
1128  /// CHECK-START: int Main.Rem1(int) constant_folding (before)
1129  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1130  /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
1131  /// CHECK-DAG:     <<Rem:i\d+>>      Rem [<<Arg>>,<<Const1>>]
1132  /// CHECK-DAG:                       Return [<<Rem>>]
1133
1134  /// CHECK-START: int Main.Rem1(int) constant_folding (after)
1135  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1136  /// CHECK-DAG:                       Return [<<Const0>>]
1137
1138  /// CHECK-START: int Main.Rem1(int) constant_folding (after)
1139  /// CHECK-NOT:                       Rem
1140
1141  public static int Rem1(int arg) {
1142    return arg % 1;
1143  }
1144
1145  /// CHECK-START: long Main.RemN1(long) constant_folding (before)
1146  /// CHECK-DAG:     <<Arg:j\d+>>           ParameterValue
1147  /// CHECK-DAG:     <<ConstN1:j\d+>>       LongConstant -1
1148  /// CHECK-DAG:     <<DivZeroCheck:j\d+>>  DivZeroCheck [<<ConstN1>>]
1149  /// CHECK-DAG:     <<Rem:j\d+>>           Rem [<<Arg>>,<<DivZeroCheck>>]
1150  /// CHECK-DAG:                            Return [<<Rem>>]
1151
1152  /// CHECK-START: long Main.RemN1(long) constant_folding (after)
1153  /// CHECK-DAG:     <<Const0:j\d+>>        LongConstant 0
1154  /// CHECK-DAG:                            Return [<<Const0>>]
1155
1156  /// CHECK-START: long Main.RemN1(long) constant_folding (after)
1157  /// CHECK-NOT:                            Rem
1158
1159  public static long RemN1(long arg) {
1160    return arg % -1;
1161  }
1162
1163  /// CHECK-START: int Main.Shl0(int) constant_folding (before)
1164  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1165  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1166  /// CHECK-DAG:     <<Shl:i\d+>>      Shl [<<Const0>>,<<Arg>>]
1167  /// CHECK-DAG:                       Return [<<Shl>>]
1168
1169  /// CHECK-START: int Main.Shl0(int) constant_folding (after)
1170  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1171  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1172  /// CHECK-DAG:                       Return [<<Const0>>]
1173
1174  /// CHECK-START: int Main.Shl0(int) constant_folding (after)
1175  /// CHECK-NOT:                       Shl
1176
1177  public static int Shl0(int arg) {
1178    return 0 << arg;
1179  }
1180
1181  /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (before)
1182  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1183  /// CHECK-DAG:     <<Const0L:j\d+>>  LongConstant 0
1184  /// CHECK-DAG:     <<Shl:j\d+>>      Shl [<<Const0L>>,<<Arg>>]
1185  /// CHECK-DAG:                       Return [<<Shl>>]
1186
1187  /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after)
1188  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1189  /// CHECK-DAG:     <<Const0L:j\d+>>  LongConstant 0
1190  /// CHECK-DAG:                       Return [<<Const0L>>]
1191
1192  /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after)
1193  /// CHECK-NOT:                       Shl
1194
1195  public static long ShlLong0WithInt(int arg) {
1196    long long_zero = 0;
1197    return long_zero << arg;
1198  }
1199
1200  /// CHECK-START: long Main.Shr0(int) constant_folding (before)
1201  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1202  /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
1203  /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Const0>>,<<Arg>>]
1204  /// CHECK-DAG:                       Return [<<Shr>>]
1205
1206  /// CHECK-START: long Main.Shr0(int) constant_folding (after)
1207  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1208  /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
1209  /// CHECK-DAG:                       Return [<<Const0>>]
1210
1211  /// CHECK-START: long Main.Shr0(int) constant_folding (after)
1212  /// CHECK-NOT:                       Shr
1213
1214  public static long Shr0(int arg) {
1215    return (long)0 >> arg;
1216  }
1217
1218  /// CHECK-START: long Main.SubSameLong(long) constant_folding (before)
1219  /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
1220  /// CHECK-DAG:     <<Sub:j\d+>>      Sub [<<Arg>>,<<Arg>>]
1221  /// CHECK-DAG:                       Return [<<Sub>>]
1222
1223  /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
1224  /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
1225  /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
1226  /// CHECK-DAG:                       Return [<<Const0>>]
1227
1228  /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
1229  /// CHECK-NOT:                       Sub
1230
1231  public static long SubSameLong(long arg) {
1232    return arg - arg;
1233  }
1234
1235  /// CHECK-START: int Main.UShr0(int) constant_folding (before)
1236  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1237  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1238  /// CHECK-DAG:     <<UShr:i\d+>>     UShr [<<Const0>>,<<Arg>>]
1239  /// CHECK-DAG:                       Return [<<UShr>>]
1240
1241  /// CHECK-START: int Main.UShr0(int) constant_folding (after)
1242  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1243  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1244  /// CHECK-DAG:                       Return [<<Const0>>]
1245
1246  /// CHECK-START: int Main.UShr0(int) constant_folding (after)
1247  /// CHECK-NOT:                       UShr
1248
1249  public static int UShr0(int arg) {
1250    return 0 >>> arg;
1251  }
1252
1253  /// CHECK-START: int Main.XorSameInt(int) constant_folding (before)
1254  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1255  /// CHECK-DAG:     <<Xor:i\d+>>      Xor [<<Arg>>,<<Arg>>]
1256  /// CHECK-DAG:                       Return [<<Xor>>]
1257
1258  /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
1259  /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1260  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1261  /// CHECK-DAG:                       Return [<<Const0>>]
1262
1263  /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
1264  /// CHECK-NOT:                       Xor
1265
1266  public static int XorSameInt(int arg) {
1267    return arg ^ arg;
1268  }
1269
1270  /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (before)
1271  /// CHECK-DAG:     <<Arg:f\d+>>      ParameterValue
1272  /// CHECK-DAG:     <<ConstNan:f\d+>> FloatConstant nan
1273  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1274  /// CHECK-DAG:                       IntConstant 1
1275  /// CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Arg>>,<<ConstNan>>]
1276  /// CHECK-DAG:     <<Le:z\d+>>       LessThanOrEqual [<<Cmp>>,<<Const0>>]
1277  /// CHECK-DAG:                       If [<<Le>>]
1278
1279  /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
1280  /// CHECK-DAG:                       ParameterValue
1281  /// CHECK-DAG:                       FloatConstant nan
1282  /// CHECK-DAG:                       IntConstant 0
1283  /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
1284  /// CHECK-DAG:                       If [<<Const1>>]
1285
1286  /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
1287  /// CHECK-NOT:                       Compare
1288  /// CHECK-NOT:                       LessThanOrEqual
1289
1290  public static boolean CmpFloatGreaterThanNaN(float arg) {
1291    return arg > Float.NaN;
1292  }
1293
1294  /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (before)
1295  /// CHECK-DAG:     <<Arg:d\d+>>      ParameterValue
1296  /// CHECK-DAG:     <<ConstNan:d\d+>> DoubleConstant nan
1297  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1298  /// CHECK-DAG:                       IntConstant 1
1299  /// CHECK-DAG:     <<Cmp:i\d+>>      Compare [<<Arg>>,<<ConstNan>>]
1300  /// CHECK-DAG:     <<Ge:z\d+>>       GreaterThanOrEqual [<<Cmp>>,<<Const0>>]
1301  /// CHECK-DAG:                       If [<<Ge>>]
1302
1303  /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
1304  /// CHECK-DAG:                       ParameterValue
1305  /// CHECK-DAG:                       DoubleConstant nan
1306  /// CHECK-DAG:                       IntConstant 0
1307  /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
1308  /// CHECK-DAG:                       If [<<Const1>>]
1309
1310  /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
1311  /// CHECK-NOT:                       Compare
1312  /// CHECK-NOT:                       GreaterThanOrEqual
1313
1314  public static boolean CmpDoubleLessThanNaN(double arg) {
1315    return arg < Double.NaN;
1316  }
1317
1318
1319  /**
1320   * Exercise constant folding on type conversions.
1321   */
1322
1323  /// CHECK-START: int Main.ReturnInt33() constant_folding (before)
1324  /// CHECK-DAG:     <<Const33:j\d+>>  LongConstant 33
1325  /// CHECK-DAG:     <<Convert:i\d+>>  TypeConversion [<<Const33>>]
1326  /// CHECK-DAG:                       Return [<<Convert>>]
1327
1328  /// CHECK-START: int Main.ReturnInt33() constant_folding (after)
1329  /// CHECK-DAG:     <<Const33:i\d+>>  IntConstant 33
1330  /// CHECK-DAG:                       Return [<<Const33>>]
1331
1332  /// CHECK-START: int Main.ReturnInt33() constant_folding (after)
1333  /// CHECK-NOT:                       TypeConversion
1334
1335  public static int ReturnInt33() {
1336    long imm = 33L;
1337    return (int) imm;
1338  }
1339
1340  /// CHECK-START: int Main.ReturnIntMax() constant_folding (before)
1341  /// CHECK-DAG:     <<ConstMax:f\d+>> FloatConstant 1e+34
1342  /// CHECK-DAG:     <<Convert:i\d+>>  TypeConversion [<<ConstMax>>]
1343  /// CHECK-DAG:                       Return [<<Convert>>]
1344
1345  /// CHECK-START: int Main.ReturnIntMax() constant_folding (after)
1346  /// CHECK-DAG:     <<ConstMax:i\d+>> IntConstant 2147483647
1347  /// CHECK-DAG:                       Return [<<ConstMax>>]
1348
1349  /// CHECK-START: int Main.ReturnIntMax() constant_folding (after)
1350  /// CHECK-NOT:                       TypeConversion
1351
1352  public static int ReturnIntMax() {
1353    float imm = 1.0e34f;
1354    return (int) imm;
1355  }
1356
1357  /// CHECK-START: int Main.ReturnInt0() constant_folding (before)
1358  /// CHECK-DAG:     <<ConstNaN:d\d+>> DoubleConstant nan
1359  /// CHECK-DAG:     <<Convert:i\d+>>  TypeConversion [<<ConstNaN>>]
1360  /// CHECK-DAG:                       Return [<<Convert>>]
1361
1362  /// CHECK-START: int Main.ReturnInt0() constant_folding (after)
1363  /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1364  /// CHECK-DAG:                       Return [<<Const0>>]
1365
1366  /// CHECK-START: int Main.ReturnInt0() constant_folding (after)
1367  /// CHECK-NOT:                       TypeConversion
1368
1369  public static int ReturnInt0() {
1370    double imm = Double.NaN;
1371    return (int) imm;
1372  }
1373
1374  /// CHECK-START: long Main.ReturnLong33() constant_folding (before)
1375  /// CHECK-DAG:     <<Const33:i\d+>>  IntConstant 33
1376  /// CHECK-DAG:     <<Convert:j\d+>>  TypeConversion [<<Const33>>]
1377  /// CHECK-DAG:                       Return [<<Convert>>]
1378
1379  /// CHECK-START: long Main.ReturnLong33() constant_folding (after)
1380  /// CHECK-DAG:     <<Const33:j\d+>>  LongConstant 33
1381  /// CHECK-DAG:                       Return [<<Const33>>]
1382
1383  /// CHECK-START: long Main.ReturnLong33() constant_folding (after)
1384  /// CHECK-NOT:                       TypeConversion
1385
1386  public static long ReturnLong33() {
1387    int imm = 33;
1388    return (long) imm;
1389  }
1390
1391  /// CHECK-START: long Main.ReturnLong34() constant_folding (before)
1392  /// CHECK-DAG:     <<Const34:f\d+>>  FloatConstant 34
1393  /// CHECK-DAG:     <<Convert:j\d+>>  TypeConversion [<<Const34>>]
1394  /// CHECK-DAG:                       Return [<<Convert>>]
1395
1396  /// CHECK-START: long Main.ReturnLong34() constant_folding (after)
1397  /// CHECK-DAG:     <<Const34:j\d+>>  LongConstant 34
1398  /// CHECK-DAG:                       Return [<<Const34>>]
1399
1400  /// CHECK-START: long Main.ReturnLong34() constant_folding (after)
1401  /// CHECK-NOT:                       TypeConversion
1402
1403  public static long ReturnLong34() {
1404    float imm = 34.0f;
1405    return (long) imm;
1406  }
1407
1408  /// CHECK-START: long Main.ReturnLong0() constant_folding (before)
1409  /// CHECK-DAG:     <<ConstNaN:d\d+>> DoubleConstant nan
1410  /// CHECK-DAG:     <<Convert:j\d+>>  TypeConversion [<<ConstNaN>>]
1411  /// CHECK-DAG:                       Return [<<Convert>>]
1412
1413  /// CHECK-START: long Main.ReturnLong0() constant_folding (after)
1414  /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
1415  /// CHECK-DAG:                       Return [<<Const0>>]
1416
1417  /// CHECK-START: long Main.ReturnLong0() constant_folding (after)
1418  /// CHECK-NOT:                       TypeConversion
1419
1420  public static long ReturnLong0() {
1421    double imm = -Double.NaN;
1422    return (long) imm;
1423  }
1424
1425  /// CHECK-START: float Main.ReturnFloat33() constant_folding (before)
1426  /// CHECK-DAG:     <<Const33:i\d+>>  IntConstant 33
1427  /// CHECK-DAG:     <<Convert:f\d+>>  TypeConversion [<<Const33>>]
1428  /// CHECK-DAG:                       Return [<<Convert>>]
1429
1430  /// CHECK-START: float Main.ReturnFloat33() constant_folding (after)
1431  /// CHECK-DAG:     <<Const33:f\d+>>  FloatConstant 33
1432  /// CHECK-DAG:                       Return [<<Const33>>]
1433
1434  /// CHECK-START: float Main.ReturnFloat33() constant_folding (after)
1435  /// CHECK-NOT:                       TypeConversion
1436
1437  public static float ReturnFloat33() {
1438    int imm = 33;
1439    return (float) imm;
1440  }
1441
1442  /// CHECK-START: float Main.ReturnFloat34() constant_folding (before)
1443  /// CHECK-DAG:     <<Const34:j\d+>>  LongConstant 34
1444  /// CHECK-DAG:     <<Convert:f\d+>>  TypeConversion [<<Const34>>]
1445  /// CHECK-DAG:                       Return [<<Convert>>]
1446
1447  /// CHECK-START: float Main.ReturnFloat34() constant_folding (after)
1448  /// CHECK-DAG:     <<Const34:f\d+>>  FloatConstant 34
1449  /// CHECK-DAG:                       Return [<<Const34>>]
1450
1451  /// CHECK-START: float Main.ReturnFloat34() constant_folding (after)
1452  /// CHECK-NOT:                       TypeConversion
1453
1454  public static float ReturnFloat34() {
1455    long imm = 34L;
1456    return (float) imm;
1457  }
1458
1459  /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (before)
1460  /// CHECK-DAG:     <<Const:d\d+>>    DoubleConstant 99.25
1461  /// CHECK-DAG:     <<Convert:f\d+>>  TypeConversion [<<Const>>]
1462  /// CHECK-DAG:                       Return [<<Convert>>]
1463
1464  /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after)
1465  /// CHECK-DAG:     <<Const:f\d+>>    FloatConstant 99.25
1466  /// CHECK-DAG:                       Return [<<Const>>]
1467
1468  /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after)
1469  /// CHECK-NOT:                       TypeConversion
1470
1471  public static float ReturnFloat99P25() {
1472    double imm = 99.25;
1473    return (float) imm;
1474  }
1475
1476  /// CHECK-START: double Main.ReturnDouble33() constant_folding (before)
1477  /// CHECK-DAG:     <<Const33:i\d+>>  IntConstant 33
1478  /// CHECK-DAG:     <<Convert:d\d+>>  TypeConversion [<<Const33>>]
1479  /// CHECK-DAG:                       Return [<<Convert>>]
1480
1481  /// CHECK-START: double Main.ReturnDouble33() constant_folding (after)
1482  /// CHECK-DAG:     <<Const33:d\d+>>  DoubleConstant 33
1483  /// CHECK-DAG:                       Return [<<Const33>>]
1484
1485  public static double ReturnDouble33() {
1486    int imm = 33;
1487    return (double) imm;
1488  }
1489
1490  /// CHECK-START: double Main.ReturnDouble34() constant_folding (before)
1491  /// CHECK-DAG:     <<Const34:j\d+>>  LongConstant 34
1492  /// CHECK-DAG:     <<Convert:d\d+>>  TypeConversion [<<Const34>>]
1493  /// CHECK-DAG:                       Return [<<Convert>>]
1494
1495  /// CHECK-START: double Main.ReturnDouble34() constant_folding (after)
1496  /// CHECK-DAG:     <<Const34:d\d+>>  DoubleConstant 34
1497  /// CHECK-DAG:                       Return [<<Const34>>]
1498
1499  /// CHECK-START: double Main.ReturnDouble34() constant_folding (after)
1500  /// CHECK-NOT:                       TypeConversion
1501
1502  public static double ReturnDouble34() {
1503    long imm = 34L;
1504    return (double) imm;
1505  }
1506
1507  /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (before)
1508  /// CHECK-DAG:     <<Const:f\d+>>    FloatConstant 99.25
1509  /// CHECK-DAG:     <<Convert:d\d+>>  TypeConversion [<<Const>>]
1510  /// CHECK-DAG:                       Return [<<Convert>>]
1511
1512  /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after)
1513  /// CHECK-DAG:     <<Const:d\d+>>    DoubleConstant 99.25
1514  /// CHECK-DAG:                       Return [<<Const>>]
1515
1516  /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after)
1517  /// CHECK-NOT:                       TypeConversion
1518
1519  public static double ReturnDouble99P25() {
1520    float imm = 99.25f;
1521    return (double) imm;
1522  }
1523
1524
1525  public static void main(String[] args) throws Exception {
1526    assertIntEquals(-42, IntNegation());
1527    assertLongEquals(-42L, LongNegation());
1528    assertFloatEquals(-42F, FloatNegation());
1529    assertDoubleEquals(-42D, DoubleNegation());
1530
1531    assertIntEquals(3, IntAddition1());
1532    assertIntEquals(14, IntAddition2());
1533    assertIntEquals(14, smaliIntAddition2());
1534    assertIntEquals(14, smaliIntAddition2AddAndMove());
1535    assertLongEquals(3L, LongAddition());
1536    assertFloatEquals(3F, FloatAddition());
1537    assertDoubleEquals(3D, DoubleAddition());
1538
1539    assertIntEquals(4, IntSubtraction());
1540    assertLongEquals(4L, LongSubtraction());
1541    assertFloatEquals(4F, FloatSubtraction());
1542    assertDoubleEquals(4D, DoubleSubtraction());
1543
1544    assertIntEquals(21, IntMultiplication());
1545    assertLongEquals(21L, LongMultiplication());
1546    assertFloatEquals(21F, FloatMultiplication());
1547    assertDoubleEquals(21D, DoubleMultiplication());
1548
1549    assertIntEquals(2, IntDivision());
1550    assertLongEquals(2L, LongDivision());
1551    assertFloatEquals(3.2F, FloatDivision());
1552    assertDoubleEquals(3.2D, DoubleDivision());
1553
1554    assertIntEquals(2, IntRemainder());
1555    assertLongEquals(2L, LongRemainder());
1556    assertFloatEquals(0.5F, FloatRemainder());
1557    assertDoubleEquals(0.5D, DoubleRemainder());
1558
1559    assertIntEquals(4, ShlIntLong());
1560    assertLongEquals(12L, ShlLongInt());
1561
1562    assertIntEquals(1, ShrIntLong());
1563    assertLongEquals(2L, ShrLongInt());
1564
1565    assertIntEquals(1073741822, UShrIntLong());
1566    assertLongEquals(4611686018427387901L, UShrLongInt());
1567
1568    assertLongEquals(2, AndIntLong());
1569    assertLongEquals(2, AndLongInt());
1570
1571    assertLongEquals(11, OrIntLong());
1572    assertLongEquals(11, OrLongInt());
1573
1574    assertLongEquals(9, XorIntLong());
1575    assertLongEquals(9, XorLongInt());
1576
1577    assertIntEquals(5, StaticCondition());
1578    assertIntEquals(5, StaticConditionNulls());
1579
1580    assertIntEquals(7, JumpsAndConditionals(true));
1581    assertIntEquals(3, JumpsAndConditionals(false));
1582    assertIntEquals(7, smaliJumpsAndConditionals(true));
1583    assertIntEquals(3, smaliJumpsAndConditionals(false));
1584
1585    int arbitrary = 123456;  // Value chosen arbitrarily.
1586
1587    assertIntEquals(0, And0(arbitrary));
1588    assertLongEquals(0, Mul0(arbitrary));
1589    assertIntEquals(-1, OrAllOnes(arbitrary));
1590    assertLongEquals(0, Rem0(arbitrary));
1591    assertIntEquals(0, Rem1(arbitrary));
1592    assertLongEquals(0, RemN1(arbitrary));
1593    assertIntEquals(0, Shl0(arbitrary));
1594    assertLongEquals(0, ShlLong0WithInt(arbitrary));
1595    assertLongEquals(0, Shr0(arbitrary));
1596    assertLongEquals(0, SubSameLong(arbitrary));
1597    assertIntEquals(0, UShr0(arbitrary));
1598    assertIntEquals(0, XorSameInt(arbitrary));
1599
1600    assertFalse(CmpFloatGreaterThanNaN(arbitrary));
1601    assertFalse(CmpDoubleLessThanNaN(arbitrary));
1602
1603    Main main = new Main();
1604    assertIntEquals(1, main.smaliCmpLongConstants());
1605    assertIntEquals(-1, main.smaliCmpGtFloatConstants());
1606    assertIntEquals(-1, main.smaliCmpLtFloatConstants());
1607    assertIntEquals(-1, main.smaliCmpGtDoubleConstants());
1608    assertIntEquals(-1, main.smaliCmpLtDoubleConstants());
1609
1610    assertIntEquals(0, main.smaliCmpLongSameConstant());
1611    assertIntEquals(0, main.smaliCmpGtFloatSameConstant());
1612    assertIntEquals(0, main.smaliCmpLtFloatSameConstant());
1613    assertIntEquals(0, main.smaliCmpGtDoubleSameConstant());
1614    assertIntEquals(0, main.smaliCmpLtDoubleSameConstant());
1615
1616    assertIntEquals(1, main.smaliCmpGtFloatConstantWithNaN());
1617    assertIntEquals(-1, main.smaliCmpLtFloatConstantWithNaN());
1618    assertIntEquals(1, main.smaliCmpGtDoubleConstantWithNaN());
1619    assertIntEquals(-1, main.smaliCmpLtDoubleConstantWithNaN());
1620
1621    assertIntEquals(33, ReturnInt33());
1622    assertIntEquals(2147483647, ReturnIntMax());
1623    assertIntEquals(0, ReturnInt0());
1624
1625    assertLongEquals(33, ReturnLong33());
1626    assertLongEquals(34, ReturnLong34());
1627    assertLongEquals(0, ReturnLong0());
1628
1629    assertFloatEquals(33, ReturnFloat33());
1630    assertFloatEquals(34, ReturnFloat34());
1631    assertFloatEquals(99.25f, ReturnFloat99P25());
1632
1633    assertDoubleEquals(33, ReturnDouble33());
1634    assertDoubleEquals(34, ReturnDouble34());
1635    assertDoubleEquals(99.25, ReturnDouble99P25());
1636  }
1637
1638  Main() throws ClassNotFoundException {
1639    testCmp = Class.forName("TestCmp");
1640  }
1641
1642  private Class<?> testCmp;
1643}
1644