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