blob: 93fe397273435249b6c5ce29cf7f0a96565a5e9c [file] [log] [blame]
David Brazdilee690a32014-12-01 17:04:16 +00001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * 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 */
David Brazdilee690a32014-12-01 17:04:16 +000016
Roland Levillain31dd3d62016-02-16 12:21:02 +000017import java.lang.reflect.Method;
18
David Brazdil4846d132015-01-15 19:07:08 +000019public class Main {
David Brazdilee690a32014-12-01 17:04:16 +000020
Roland Levillain31dd3d62016-02-16 12:21:02 +000021 // Workaround for b/18051191.
22 class InnerClass {}
23
Roland Levillain3b55ebb2015-05-08 13:13:19 +010024 public static void assertFalse(boolean condition) {
25 if (condition) {
26 throw new Error();
27 }
28 }
29
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000030 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
Mark Mendelle82549b2015-05-06 10:55:34 -040042 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
Roland Levillainb65eb502015-07-23 12:11:42 +010054
Roland Levillain31dd3d62016-02-16 12:21:02 +000055 // 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
David Brazdilee690a32014-12-01 17:04:16 +0000117 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100118 * Exercise constant folding on negation.
David Brazdilee690a32014-12-01 17:04:16 +0000119 */
120
David Brazdila06d66a2015-05-28 11:14:54 +0100121 /// CHECK-START: int Main.IntNegation() constant_folding (before)
122 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
123 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Const42>>]
124 /// CHECK-DAG: Return [<<Neg>>]
David Brazdilee690a32014-12-01 17:04:16 +0000125
David Brazdila06d66a2015-05-28 11:14:54 +0100126 /// CHECK-START: int Main.IntNegation() constant_folding (after)
127 /// CHECK-DAG: <<ConstN42:i\d+>> IntConstant -42
128 /// CHECK-DAG: Return [<<ConstN42>>]
David Brazdilee690a32014-12-01 17:04:16 +0000129
Roland Levillainb65eb502015-07-23 12:11:42 +0100130 /// CHECK-START: int Main.IntNegation() constant_folding (after)
131 /// CHECK-NOT: Neg
132
David Brazdilee690a32014-12-01 17:04:16 +0000133 public static int IntNegation() {
134 int x, y;
135 x = 42;
136 y = -x;
137 return y;
138 }
139
Roland Levillainc90bc7c2014-12-11 12:14:33 +0000140 /// CHECK-START: long Main.LongNegation() constant_folding (before)
141 /// CHECK-DAG: <<Const42:j\d+>> LongConstant 42
142 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Const42>>]
143 /// CHECK-DAG: Return [<<Neg>>]
144
145 /// CHECK-START: long Main.LongNegation() constant_folding (after)
146 /// CHECK-DAG: <<ConstN42:j\d+>> LongConstant -42
147 /// CHECK-DAG: Return [<<ConstN42>>]
148
149 /// CHECK-START: long Main.LongNegation() constant_folding (after)
150 /// CHECK-NOT: Neg
151
152 public static long LongNegation() {
153 long x, y;
154 x = 42L;
155 y = -x;
156 return y;
157 }
158
Roland Levillain31dd3d62016-02-16 12:21:02 +0000159 /// CHECK-START: float Main.FloatNegation() constant_folding (before)
160 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
161 /// CHECK-DAG: <<Neg:f\d+>> Neg [<<Const42>>]
162 /// CHECK-DAG: Return [<<Neg>>]
163
164 /// CHECK-START: float Main.FloatNegation() constant_folding (after)
165 /// CHECK-DAG: <<ConstN42:f\d+>> FloatConstant -42
166 /// CHECK-DAG: Return [<<ConstN42>>]
167
168 /// CHECK-START: float Main.FloatNegation() constant_folding (after)
169 /// CHECK-NOT: Neg
170
171 public static float FloatNegation() {
172 float x, y;
173 x = 42F;
174 y = -x;
175 return y;
176 }
177
178 /// CHECK-START: double Main.DoubleNegation() constant_folding (before)
179 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
180 /// CHECK-DAG: <<Neg:d\d+>> Neg [<<Const42>>]
181 /// CHECK-DAG: Return [<<Neg>>]
182
183 /// CHECK-START: double Main.DoubleNegation() constant_folding (after)
184 /// CHECK-DAG: <<ConstN42:d\d+>> DoubleConstant -42
185 /// CHECK-DAG: Return [<<ConstN42>>]
186
187 /// CHECK-START: double Main.DoubleNegation() constant_folding (after)
188 /// CHECK-NOT: Neg
189
190 public static double DoubleNegation() {
191 double x, y;
192 x = 42D;
193 y = -x;
194 return y;
195 }
196
Roland Levillainb65eb502015-07-23 12:11:42 +0100197
David Brazdilee690a32014-12-01 17:04:16 +0000198 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100199 * Exercise constant folding on addition.
David Brazdilee690a32014-12-01 17:04:16 +0000200 */
201
David Brazdila06d66a2015-05-28 11:14:54 +0100202 /// CHECK-START: int Main.IntAddition1() constant_folding (before)
203 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
204 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
205 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const1>>,<<Const2>>]
206 /// CHECK-DAG: Return [<<Add>>]
David Brazdilee690a32014-12-01 17:04:16 +0000207
David Brazdila06d66a2015-05-28 11:14:54 +0100208 /// CHECK-START: int Main.IntAddition1() constant_folding (after)
209 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
210 /// CHECK-DAG: Return [<<Const3>>]
David Brazdilee690a32014-12-01 17:04:16 +0000211
Roland Levillainb65eb502015-07-23 12:11:42 +0100212 /// CHECK-START: int Main.IntAddition1() constant_folding (after)
213 /// CHECK-NOT: Add
214
David Brazdilee690a32014-12-01 17:04:16 +0000215 public static int IntAddition1() {
216 int a, b, c;
217 a = 1;
218 b = 2;
219 c = a + b;
220 return c;
221 }
222
David Brazdila06d66a2015-05-28 11:14:54 +0100223 /// CHECK-START: int Main.IntAddition2() constant_folding (before)
224 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
225 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
226 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
227 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
David Brazdil57e863c2016-01-11 10:27:13 +0000228 /// CHECK-DAG: <<Const11:i\d+>> IntConstant 11
David Brazdila06d66a2015-05-28 11:14:54 +0100229 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Const1>>,<<Const2>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000230 /// CHECK-DAG: Add [<<Const5>>,<<Const6>>]
231 /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add1>>,<<Const11>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100232 /// CHECK-DAG: Return [<<Add3>>]
David Brazdilee690a32014-12-01 17:04:16 +0000233
David Brazdila06d66a2015-05-28 11:14:54 +0100234 /// CHECK-START: int Main.IntAddition2() constant_folding (after)
235 /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14
236 /// CHECK-DAG: Return [<<Const14>>]
David Brazdilee690a32014-12-01 17:04:16 +0000237
Roland Levillainb65eb502015-07-23 12:11:42 +0100238 /// CHECK-START: int Main.IntAddition2() constant_folding (after)
239 /// CHECK-NOT: Add
240
David Brazdilee690a32014-12-01 17:04:16 +0000241 public static int IntAddition2() {
242 int a, b, c;
243 a = 1;
244 b = 2;
245 a += b;
246 b = 5;
247 c = 6;
248 b += c;
249 c = a + b;
250 return c;
251 }
252
Roland Levillainb65eb502015-07-23 12:11:42 +0100253 /// CHECK-START: long Main.LongAddition() constant_folding (before)
254 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
255 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
256 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const1>>,<<Const2>>]
257 /// CHECK-DAG: Return [<<Add>>]
258
259 /// CHECK-START: long Main.LongAddition() constant_folding (after)
260 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
261 /// CHECK-DAG: Return [<<Const3>>]
262
263 /// CHECK-START: long Main.LongAddition() constant_folding (after)
264 /// CHECK-NOT: Add
265
266 public static long LongAddition() {
267 long a, b, c;
268 a = 1L;
269 b = 2L;
270 c = a + b;
271 return c;
272 }
273
Roland Levillain31dd3d62016-02-16 12:21:02 +0000274 /// CHECK-START: float Main.FloatAddition() constant_folding (before)
275 /// CHECK-DAG: <<Const1:f\d+>> FloatConstant 1
276 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
277 /// CHECK-DAG: <<Add:f\d+>> Add [<<Const1>>,<<Const2>>]
278 /// CHECK-DAG: Return [<<Add>>]
279
280 /// CHECK-START: float Main.FloatAddition() constant_folding (after)
281 /// CHECK-DAG: <<Const3:f\d+>> FloatConstant 3
282 /// CHECK-DAG: Return [<<Const3>>]
283
284 /// CHECK-START: float Main.FloatAddition() constant_folding (after)
285 /// CHECK-NOT: Add
286
287 public static float FloatAddition() {
288 float a, b, c;
289 a = 1F;
290 b = 2F;
291 c = a + b;
292 return c;
293 }
294
295 /// CHECK-START: double Main.DoubleAddition() constant_folding (before)
296 /// CHECK-DAG: <<Const1:d\d+>> DoubleConstant 1
297 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
298 /// CHECK-DAG: <<Add:d\d+>> Add [<<Const1>>,<<Const2>>]
299 /// CHECK-DAG: Return [<<Add>>]
300
301 /// CHECK-START: double Main.DoubleAddition() constant_folding (after)
302 /// CHECK-DAG: <<Const3:d\d+>> DoubleConstant 3
303 /// CHECK-DAG: Return [<<Const3>>]
304
305 /// CHECK-START: double Main.DoubleAddition() constant_folding (after)
306 /// CHECK-NOT: Add
307
308 public static double DoubleAddition() {
309 double a, b, c;
310 a = 1D;
311 b = 2D;
312 c = a + b;
313 return c;
314 }
315
Roland Levillainb65eb502015-07-23 12:11:42 +0100316
David Brazdilee690a32014-12-01 17:04:16 +0000317 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100318 * Exercise constant folding on subtraction.
David Brazdilee690a32014-12-01 17:04:16 +0000319 */
320
David Brazdila06d66a2015-05-28 11:14:54 +0100321 /// CHECK-START: int Main.IntSubtraction() constant_folding (before)
322 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
323 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
324 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const6>>,<<Const2>>]
325 /// CHECK-DAG: Return [<<Sub>>]
David Brazdilee690a32014-12-01 17:04:16 +0000326
David Brazdila06d66a2015-05-28 11:14:54 +0100327 /// CHECK-START: int Main.IntSubtraction() constant_folding (after)
328 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
329 /// CHECK-DAG: Return [<<Const4>>]
David Brazdilee690a32014-12-01 17:04:16 +0000330
Roland Levillainb65eb502015-07-23 12:11:42 +0100331 /// CHECK-START: int Main.IntSubtraction() constant_folding (after)
332 /// CHECK-NOT: Sub
333
David Brazdilee690a32014-12-01 17:04:16 +0000334 public static int IntSubtraction() {
335 int a, b, c;
David Brazdil4846d132015-01-15 19:07:08 +0000336 a = 6;
David Brazdilee690a32014-12-01 17:04:16 +0000337 b = 2;
338 c = a - b;
339 return c;
340 }
341
David Brazdila06d66a2015-05-28 11:14:54 +0100342 /// CHECK-START: long Main.LongSubtraction() constant_folding (before)
343 /// CHECK-DAG: <<Const6:j\d+>> LongConstant 6
344 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
345 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const6>>,<<Const2>>]
346 /// CHECK-DAG: Return [<<Sub>>]
David Brazdilee690a32014-12-01 17:04:16 +0000347
David Brazdila06d66a2015-05-28 11:14:54 +0100348 /// CHECK-START: long Main.LongSubtraction() constant_folding (after)
349 /// CHECK-DAG: <<Const4:j\d+>> LongConstant 4
350 /// CHECK-DAG: Return [<<Const4>>]
David Brazdilee690a32014-12-01 17:04:16 +0000351
Roland Levillainb65eb502015-07-23 12:11:42 +0100352 /// CHECK-START: long Main.LongSubtraction() constant_folding (after)
353 /// CHECK-NOT: Sub
354
David Brazdilee690a32014-12-01 17:04:16 +0000355 public static long LongSubtraction() {
356 long a, b, c;
David Brazdil4846d132015-01-15 19:07:08 +0000357 a = 6L;
David Brazdilee690a32014-12-01 17:04:16 +0000358 b = 2L;
359 c = a - b;
360 return c;
361 }
362
Roland Levillain31dd3d62016-02-16 12:21:02 +0000363 /// CHECK-START: float Main.FloatSubtraction() constant_folding (before)
364 /// CHECK-DAG: <<Const6:f\d+>> FloatConstant 6
365 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
366 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<Const6>>,<<Const2>>]
367 /// CHECK-DAG: Return [<<Sub>>]
368
369 /// CHECK-START: float Main.FloatSubtraction() constant_folding (after)
370 /// CHECK-DAG: <<Const4:f\d+>> FloatConstant 4
371 /// CHECK-DAG: Return [<<Const4>>]
372
373 /// CHECK-START: float Main.FloatSubtraction() constant_folding (after)
374 /// CHECK-NOT: Sub
375
376 public static float FloatSubtraction() {
377 float a, b, c;
378 a = 6F;
379 b = 2F;
380 c = a - b;
381 return c;
382 }
383
384 /// CHECK-START: double Main.DoubleSubtraction() constant_folding (before)
385 /// CHECK-DAG: <<Const6:d\d+>> DoubleConstant 6
386 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
387 /// CHECK-DAG: <<Sub:d\d+>> Sub [<<Const6>>,<<Const2>>]
388 /// CHECK-DAG: Return [<<Sub>>]
389
390 /// CHECK-START: double Main.DoubleSubtraction() constant_folding (after)
391 /// CHECK-DAG: <<Const4:d\d+>> DoubleConstant 4
392 /// CHECK-DAG: Return [<<Const4>>]
393
394 /// CHECK-START: double Main.DoubleSubtraction() constant_folding (after)
395 /// CHECK-NOT: Sub
396
397 public static double DoubleSubtraction() {
398 double a, b, c;
399 a = 6D;
400 b = 2D;
401 c = a - b;
402 return c;
403 }
404
Roland Levillainb65eb502015-07-23 12:11:42 +0100405
David Brazdilee690a32014-12-01 17:04:16 +0000406 /**
Roland Levillainf7746ad2015-07-22 14:12:01 +0100407 * Exercise constant folding on multiplication.
408 */
409
410 /// CHECK-START: int Main.IntMultiplication() constant_folding (before)
411 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
412 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
413 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Const7>>,<<Const3>>]
414 /// CHECK-DAG: Return [<<Mul>>]
415
416 /// CHECK-START: int Main.IntMultiplication() constant_folding (after)
417 /// CHECK-DAG: <<Const21:i\d+>> IntConstant 21
418 /// CHECK-DAG: Return [<<Const21>>]
419
420 /// CHECK-START: int Main.IntMultiplication() constant_folding (after)
421 /// CHECK-NOT: Mul
422
423 public static int IntMultiplication() {
424 int a, b, c;
425 a = 7;
426 b = 3;
427 c = a * b;
428 return c;
429 }
430
431 /// CHECK-START: long Main.LongMultiplication() constant_folding (before)
432 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
433 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
434 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const7>>,<<Const3>>]
435 /// CHECK-DAG: Return [<<Mul>>]
436
437 /// CHECK-START: long Main.LongMultiplication() constant_folding (after)
438 /// CHECK-DAG: <<Const21:j\d+>> LongConstant 21
439 /// CHECK-DAG: Return [<<Const21>>]
440
441 /// CHECK-START: long Main.LongMultiplication() constant_folding (after)
442 /// CHECK-NOT: Mul
443
444 public static long LongMultiplication() {
445 long a, b, c;
446 a = 7L;
447 b = 3L;
448 c = a * b;
449 return c;
450 }
451
Roland Levillain31dd3d62016-02-16 12:21:02 +0000452 /// CHECK-START: float Main.FloatMultiplication() constant_folding (before)
453 /// CHECK-DAG: <<Const7:f\d+>> FloatConstant 7
454 /// CHECK-DAG: <<Const3:f\d+>> FloatConstant 3
455 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Const7>>,<<Const3>>]
456 /// CHECK-DAG: Return [<<Mul>>]
457
458 /// CHECK-START: float Main.FloatMultiplication() constant_folding (after)
459 /// CHECK-DAG: <<Const21:f\d+>> FloatConstant 21
460 /// CHECK-DAG: Return [<<Const21>>]
461
462 /// CHECK-START: float Main.FloatMultiplication() constant_folding (after)
463 /// CHECK-NOT: Mul
464
465 public static float FloatMultiplication() {
466 float a, b, c;
467 a = 7F;
468 b = 3F;
469 c = a * b;
470 return c;
471 }
472
473 /// CHECK-START: double Main.DoubleMultiplication() constant_folding (before)
474 /// CHECK-DAG: <<Const7:d\d+>> DoubleConstant 7
475 /// CHECK-DAG: <<Const3:d\d+>> DoubleConstant 3
476 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Const7>>,<<Const3>>]
477 /// CHECK-DAG: Return [<<Mul>>]
478
479 /// CHECK-START: double Main.DoubleMultiplication() constant_folding (after)
480 /// CHECK-DAG: <<Const21:d\d+>> DoubleConstant 21
481 /// CHECK-DAG: Return [<<Const21>>]
482
483 /// CHECK-START: double Main.DoubleMultiplication() constant_folding (after)
484 /// CHECK-NOT: Mul
485
486 public static double DoubleMultiplication() {
487 double a, b, c;
488 a = 7D;
489 b = 3D;
490 c = a * b;
491 return c;
492 }
493
Roland Levillainf7746ad2015-07-22 14:12:01 +0100494
495 /**
496 * Exercise constant folding on division.
497 */
498
499 /// CHECK-START: int Main.IntDivision() constant_folding (before)
500 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
501 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
502 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>]
503 /// CHECK-DAG: <<Div:i\d+>> Div [<<Const8>>,<<Div0Chk>>]
504 /// CHECK-DAG: Return [<<Div>>]
505
506 /// CHECK-START: int Main.IntDivision() constant_folding (after)
507 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
508 /// CHECK-DAG: Return [<<Const2>>]
509
510 /// CHECK-START: int Main.IntDivision() constant_folding (after)
511 /// CHECK-NOT: DivZeroCheck
512 /// CHECK-NOT: Div
513
514 public static int IntDivision() {
515 int a, b, c;
516 a = 8;
517 b = 3;
518 c = a / b;
519 return c;
520 }
521
522 /// CHECK-START: long Main.LongDivision() constant_folding (before)
523 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8
524 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
525 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>]
526 /// CHECK-DAG: <<Div:j\d+>> Div [<<Const8>>,<<Div0Chk>>]
527 /// CHECK-DAG: Return [<<Div>>]
528
529 /// CHECK-START: long Main.LongDivision() constant_folding (after)
530 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
531 /// CHECK-DAG: Return [<<Const2>>]
532
533 /// CHECK-START: long Main.LongDivision() constant_folding (after)
534 /// CHECK-NOT: DivZeroCheck
535 /// CHECK-NOT: Div
536
537 public static long LongDivision() {
538 long a, b, c;
539 a = 8L;
540 b = 3L;
541 c = a / b;
542 return c;
543 }
544
Roland Levillain31dd3d62016-02-16 12:21:02 +0000545 /// CHECK-START: float Main.FloatDivision() constant_folding (before)
546 /// CHECK-DAG: <<Const8:f\d+>> FloatConstant 8
547 /// CHECK-DAG: <<Const2P5:f\d+>> FloatConstant 2.5
548 /// CHECK-DAG: <<Div:f\d+>> Div [<<Const8>>,<<Const2P5>>]
549 /// CHECK-DAG: Return [<<Div>>]
550
551 /// CHECK-START: float Main.FloatDivision() constant_folding (after)
552 /// CHECK-DAG: <<Const3P2:f\d+>> FloatConstant 3.2
553 /// CHECK-DAG: Return [<<Const3P2>>]
554
555 /// CHECK-START: float Main.FloatDivision() constant_folding (after)
556 /// CHECK-NOT: Div
557
558 public static float FloatDivision() {
559 float a, b, c;
560 a = 8F;
561 b = 2.5F;
562 c = a / b;
563 return c;
564 }
565
566 /// CHECK-START: double Main.DoubleDivision() constant_folding (before)
567 /// CHECK-DAG: <<Const8:d\d+>> DoubleConstant 8
568 /// CHECK-DAG: <<Const2P5:d\d+>> DoubleConstant 2.5
569 /// CHECK-DAG: <<Div:d\d+>> Div [<<Const8>>,<<Const2P5>>]
570 /// CHECK-DAG: Return [<<Div>>]
571
572 /// CHECK-START: double Main.DoubleDivision() constant_folding (after)
573 /// CHECK-DAG: <<Const3P2:d\d+>> DoubleConstant 3.2
574 /// CHECK-DAG: Return [<<Const3P2>>]
575
576 /// CHECK-START: double Main.DoubleDivision() constant_folding (after)
577 /// CHECK-NOT: Div
578
579 public static double DoubleDivision() {
580 double a, b, c;
581 a = 8D;
582 b = 2.5D;
583 c = a / b;
584 return c;
585 }
586
Roland Levillainf7746ad2015-07-22 14:12:01 +0100587
588 /**
589 * Exercise constant folding on remainder.
590 */
591
592 /// CHECK-START: int Main.IntRemainder() constant_folding (before)
593 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
594 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
595 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>]
596 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Const8>>,<<Div0Chk>>]
597 /// CHECK-DAG: Return [<<Rem>>]
598
599 /// CHECK-START: int Main.IntRemainder() constant_folding (after)
600 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
601 /// CHECK-DAG: Return [<<Const2>>]
602
603 /// CHECK-START: int Main.IntRemainder() constant_folding (after)
604 /// CHECK-NOT: DivZeroCheck
605 /// CHECK-NOT: Rem
606
607 public static int IntRemainder() {
608 int a, b, c;
609 a = 8;
610 b = 3;
611 c = a % b;
612 return c;
613 }
614
615 /// CHECK-START: long Main.LongRemainder() constant_folding (before)
616 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8
617 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
618 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>]
619 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const8>>,<<Div0Chk>>]
620 /// CHECK-DAG: Return [<<Rem>>]
621
622 /// CHECK-START: long Main.LongRemainder() constant_folding (after)
623 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
624 /// CHECK-DAG: Return [<<Const2>>]
625
626 /// CHECK-START: long Main.LongRemainder() constant_folding (after)
627 /// CHECK-NOT: DivZeroCheck
628 /// CHECK-NOT: Rem
629
630 public static long LongRemainder() {
631 long a, b, c;
632 a = 8L;
633 b = 3L;
634 c = a % b;
635 return c;
636 }
637
Roland Levillain31dd3d62016-02-16 12:21:02 +0000638 /// CHECK-START: float Main.FloatRemainder() constant_folding (before)
639 /// CHECK-DAG: <<Const8:f\d+>> FloatConstant 8
640 /// CHECK-DAG: <<Const2P5:f\d+>> FloatConstant 2.5
641 /// CHECK-DAG: <<Rem:f\d+>> Rem [<<Const8>>,<<Const2P5>>]
642 /// CHECK-DAG: Return [<<Rem>>]
643
644 /// CHECK-START: float Main.FloatRemainder() constant_folding (after)
645 /// CHECK-DAG: <<Const0P5:f\d+>> FloatConstant 0.5
646 /// CHECK-DAG: Return [<<Const0P5>>]
647
648 /// CHECK-START: float Main.FloatRemainder() constant_folding (after)
649 /// CHECK-NOT: Rem
650
651 public static float FloatRemainder() {
652 float a, b, c;
653 a = 8F;
654 b = 2.5F;
655 c = a % b;
656 return c;
657 }
658
659 /// CHECK-START: double Main.DoubleRemainder() constant_folding (before)
660 /// CHECK-DAG: <<Const8:d\d+>> DoubleConstant 8
661 /// CHECK-DAG: <<Const2P5:d\d+>> DoubleConstant 2.5
662 /// CHECK-DAG: <<Rem:d\d+>> Rem [<<Const8>>,<<Const2P5>>]
663 /// CHECK-DAG: Return [<<Rem>>]
664
665 /// CHECK-START: double Main.DoubleRemainder() constant_folding (after)
666 /// CHECK-DAG: <<Const0P5:d\d+>> DoubleConstant 0.5
667 /// CHECK-DAG: Return [<<Const0P5>>]
668
669 /// CHECK-START: double Main.DoubleRemainder() constant_folding (after)
670 /// CHECK-NOT: Rem
671
672 public static double DoubleRemainder() {
673 double a, b, c;
674 a = 8D;
675 b = 2.5D;
676 c = a % b;
677 return c;
678 }
679
Roland Levillainf7746ad2015-07-22 14:12:01 +0100680
681 /**
Roland Levillain9867bc72015-08-05 10:21:34 +0100682 * Exercise constant folding on left shift.
683 */
684
685 /// CHECK-START: int Main.ShlIntLong() constant_folding (before)
686 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
687 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2
688 /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>]
689 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const1>>,<<TypeConv>>]
690 /// CHECK-DAG: Return [<<Shl>>]
691
692 /// CHECK-START: int Main.ShlIntLong() constant_folding (after)
693 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
694 /// CHECK-DAG: Return [<<Const4>>]
695
696 /// CHECK-START: int Main.ShlIntLong() constant_folding (after)
697 /// CHECK-NOT: Shl
698
699 public static int ShlIntLong() {
700 int lhs = 1;
701 long rhs = 2;
702 return lhs << rhs;
703 }
704
705 /// CHECK-START: long Main.ShlLongInt() constant_folding (before)
706 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3
707 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
708 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Const3L>>,<<Const2>>]
709 /// CHECK-DAG: Return [<<Shl>>]
710
711 /// CHECK-START: long Main.ShlLongInt() constant_folding (after)
712 /// CHECK-DAG: <<Const12L:j\d+>> LongConstant 12
713 /// CHECK-DAG: Return [<<Const12L>>]
714
715 /// CHECK-START: long Main.ShlLongInt() constant_folding (after)
716 /// CHECK-NOT: Shl
717
718 public static long ShlLongInt() {
719 long lhs = 3;
720 int rhs = 2;
721 return lhs << rhs;
722 }
723
724
725 /**
726 * Exercise constant folding on right shift.
727 */
728
729 /// CHECK-START: int Main.ShrIntLong() constant_folding (before)
730 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
731 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2
732 /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>]
733 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Const7>>,<<TypeConv>>]
734 /// CHECK-DAG: Return [<<Shr>>]
735
736 /// CHECK-START: int Main.ShrIntLong() constant_folding (after)
737 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
738 /// CHECK-DAG: Return [<<Const1>>]
739
740 /// CHECK-START: int Main.ShrIntLong() constant_folding (after)
741 /// CHECK-NOT: Shr
742
743 public static int ShrIntLong() {
744 int lhs = 7;
745 long rhs = 2;
746 return lhs >> rhs;
747 }
748
749 /// CHECK-START: long Main.ShrLongInt() constant_folding (before)
750 /// CHECK-DAG: <<Const9L:j\d+>> LongConstant 9
751 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
752 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const9L>>,<<Const2>>]
753 /// CHECK-DAG: Return [<<Shr>>]
754
755 /// CHECK-START: long Main.ShrLongInt() constant_folding (after)
756 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2
757 /// CHECK-DAG: Return [<<Const2L>>]
758
759 /// CHECK-START: long Main.ShrLongInt() constant_folding (after)
760 /// CHECK-NOT: Shr
761
762 public static long ShrLongInt() {
763 long lhs = 9;
764 int rhs = 2;
765 return lhs >> rhs;
766 }
767
768
769 /**
770 * Exercise constant folding on unsigned right shift.
771 */
772
773 /// CHECK-START: int Main.UShrIntLong() constant_folding (before)
774 /// CHECK-DAG: <<ConstM7:i\d+>> IntConstant -7
775 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2
776 /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>]
777 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<ConstM7>>,<<TypeConv>>]
778 /// CHECK-DAG: Return [<<UShr>>]
779
780 /// CHECK-START: int Main.UShrIntLong() constant_folding (after)
781 /// CHECK-DAG: <<ConstRes:i\d+>> IntConstant 1073741822
782 /// CHECK-DAG: Return [<<ConstRes>>]
783
784 /// CHECK-START: int Main.UShrIntLong() constant_folding (after)
785 /// CHECK-NOT: UShr
786
787 public static int UShrIntLong() {
788 int lhs = -7;
789 long rhs = 2;
790 return lhs >>> rhs;
791 }
792
793 /// CHECK-START: long Main.UShrLongInt() constant_folding (before)
794 /// CHECK-DAG: <<ConstM9L:j\d+>> LongConstant -9
795 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
796 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<ConstM9L>>,<<Const2>>]
797 /// CHECK-DAG: Return [<<UShr>>]
798
799 /// CHECK-START: long Main.UShrLongInt() constant_folding (after)
800 /// CHECK-DAG: <<ConstRes:j\d+>> LongConstant 4611686018427387901
801 /// CHECK-DAG: Return [<<ConstRes>>]
802
803 /// CHECK-START: long Main.UShrLongInt() constant_folding (after)
804 /// CHECK-NOT: UShr
805
806 public static long UShrLongInt() {
807 long lhs = -9;
808 int rhs = 2;
809 return lhs >>> rhs;
810 }
811
812
813 /**
814 * Exercise constant folding on logical and.
815 */
816
817 /// CHECK-START: long Main.AndIntLong() constant_folding (before)
818 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10
819 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3
820 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>]
821 /// CHECK-DAG: <<And:j\d+>> And [<<TypeConv>>,<<Const3L>>]
822 /// CHECK-DAG: Return [<<And>>]
823
824 /// CHECK-START: long Main.AndIntLong() constant_folding (after)
825 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
826 /// CHECK-DAG: Return [<<Const2>>]
827
828 /// CHECK-START: long Main.AndIntLong() constant_folding (after)
829 /// CHECK-NOT: And
830
831 public static long AndIntLong() {
832 int lhs = 10;
833 long rhs = 3;
834 return lhs & rhs;
835 }
836
837 /// CHECK-START: long Main.AndLongInt() constant_folding (before)
838 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10
839 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
840 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000841 /// CHECK-DAG: <<And:j\d+>> And [<<TypeConv>>,<<Const10L>>]
Roland Levillain9867bc72015-08-05 10:21:34 +0100842 /// CHECK-DAG: Return [<<And>>]
843
844 /// CHECK-START: long Main.AndLongInt() constant_folding (after)
845 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
846 /// CHECK-DAG: Return [<<Const2>>]
847
848 /// CHECK-START: long Main.AndLongInt() constant_folding (after)
849 /// CHECK-NOT: And
850
851 public static long AndLongInt() {
852 long lhs = 10;
853 int rhs = 3;
854 return lhs & rhs;
855 }
856
857
858 /**
859 * Exercise constant folding on logical or.
860 */
861
862 /// CHECK-START: long Main.OrIntLong() constant_folding (before)
863 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10
864 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3
865 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>]
866 /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const3L>>]
867 /// CHECK-DAG: Return [<<Or>>]
868
869 /// CHECK-START: long Main.OrIntLong() constant_folding (after)
870 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11
871 /// CHECK-DAG: Return [<<Const11>>]
872
873 /// CHECK-START: long Main.OrIntLong() constant_folding (after)
874 /// CHECK-NOT: Or
875
876 public static long OrIntLong() {
877 int lhs = 10;
878 long rhs = 3;
879 return lhs | rhs;
880 }
881
882 /// CHECK-START: long Main.OrLongInt() constant_folding (before)
883 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10
884 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
885 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000886 /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const10L>>]
Roland Levillain9867bc72015-08-05 10:21:34 +0100887 /// CHECK-DAG: Return [<<Or>>]
888
889 /// CHECK-START: long Main.OrLongInt() constant_folding (after)
890 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11
891 /// CHECK-DAG: Return [<<Const11>>]
892
893 /// CHECK-START: long Main.OrLongInt() constant_folding (after)
894 /// CHECK-NOT: Or
895
896 public static long OrLongInt() {
897 long lhs = 10;
898 int rhs = 3;
899 return lhs | rhs;
900 }
901
902
903 /**
904 * Exercise constant folding on logical exclusive or.
905 */
906
907 /// CHECK-START: long Main.XorIntLong() constant_folding (before)
908 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10
909 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3
910 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>]
911 /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const3L>>]
912 /// CHECK-DAG: Return [<<Xor>>]
913
914 /// CHECK-START: long Main.XorIntLong() constant_folding (after)
915 /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9
916 /// CHECK-DAG: Return [<<Const9>>]
917
918 /// CHECK-START: long Main.XorIntLong() constant_folding (after)
919 /// CHECK-NOT: Xor
920
921 public static long XorIntLong() {
922 int lhs = 10;
923 long rhs = 3;
924 return lhs ^ rhs;
925 }
926
927 /// CHECK-START: long Main.XorLongInt() constant_folding (before)
928 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10
929 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
930 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000931 /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const10L>>]
Roland Levillain9867bc72015-08-05 10:21:34 +0100932 /// CHECK-DAG: Return [<<Xor>>]
933
934 /// CHECK-START: long Main.XorLongInt() constant_folding (after)
935 /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9
936 /// CHECK-DAG: Return [<<Const9>>]
937
938 /// CHECK-START: long Main.XorLongInt() constant_folding (after)
939 /// CHECK-NOT: Xor
940
941 public static long XorLongInt() {
942 long lhs = 10;
943 int rhs = 3;
944 return lhs ^ rhs;
945 }
946
947
948 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100949 * Exercise constant folding on constant (static) condition.
David Brazdilee690a32014-12-01 17:04:16 +0000950 */
951
David Brazdila06d66a2015-05-28 11:14:54 +0100952 /// CHECK-START: int Main.StaticCondition() constant_folding (before)
953 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
954 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
955 /// CHECK-DAG: <<Cond:z\d+>> GreaterThanOrEqual [<<Const7>>,<<Const2>>]
956 /// CHECK-DAG: If [<<Cond>>]
David Brazdilee690a32014-12-01 17:04:16 +0000957
David Brazdila06d66a2015-05-28 11:14:54 +0100958 /// CHECK-START: int Main.StaticCondition() constant_folding (after)
959 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
960 /// CHECK-DAG: If [<<Const1>>]
David Brazdilee690a32014-12-01 17:04:16 +0000961
Roland Levillainb65eb502015-07-23 12:11:42 +0100962 /// CHECK-START: int Main.StaticCondition() constant_folding (after)
963 /// CHECK-NOT: GreaterThanOrEqual
964
David Brazdilee690a32014-12-01 17:04:16 +0000965 public static int StaticCondition() {
966 int a, b, c;
David Brazdil4846d132015-01-15 19:07:08 +0000967 a = 7;
David Brazdilee690a32014-12-01 17:04:16 +0000968 b = 2;
969 if (a < b)
970 c = a + b;
971 else
972 c = a - b;
973 return c;
974 }
975
Roland Levillainb65eb502015-07-23 12:11:42 +0100976
David Brazdilee690a32014-12-01 17:04:16 +0000977 /**
Vladimir Marko9e23df52015-11-10 17:14:35 +0000978 * Exercise constant folding on constant (static) condition for null references.
979 */
980
981 /// CHECK-START: int Main.StaticConditionNulls() constant_folding_after_inlining (before)
982 /// CHECK-DAG: <<Null:l\d+>> NullConstant
983 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Null>>,<<Null>>]
David Brazdil74eb1b22015-12-14 11:44:01 +0000984 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Cond>>]
Vladimir Marko9e23df52015-11-10 17:14:35 +0000985
986 /// CHECK-START: int Main.StaticConditionNulls() constant_folding_after_inlining (after)
987 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +0000988 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Const0>>]
Vladimir Marko9e23df52015-11-10 17:14:35 +0000989
990 /// CHECK-START: int Main.StaticConditionNulls() constant_folding_after_inlining (after)
991 /// CHECK-NOT: NotEqual
992
993 private static Object getNull() {
994 return null;
995 }
996
997 public static int StaticConditionNulls() {
998 Object a = getNull();
999 Object b = getNull();
1000 return (a == b) ? 5 : 2;
1001 }
1002
1003
1004 /**
Roland Levillainb65eb502015-07-23 12:11:42 +01001005 * Exercise constant folding on a program with condition
1006 * (i.e. jumps) leading to the creation of many blocks.
David Brazdilee690a32014-12-01 17:04:16 +00001007 *
1008 * The intent of this test is to ensure that all constant expressions
1009 * are actually evaluated at compile-time, thanks to the reverse
1010 * (forward) post-order traversal of the the dominator tree.
1011 */
1012
David Brazdila06d66a2015-05-28 11:14:54 +01001013 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (before)
1014 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
1015 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1016 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const5>>,<<Const2>>]
1017 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<Const2>>]
1018 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Add>>,<<Sub>>]
1019 /// CHECK-DAG: Return [<<Phi>>]
David Brazdilee690a32014-12-01 17:04:16 +00001020
David Brazdila06d66a2015-05-28 11:14:54 +01001021 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after)
1022 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1023 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
1024 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const7>>,<<Const3>>]
1025 /// CHECK-DAG: Return [<<Phi>>]
David Brazdilee690a32014-12-01 17:04:16 +00001026
Roland Levillainb65eb502015-07-23 12:11:42 +01001027 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after)
1028 /// CHECK-NOT: Add
1029 /// CHECK-NOT: Sub
1030
David Brazdilee690a32014-12-01 17:04:16 +00001031 public static int JumpsAndConditionals(boolean cond) {
1032 int a, b, c;
1033 a = 5;
1034 b = 2;
1035 if (cond)
1036 c = a + b;
1037 else
1038 c = a - b;
1039 return c;
1040 }
David Brazdil4846d132015-01-15 19:07:08 +00001041
Roland Levillainb65eb502015-07-23 12:11:42 +01001042
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001043 /**
1044 * Test optimizations of arithmetic identities yielding a constant result.
1045 */
1046
David Brazdila06d66a2015-05-28 11:14:54 +01001047 /// CHECK-START: int Main.And0(int) constant_folding (before)
1048 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1049 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1050 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const0>>]
1051 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001052
David Brazdila06d66a2015-05-28 11:14:54 +01001053 /// CHECK-START: int Main.And0(int) constant_folding (after)
1054 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1055 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001056 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001057
Roland Levillainb65eb502015-07-23 12:11:42 +01001058 /// CHECK-START: int Main.And0(int) constant_folding (after)
1059 /// CHECK-NOT: And
1060
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001061 public static int And0(int arg) {
1062 return arg & 0;
1063 }
1064
David Brazdila06d66a2015-05-28 11:14:54 +01001065 /// CHECK-START: long Main.Mul0(long) constant_folding (before)
1066 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1067 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdil57e863c2016-01-11 10:27:13 +00001068 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const0>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001069 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001070
David Brazdila06d66a2015-05-28 11:14:54 +01001071 /// CHECK-START: long Main.Mul0(long) constant_folding (after)
1072 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1073 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001074 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001075
Roland Levillainb65eb502015-07-23 12:11:42 +01001076 /// CHECK-START: long Main.Mul0(long) constant_folding (after)
1077 /// CHECK-NOT: Mul
1078
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001079 public static long Mul0(long arg) {
1080 return arg * 0;
1081 }
1082
David Brazdila06d66a2015-05-28 11:14:54 +01001083 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (before)
1084 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1085 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
1086 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<ConstF>>]
1087 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001088
David Brazdila06d66a2015-05-28 11:14:54 +01001089 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
1090 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
David Brazdila06d66a2015-05-28 11:14:54 +01001091 /// CHECK-DAG: Return [<<ConstF>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001092
Roland Levillainb65eb502015-07-23 12:11:42 +01001093 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
1094 /// CHECK-NOT: Or
1095
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001096 public static int OrAllOnes(int arg) {
1097 return arg | -1;
1098 }
1099
David Brazdila06d66a2015-05-28 11:14:54 +01001100 /// CHECK-START: long Main.Rem0(long) constant_folding (before)
1101 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1102 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
1103 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<Arg>>]
1104 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const0>>,<<DivZeroCheck>>]
1105 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001106
David Brazdila06d66a2015-05-28 11:14:54 +01001107 /// CHECK-START: long Main.Rem0(long) constant_folding (after)
1108 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001109 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001110
Roland Levillainb65eb502015-07-23 12:11:42 +01001111 /// CHECK-START: long Main.Rem0(long) constant_folding (after)
1112 /// CHECK-NOT: Rem
1113
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001114 public static long Rem0(long arg) {
1115 return 0 % arg;
1116 }
1117
David Brazdila06d66a2015-05-28 11:14:54 +01001118 /// CHECK-START: int Main.Rem1(int) constant_folding (before)
1119 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1120 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1121 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Arg>>,<<Const1>>]
1122 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001123
David Brazdila06d66a2015-05-28 11:14:54 +01001124 /// CHECK-START: int Main.Rem1(int) constant_folding (after)
1125 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001126 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001127
Roland Levillainb65eb502015-07-23 12:11:42 +01001128 /// CHECK-START: int Main.Rem1(int) constant_folding (after)
1129 /// CHECK-NOT: Rem
1130
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001131 public static int Rem1(int arg) {
1132 return arg % 1;
1133 }
1134
David Brazdila06d66a2015-05-28 11:14:54 +01001135 /// CHECK-START: long Main.RemN1(long) constant_folding (before)
1136 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1137 /// CHECK-DAG: <<ConstN1:j\d+>> LongConstant -1
1138 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<ConstN1>>]
1139 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Arg>>,<<DivZeroCheck>>]
1140 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001141
David Brazdila06d66a2015-05-28 11:14:54 +01001142 /// CHECK-START: long Main.RemN1(long) constant_folding (after)
1143 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001144 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001145
Roland Levillainb65eb502015-07-23 12:11:42 +01001146 /// CHECK-START: long Main.RemN1(long) constant_folding (after)
1147 /// CHECK-NOT: Rem
1148
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001149 public static long RemN1(long arg) {
1150 return arg % -1;
1151 }
1152
David Brazdila06d66a2015-05-28 11:14:54 +01001153 /// CHECK-START: int Main.Shl0(int) constant_folding (before)
1154 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1155 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1156 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const0>>,<<Arg>>]
1157 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001158
David Brazdila06d66a2015-05-28 11:14:54 +01001159 /// CHECK-START: int Main.Shl0(int) constant_folding (after)
1160 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1161 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001162 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001163
Roland Levillainb65eb502015-07-23 12:11:42 +01001164 /// CHECK-START: int Main.Shl0(int) constant_folding (after)
1165 /// CHECK-NOT: Shl
1166
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001167 public static int Shl0(int arg) {
1168 return 0 << arg;
1169 }
1170
Roland Levillain9867bc72015-08-05 10:21:34 +01001171 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (before)
1172 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1173 /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0
1174 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Const0L>>,<<Arg>>]
1175 /// CHECK-DAG: Return [<<Shl>>]
1176
1177 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after)
1178 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1179 /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0
1180 /// CHECK-DAG: Return [<<Const0L>>]
1181
1182 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after)
1183 /// CHECK-NOT: Shl
1184
1185 public static long ShlLong0WithInt(int arg) {
1186 long long_zero = 0;
1187 return long_zero << arg;
1188 }
1189
David Brazdila06d66a2015-05-28 11:14:54 +01001190 /// CHECK-START: long Main.Shr0(int) constant_folding (before)
1191 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1192 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
1193 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const0>>,<<Arg>>]
1194 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001195
David Brazdila06d66a2015-05-28 11:14:54 +01001196 /// CHECK-START: long Main.Shr0(int) constant_folding (after)
1197 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1198 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001199 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001200
Roland Levillainb65eb502015-07-23 12:11:42 +01001201 /// CHECK-START: long Main.Shr0(int) constant_folding (after)
1202 /// CHECK-NOT: Shr
1203
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001204 public static long Shr0(int arg) {
1205 return (long)0 >> arg;
1206 }
1207
David Brazdila06d66a2015-05-28 11:14:54 +01001208 /// CHECK-START: long Main.SubSameLong(long) constant_folding (before)
1209 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1210 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Arg>>]
1211 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001212
David Brazdila06d66a2015-05-28 11:14:54 +01001213 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
1214 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1215 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001216 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001217
Roland Levillainb65eb502015-07-23 12:11:42 +01001218 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
1219 /// CHECK-NOT: Sub
1220
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001221 public static long SubSameLong(long arg) {
1222 return arg - arg;
1223 }
1224
David Brazdila06d66a2015-05-28 11:14:54 +01001225 /// CHECK-START: int Main.UShr0(int) constant_folding (before)
1226 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1227 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1228 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Const0>>,<<Arg>>]
1229 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001230
David Brazdila06d66a2015-05-28 11:14:54 +01001231 /// CHECK-START: int Main.UShr0(int) constant_folding (after)
1232 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1233 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001234 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001235
Roland Levillainb65eb502015-07-23 12:11:42 +01001236 /// CHECK-START: int Main.UShr0(int) constant_folding (after)
1237 /// CHECK-NOT: UShr
1238
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001239 public static int UShr0(int arg) {
1240 return 0 >>> arg;
1241 }
1242
David Brazdila06d66a2015-05-28 11:14:54 +01001243 /// CHECK-START: int Main.XorSameInt(int) constant_folding (before)
1244 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1245 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Arg>>]
1246 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001247
David Brazdila06d66a2015-05-28 11:14:54 +01001248 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
1249 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1250 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001251 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001252
Roland Levillainb65eb502015-07-23 12:11:42 +01001253 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
1254 /// CHECK-NOT: Xor
1255
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001256 public static int XorSameInt(int arg) {
1257 return arg ^ arg;
1258 }
1259
David Brazdila06d66a2015-05-28 11:14:54 +01001260 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (before)
1261 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1262 /// CHECK-DAG: <<ConstNan:f\d+>> FloatConstant nan
1263 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1264 /// CHECK-DAG: IntConstant 1
1265 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>]
1266 /// CHECK-DAG: <<Le:z\d+>> LessThanOrEqual [<<Cmp>>,<<Const0>>]
1267 /// CHECK-DAG: If [<<Le>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001268
David Brazdila06d66a2015-05-28 11:14:54 +01001269 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
1270 /// CHECK-DAG: ParameterValue
1271 /// CHECK-DAG: FloatConstant nan
1272 /// CHECK-DAG: IntConstant 0
1273 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1274 /// CHECK-DAG: If [<<Const1>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001275
David Brazdila06d66a2015-05-28 11:14:54 +01001276 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
1277 /// CHECK-NOT: Compare
1278 /// CHECK-NOT: LessThanOrEqual
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001279
1280 public static boolean CmpFloatGreaterThanNaN(float arg) {
1281 return arg > Float.NaN;
1282 }
1283
David Brazdila06d66a2015-05-28 11:14:54 +01001284 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (before)
1285 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1286 /// CHECK-DAG: <<ConstNan:d\d+>> DoubleConstant nan
1287 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1288 /// CHECK-DAG: IntConstant 1
1289 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>]
1290 /// CHECK-DAG: <<Ge:z\d+>> GreaterThanOrEqual [<<Cmp>>,<<Const0>>]
1291 /// CHECK-DAG: If [<<Ge>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001292
David Brazdila06d66a2015-05-28 11:14:54 +01001293 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
1294 /// CHECK-DAG: ParameterValue
1295 /// CHECK-DAG: DoubleConstant nan
1296 /// CHECK-DAG: IntConstant 0
1297 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1298 /// CHECK-DAG: If [<<Const1>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001299
David Brazdila06d66a2015-05-28 11:14:54 +01001300 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
1301 /// CHECK-NOT: Compare
1302 /// CHECK-NOT: GreaterThanOrEqual
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001303
1304 public static boolean CmpDoubleLessThanNaN(double arg) {
1305 return arg < Double.NaN;
1306 }
1307
Roland Levillainb65eb502015-07-23 12:11:42 +01001308
1309 /**
1310 * Exercise constant folding on type conversions.
1311 */
1312
David Brazdila06d66a2015-05-28 11:14:54 +01001313 /// CHECK-START: int Main.ReturnInt33() constant_folding (before)
1314 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
1315 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<Const33>>]
1316 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001317
David Brazdila06d66a2015-05-28 11:14:54 +01001318 /// CHECK-START: int Main.ReturnInt33() constant_folding (after)
1319 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
1320 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001321
Roland Levillainb65eb502015-07-23 12:11:42 +01001322 /// CHECK-START: int Main.ReturnInt33() constant_folding (after)
1323 /// CHECK-NOT: TypeConversion
1324
Mark Mendelle82549b2015-05-06 10:55:34 -04001325 public static int ReturnInt33() {
1326 long imm = 33L;
1327 return (int) imm;
1328 }
1329
David Brazdila06d66a2015-05-28 11:14:54 +01001330 /// CHECK-START: int Main.ReturnIntMax() constant_folding (before)
1331 /// CHECK-DAG: <<ConstMax:f\d+>> FloatConstant 1e+34
1332 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstMax>>]
1333 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001334
David Brazdila06d66a2015-05-28 11:14:54 +01001335 /// CHECK-START: int Main.ReturnIntMax() constant_folding (after)
1336 /// CHECK-DAG: <<ConstMax:i\d+>> IntConstant 2147483647
1337 /// CHECK-DAG: Return [<<ConstMax>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001338
Roland Levillainb65eb502015-07-23 12:11:42 +01001339 /// CHECK-START: int Main.ReturnIntMax() constant_folding (after)
1340 /// CHECK-NOT: TypeConversion
1341
Mark Mendelle82549b2015-05-06 10:55:34 -04001342 public static int ReturnIntMax() {
1343 float imm = 1.0e34f;
1344 return (int) imm;
1345 }
1346
David Brazdila06d66a2015-05-28 11:14:54 +01001347 /// CHECK-START: int Main.ReturnInt0() constant_folding (before)
1348 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan
1349 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstNaN>>]
1350 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001351
David Brazdila06d66a2015-05-28 11:14:54 +01001352 /// CHECK-START: int Main.ReturnInt0() constant_folding (after)
1353 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1354 /// CHECK-DAG: Return [<<Const0>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001355
Roland Levillainb65eb502015-07-23 12:11:42 +01001356 /// CHECK-START: int Main.ReturnInt0() constant_folding (after)
1357 /// CHECK-NOT: TypeConversion
1358
Mark Mendelle82549b2015-05-06 10:55:34 -04001359 public static int ReturnInt0() {
1360 double imm = Double.NaN;
1361 return (int) imm;
1362 }
1363
David Brazdila06d66a2015-05-28 11:14:54 +01001364 /// CHECK-START: long Main.ReturnLong33() constant_folding (before)
1365 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
1366 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const33>>]
1367 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001368
David Brazdila06d66a2015-05-28 11:14:54 +01001369 /// CHECK-START: long Main.ReturnLong33() constant_folding (after)
1370 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
1371 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001372
Roland Levillainb65eb502015-07-23 12:11:42 +01001373 /// CHECK-START: long Main.ReturnLong33() constant_folding (after)
1374 /// CHECK-NOT: TypeConversion
1375
Mark Mendelle82549b2015-05-06 10:55:34 -04001376 public static long ReturnLong33() {
1377 int imm = 33;
1378 return (long) imm;
1379 }
1380
David Brazdila06d66a2015-05-28 11:14:54 +01001381 /// CHECK-START: long Main.ReturnLong34() constant_folding (before)
1382 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34
1383 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const34>>]
1384 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001385
David Brazdila06d66a2015-05-28 11:14:54 +01001386 /// CHECK-START: long Main.ReturnLong34() constant_folding (after)
1387 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
1388 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001389
Roland Levillainb65eb502015-07-23 12:11:42 +01001390 /// CHECK-START: long Main.ReturnLong34() constant_folding (after)
1391 /// CHECK-NOT: TypeConversion
1392
Mark Mendelle82549b2015-05-06 10:55:34 -04001393 public static long ReturnLong34() {
1394 float imm = 34.0f;
1395 return (long) imm;
1396 }
1397
David Brazdila06d66a2015-05-28 11:14:54 +01001398 /// CHECK-START: long Main.ReturnLong0() constant_folding (before)
1399 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan
1400 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<ConstNaN>>]
1401 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001402
David Brazdila06d66a2015-05-28 11:14:54 +01001403 /// CHECK-START: long Main.ReturnLong0() constant_folding (after)
1404 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
1405 /// CHECK-DAG: Return [<<Const0>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001406
Roland Levillainb65eb502015-07-23 12:11:42 +01001407 /// CHECK-START: long Main.ReturnLong0() constant_folding (after)
1408 /// CHECK-NOT: TypeConversion
1409
Mark Mendelle82549b2015-05-06 10:55:34 -04001410 public static long ReturnLong0() {
1411 double imm = -Double.NaN;
1412 return (long) imm;
1413 }
1414
David Brazdila06d66a2015-05-28 11:14:54 +01001415 /// CHECK-START: float Main.ReturnFloat33() constant_folding (before)
1416 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
1417 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const33>>]
1418 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001419
David Brazdila06d66a2015-05-28 11:14:54 +01001420 /// CHECK-START: float Main.ReturnFloat33() constant_folding (after)
1421 /// CHECK-DAG: <<Const33:f\d+>> FloatConstant 33
1422 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001423
Roland Levillainb65eb502015-07-23 12:11:42 +01001424 /// CHECK-START: float Main.ReturnFloat33() constant_folding (after)
1425 /// CHECK-NOT: TypeConversion
1426
Mark Mendelle82549b2015-05-06 10:55:34 -04001427 public static float ReturnFloat33() {
1428 int imm = 33;
1429 return (float) imm;
1430 }
1431
David Brazdila06d66a2015-05-28 11:14:54 +01001432 /// CHECK-START: float Main.ReturnFloat34() constant_folding (before)
1433 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
1434 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const34>>]
1435 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001436
David Brazdila06d66a2015-05-28 11:14:54 +01001437 /// CHECK-START: float Main.ReturnFloat34() constant_folding (after)
1438 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34
1439 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001440
Roland Levillainb65eb502015-07-23 12:11:42 +01001441 /// CHECK-START: float Main.ReturnFloat34() constant_folding (after)
1442 /// CHECK-NOT: TypeConversion
1443
Mark Mendelle82549b2015-05-06 10:55:34 -04001444 public static float ReturnFloat34() {
1445 long imm = 34L;
1446 return (float) imm;
1447 }
1448
David Brazdila06d66a2015-05-28 11:14:54 +01001449 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (before)
1450 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25
1451 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const>>]
1452 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001453
David Brazdila06d66a2015-05-28 11:14:54 +01001454 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after)
1455 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25
1456 /// CHECK-DAG: Return [<<Const>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001457
Roland Levillainb65eb502015-07-23 12:11:42 +01001458 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after)
1459 /// CHECK-NOT: TypeConversion
1460
Mark Mendelle82549b2015-05-06 10:55:34 -04001461 public static float ReturnFloat99P25() {
1462 double imm = 99.25;
1463 return (float) imm;
1464 }
1465
David Brazdila06d66a2015-05-28 11:14:54 +01001466 /// CHECK-START: double Main.ReturnDouble33() constant_folding (before)
1467 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
1468 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const33>>]
1469 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001470
David Brazdila06d66a2015-05-28 11:14:54 +01001471 /// CHECK-START: double Main.ReturnDouble33() constant_folding (after)
1472 /// CHECK-DAG: <<Const33:d\d+>> DoubleConstant 33
1473 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001474
1475 public static double ReturnDouble33() {
1476 int imm = 33;
1477 return (double) imm;
1478 }
1479
David Brazdila06d66a2015-05-28 11:14:54 +01001480 /// CHECK-START: double Main.ReturnDouble34() constant_folding (before)
1481 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
1482 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const34>>]
1483 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001484
David Brazdila06d66a2015-05-28 11:14:54 +01001485 /// CHECK-START: double Main.ReturnDouble34() constant_folding (after)
1486 /// CHECK-DAG: <<Const34:d\d+>> DoubleConstant 34
1487 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001488
Roland Levillainb65eb502015-07-23 12:11:42 +01001489 /// CHECK-START: double Main.ReturnDouble34() constant_folding (after)
1490 /// CHECK-NOT: TypeConversion
1491
Mark Mendelle82549b2015-05-06 10:55:34 -04001492 public static double ReturnDouble34() {
1493 long imm = 34L;
1494 return (double) imm;
1495 }
1496
David Brazdila06d66a2015-05-28 11:14:54 +01001497 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (before)
1498 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25
1499 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const>>]
1500 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001501
David Brazdila06d66a2015-05-28 11:14:54 +01001502 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after)
1503 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25
1504 /// CHECK-DAG: Return [<<Const>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001505
Roland Levillainb65eb502015-07-23 12:11:42 +01001506 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after)
1507 /// CHECK-NOT: TypeConversion
1508
Mark Mendelle82549b2015-05-06 10:55:34 -04001509 public static double ReturnDouble99P25() {
1510 float imm = 99.25f;
1511 return (double) imm;
1512 }
1513
Roland Levillainb65eb502015-07-23 12:11:42 +01001514
Roland Levillain31dd3d62016-02-16 12:21:02 +00001515 public static void main(String[] args) throws Exception {
Roland Levillainb65eb502015-07-23 12:11:42 +01001516 assertIntEquals(-42, IntNegation());
Roland Levillainc90bc7c2014-12-11 12:14:33 +00001517 assertLongEquals(-42L, LongNegation());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001518 assertFloatEquals(-42F, FloatNegation());
1519 assertDoubleEquals(-42D, DoubleNegation());
Roland Levillainb65eb502015-07-23 12:11:42 +01001520
1521 assertIntEquals(3, IntAddition1());
1522 assertIntEquals(14, IntAddition2());
1523 assertLongEquals(3L, LongAddition());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001524 assertFloatEquals(3F, FloatAddition());
1525 assertDoubleEquals(3D, DoubleAddition());
Roland Levillainb65eb502015-07-23 12:11:42 +01001526
1527 assertIntEquals(4, IntSubtraction());
1528 assertLongEquals(4L, LongSubtraction());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001529 assertFloatEquals(4F, FloatSubtraction());
1530 assertDoubleEquals(4D, DoubleSubtraction());
Roland Levillainb65eb502015-07-23 12:11:42 +01001531
Roland Levillainf7746ad2015-07-22 14:12:01 +01001532 assertIntEquals(21, IntMultiplication());
1533 assertLongEquals(21L, LongMultiplication());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001534 assertFloatEquals(21F, FloatMultiplication());
1535 assertDoubleEquals(21D, DoubleMultiplication());
Roland Levillainf7746ad2015-07-22 14:12:01 +01001536
1537 assertIntEquals(2, IntDivision());
1538 assertLongEquals(2L, LongDivision());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001539 assertFloatEquals(3.2F, FloatDivision());
1540 assertDoubleEquals(3.2D, DoubleDivision());
Roland Levillainf7746ad2015-07-22 14:12:01 +01001541
1542 assertIntEquals(2, IntRemainder());
1543 assertLongEquals(2L, LongRemainder());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001544 assertFloatEquals(0.5F, FloatRemainder());
1545 assertDoubleEquals(0.5D, DoubleRemainder());
Roland Levillainf7746ad2015-07-22 14:12:01 +01001546
Roland Levillain9867bc72015-08-05 10:21:34 +01001547 assertIntEquals(4, ShlIntLong());
1548 assertLongEquals(12L, ShlLongInt());
1549
1550 assertIntEquals(1, ShrIntLong());
1551 assertLongEquals(2L, ShrLongInt());
1552
1553 assertIntEquals(1073741822, UShrIntLong());
1554 assertLongEquals(4611686018427387901L, UShrLongInt());
1555
1556 assertLongEquals(2, AndIntLong());
1557 assertLongEquals(2, AndLongInt());
1558
1559 assertLongEquals(11, OrIntLong());
1560 assertLongEquals(11, OrLongInt());
1561
1562 assertLongEquals(9, XorIntLong());
1563 assertLongEquals(9, XorLongInt());
1564
Roland Levillainb65eb502015-07-23 12:11:42 +01001565 assertIntEquals(5, StaticCondition());
Vladimir Marko9e23df52015-11-10 17:14:35 +00001566 assertIntEquals(5, StaticConditionNulls());
Roland Levillainb65eb502015-07-23 12:11:42 +01001567
1568 assertIntEquals(7, JumpsAndConditionals(true));
1569 assertIntEquals(3, JumpsAndConditionals(false));
1570
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001571 int arbitrary = 123456; // Value chosen arbitrarily.
Roland Levillainb65eb502015-07-23 12:11:42 +01001572
1573 assertIntEquals(0, And0(arbitrary));
1574 assertLongEquals(0, Mul0(arbitrary));
1575 assertIntEquals(-1, OrAllOnes(arbitrary));
1576 assertLongEquals(0, Rem0(arbitrary));
1577 assertIntEquals(0, Rem1(arbitrary));
1578 assertLongEquals(0, RemN1(arbitrary));
1579 assertIntEquals(0, Shl0(arbitrary));
Roland Levillain9867bc72015-08-05 10:21:34 +01001580 assertLongEquals(0, ShlLong0WithInt(arbitrary));
Roland Levillainb65eb502015-07-23 12:11:42 +01001581 assertLongEquals(0, Shr0(arbitrary));
1582 assertLongEquals(0, SubSameLong(arbitrary));
1583 assertIntEquals(0, UShr0(arbitrary));
1584 assertIntEquals(0, XorSameInt(arbitrary));
1585
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001586 assertFalse(CmpFloatGreaterThanNaN(arbitrary));
1587 assertFalse(CmpDoubleLessThanNaN(arbitrary));
Roland Levillainb65eb502015-07-23 12:11:42 +01001588
Roland Levillain31dd3d62016-02-16 12:21:02 +00001589 Main main = new Main();
1590 assertIntEquals(1, main.smaliCmpLongConstants());
1591 assertIntEquals(-1, main.smaliCmpGtFloatConstants());
1592 assertIntEquals(-1, main.smaliCmpLtFloatConstants());
1593 assertIntEquals(-1, main.smaliCmpGtDoubleConstants());
1594 assertIntEquals(-1, main.smaliCmpLtDoubleConstants());
1595
1596 assertIntEquals(0, main.smaliCmpLongSameConstant());
1597 assertIntEquals(0, main.smaliCmpGtFloatSameConstant());
1598 assertIntEquals(0, main.smaliCmpLtFloatSameConstant());
1599 assertIntEquals(0, main.smaliCmpGtDoubleSameConstant());
1600 assertIntEquals(0, main.smaliCmpLtDoubleSameConstant());
1601
1602 assertIntEquals(1, main.smaliCmpGtFloatConstantWithNaN());
1603 assertIntEquals(-1, main.smaliCmpLtFloatConstantWithNaN());
1604 assertIntEquals(1, main.smaliCmpGtDoubleConstantWithNaN());
1605 assertIntEquals(-1, main.smaliCmpLtDoubleConstantWithNaN());
1606
Roland Levillainb65eb502015-07-23 12:11:42 +01001607 assertIntEquals(33, ReturnInt33());
1608 assertIntEquals(2147483647, ReturnIntMax());
1609 assertIntEquals(0, ReturnInt0());
1610
1611 assertLongEquals(33, ReturnLong33());
1612 assertLongEquals(34, ReturnLong34());
1613 assertLongEquals(0, ReturnLong0());
1614
1615 assertFloatEquals(33, ReturnFloat33());
1616 assertFloatEquals(34, ReturnFloat34());
1617 assertFloatEquals(99.25f, ReturnFloat99P25());
1618
1619 assertDoubleEquals(33, ReturnDouble33());
1620 assertDoubleEquals(34, ReturnDouble34());
1621 assertDoubleEquals(99.25, ReturnDouble99P25());
David Brazdil4846d132015-01-15 19:07:08 +00001622 }
Roland Levillain31dd3d62016-02-16 12:21:02 +00001623
1624 Main() throws ClassNotFoundException {
1625 testCmp = Class.forName("TestCmp");
1626 }
1627
1628 private Class<?> testCmp;
David Brazdilee690a32014-12-01 17:04:16 +00001629}