blob: 20dac42b916a392046683df63328de35cb8eb9aa [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
David Brazdil4846d132015-01-15 19:07:08 +000017public class Main {
David Brazdilee690a32014-12-01 17:04:16 +000018
Roland Levillain3b55ebb2015-05-08 13:13:19 +010019 public static void assertFalse(boolean condition) {
20 if (condition) {
21 throw new Error();
22 }
23 }
24
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000025 public static void assertIntEquals(int expected, int result) {
26 if (expected != result) {
27 throw new Error("Expected: " + expected + ", found: " + result);
28 }
29 }
30
31 public static void assertLongEquals(long expected, long result) {
32 if (expected != result) {
33 throw new Error("Expected: " + expected + ", found: " + result);
34 }
35 }
36
Mark Mendelle82549b2015-05-06 10:55:34 -040037 public static void assertFloatEquals(float expected, float result) {
38 if (expected != result) {
39 throw new Error("Expected: " + expected + ", found: " + result);
40 }
41 }
42
43 public static void assertDoubleEquals(double expected, double result) {
44 if (expected != result) {
45 throw new Error("Expected: " + expected + ", found: " + result);
46 }
47 }
48
Roland Levillainb65eb502015-07-23 12:11:42 +010049
David Brazdilee690a32014-12-01 17:04:16 +000050 /**
Roland Levillainb65eb502015-07-23 12:11:42 +010051 * Exercise constant folding on negation.
David Brazdilee690a32014-12-01 17:04:16 +000052 */
53
David Brazdila06d66a2015-05-28 11:14:54 +010054 /// CHECK-START: int Main.IntNegation() constant_folding (before)
55 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
56 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Const42>>]
57 /// CHECK-DAG: Return [<<Neg>>]
David Brazdilee690a32014-12-01 17:04:16 +000058
David Brazdila06d66a2015-05-28 11:14:54 +010059 /// CHECK-START: int Main.IntNegation() constant_folding (after)
60 /// CHECK-DAG: <<ConstN42:i\d+>> IntConstant -42
61 /// CHECK-DAG: Return [<<ConstN42>>]
David Brazdilee690a32014-12-01 17:04:16 +000062
Roland Levillainb65eb502015-07-23 12:11:42 +010063 /// CHECK-START: int Main.IntNegation() constant_folding (after)
64 /// CHECK-NOT: Neg
65
David Brazdilee690a32014-12-01 17:04:16 +000066 public static int IntNegation() {
67 int x, y;
68 x = 42;
69 y = -x;
70 return y;
71 }
72
Roland Levillainb65eb502015-07-23 12:11:42 +010073
David Brazdilee690a32014-12-01 17:04:16 +000074 /**
Roland Levillainb65eb502015-07-23 12:11:42 +010075 * Exercise constant folding on addition.
David Brazdilee690a32014-12-01 17:04:16 +000076 */
77
David Brazdila06d66a2015-05-28 11:14:54 +010078 /// CHECK-START: int Main.IntAddition1() constant_folding (before)
79 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
80 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
81 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const1>>,<<Const2>>]
82 /// CHECK-DAG: Return [<<Add>>]
David Brazdilee690a32014-12-01 17:04:16 +000083
David Brazdila06d66a2015-05-28 11:14:54 +010084 /// CHECK-START: int Main.IntAddition1() constant_folding (after)
85 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
86 /// CHECK-DAG: Return [<<Const3>>]
David Brazdilee690a32014-12-01 17:04:16 +000087
Roland Levillainb65eb502015-07-23 12:11:42 +010088 /// CHECK-START: int Main.IntAddition1() constant_folding (after)
89 /// CHECK-NOT: Add
90
David Brazdilee690a32014-12-01 17:04:16 +000091 public static int IntAddition1() {
92 int a, b, c;
93 a = 1;
94 b = 2;
95 c = a + b;
96 return c;
97 }
98
David Brazdila06d66a2015-05-28 11:14:54 +010099 /// CHECK-START: int Main.IntAddition2() constant_folding (before)
100 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
101 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
102 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
103 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
104 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Const1>>,<<Const2>>]
105 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Const5>>,<<Const6>>]
106 /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add1>>,<<Add2>>]
107 /// CHECK-DAG: Return [<<Add3>>]
David Brazdilee690a32014-12-01 17:04:16 +0000108
David Brazdila06d66a2015-05-28 11:14:54 +0100109 /// CHECK-START: int Main.IntAddition2() constant_folding (after)
110 /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14
111 /// CHECK-DAG: Return [<<Const14>>]
David Brazdilee690a32014-12-01 17:04:16 +0000112
Roland Levillainb65eb502015-07-23 12:11:42 +0100113 /// CHECK-START: int Main.IntAddition2() constant_folding (after)
114 /// CHECK-NOT: Add
115
David Brazdilee690a32014-12-01 17:04:16 +0000116 public static int IntAddition2() {
117 int a, b, c;
118 a = 1;
119 b = 2;
120 a += b;
121 b = 5;
122 c = 6;
123 b += c;
124 c = a + b;
125 return c;
126 }
127
Roland Levillainb65eb502015-07-23 12:11:42 +0100128 /// CHECK-START: long Main.LongAddition() constant_folding (before)
129 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
130 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
131 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const1>>,<<Const2>>]
132 /// CHECK-DAG: Return [<<Add>>]
133
134 /// CHECK-START: long Main.LongAddition() constant_folding (after)
135 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
136 /// CHECK-DAG: Return [<<Const3>>]
137
138 /// CHECK-START: long Main.LongAddition() constant_folding (after)
139 /// CHECK-NOT: Add
140
141 public static long LongAddition() {
142 long a, b, c;
143 a = 1L;
144 b = 2L;
145 c = a + b;
146 return c;
147 }
148
149
David Brazdilee690a32014-12-01 17:04:16 +0000150 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100151 * Exercise constant folding on subtraction.
David Brazdilee690a32014-12-01 17:04:16 +0000152 */
153
David Brazdila06d66a2015-05-28 11:14:54 +0100154 /// CHECK-START: int Main.IntSubtraction() constant_folding (before)
155 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
156 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
157 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const6>>,<<Const2>>]
158 /// CHECK-DAG: Return [<<Sub>>]
David Brazdilee690a32014-12-01 17:04:16 +0000159
David Brazdila06d66a2015-05-28 11:14:54 +0100160 /// CHECK-START: int Main.IntSubtraction() constant_folding (after)
161 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
162 /// CHECK-DAG: Return [<<Const4>>]
David Brazdilee690a32014-12-01 17:04:16 +0000163
Roland Levillainb65eb502015-07-23 12:11:42 +0100164 /// CHECK-START: int Main.IntSubtraction() constant_folding (after)
165 /// CHECK-NOT: Sub
166
David Brazdilee690a32014-12-01 17:04:16 +0000167 public static int IntSubtraction() {
168 int a, b, c;
David Brazdil4846d132015-01-15 19:07:08 +0000169 a = 6;
David Brazdilee690a32014-12-01 17:04:16 +0000170 b = 2;
171 c = a - b;
172 return c;
173 }
174
David Brazdila06d66a2015-05-28 11:14:54 +0100175 /// CHECK-START: long Main.LongSubtraction() constant_folding (before)
176 /// CHECK-DAG: <<Const6:j\d+>> LongConstant 6
177 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
178 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const6>>,<<Const2>>]
179 /// CHECK-DAG: Return [<<Sub>>]
David Brazdilee690a32014-12-01 17:04:16 +0000180
David Brazdila06d66a2015-05-28 11:14:54 +0100181 /// CHECK-START: long Main.LongSubtraction() constant_folding (after)
182 /// CHECK-DAG: <<Const4:j\d+>> LongConstant 4
183 /// CHECK-DAG: Return [<<Const4>>]
David Brazdilee690a32014-12-01 17:04:16 +0000184
Roland Levillainb65eb502015-07-23 12:11:42 +0100185 /// CHECK-START: long Main.LongSubtraction() constant_folding (after)
186 /// CHECK-NOT: Sub
187
David Brazdilee690a32014-12-01 17:04:16 +0000188 public static long LongSubtraction() {
189 long a, b, c;
David Brazdil4846d132015-01-15 19:07:08 +0000190 a = 6L;
David Brazdilee690a32014-12-01 17:04:16 +0000191 b = 2L;
192 c = a - b;
193 return c;
194 }
195
Roland Levillainb65eb502015-07-23 12:11:42 +0100196
David Brazdilee690a32014-12-01 17:04:16 +0000197 /**
Roland Levillainf7746ad2015-07-22 14:12:01 +0100198 * Exercise constant folding on multiplication.
199 */
200
201 /// CHECK-START: int Main.IntMultiplication() constant_folding (before)
202 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
203 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
204 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Const7>>,<<Const3>>]
205 /// CHECK-DAG: Return [<<Mul>>]
206
207 /// CHECK-START: int Main.IntMultiplication() constant_folding (after)
208 /// CHECK-DAG: <<Const21:i\d+>> IntConstant 21
209 /// CHECK-DAG: Return [<<Const21>>]
210
211 /// CHECK-START: int Main.IntMultiplication() constant_folding (after)
212 /// CHECK-NOT: Mul
213
214 public static int IntMultiplication() {
215 int a, b, c;
216 a = 7;
217 b = 3;
218 c = a * b;
219 return c;
220 }
221
222 /// CHECK-START: long Main.LongMultiplication() constant_folding (before)
223 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
224 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
225 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const7>>,<<Const3>>]
226 /// CHECK-DAG: Return [<<Mul>>]
227
228 /// CHECK-START: long Main.LongMultiplication() constant_folding (after)
229 /// CHECK-DAG: <<Const21:j\d+>> LongConstant 21
230 /// CHECK-DAG: Return [<<Const21>>]
231
232 /// CHECK-START: long Main.LongMultiplication() constant_folding (after)
233 /// CHECK-NOT: Mul
234
235 public static long LongMultiplication() {
236 long a, b, c;
237 a = 7L;
238 b = 3L;
239 c = a * b;
240 return c;
241 }
242
243
244 /**
245 * Exercise constant folding on division.
246 */
247
248 /// CHECK-START: int Main.IntDivision() constant_folding (before)
249 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
250 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
251 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>]
252 /// CHECK-DAG: <<Div:i\d+>> Div [<<Const8>>,<<Div0Chk>>]
253 /// CHECK-DAG: Return [<<Div>>]
254
255 /// CHECK-START: int Main.IntDivision() constant_folding (after)
256 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
257 /// CHECK-DAG: Return [<<Const2>>]
258
259 /// CHECK-START: int Main.IntDivision() constant_folding (after)
260 /// CHECK-NOT: DivZeroCheck
261 /// CHECK-NOT: Div
262
263 public static int IntDivision() {
264 int a, b, c;
265 a = 8;
266 b = 3;
267 c = a / b;
268 return c;
269 }
270
271 /// CHECK-START: long Main.LongDivision() constant_folding (before)
272 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8
273 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
274 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>]
275 /// CHECK-DAG: <<Div:j\d+>> Div [<<Const8>>,<<Div0Chk>>]
276 /// CHECK-DAG: Return [<<Div>>]
277
278 /// CHECK-START: long Main.LongDivision() constant_folding (after)
279 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
280 /// CHECK-DAG: Return [<<Const2>>]
281
282 /// CHECK-START: long Main.LongDivision() constant_folding (after)
283 /// CHECK-NOT: DivZeroCheck
284 /// CHECK-NOT: Div
285
286 public static long LongDivision() {
287 long a, b, c;
288 a = 8L;
289 b = 3L;
290 c = a / b;
291 return c;
292 }
293
294
295 /**
296 * Exercise constant folding on remainder.
297 */
298
299 /// CHECK-START: int Main.IntRemainder() constant_folding (before)
300 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
301 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
302 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>]
303 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Const8>>,<<Div0Chk>>]
304 /// CHECK-DAG: Return [<<Rem>>]
305
306 /// CHECK-START: int Main.IntRemainder() constant_folding (after)
307 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
308 /// CHECK-DAG: Return [<<Const2>>]
309
310 /// CHECK-START: int Main.IntRemainder() constant_folding (after)
311 /// CHECK-NOT: DivZeroCheck
312 /// CHECK-NOT: Rem
313
314 public static int IntRemainder() {
315 int a, b, c;
316 a = 8;
317 b = 3;
318 c = a % b;
319 return c;
320 }
321
322 /// CHECK-START: long Main.LongRemainder() constant_folding (before)
323 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8
324 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
325 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>]
326 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const8>>,<<Div0Chk>>]
327 /// CHECK-DAG: Return [<<Rem>>]
328
329 /// CHECK-START: long Main.LongRemainder() constant_folding (after)
330 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
331 /// CHECK-DAG: Return [<<Const2>>]
332
333 /// CHECK-START: long Main.LongRemainder() constant_folding (after)
334 /// CHECK-NOT: DivZeroCheck
335 /// CHECK-NOT: Rem
336
337 public static long LongRemainder() {
338 long a, b, c;
339 a = 8L;
340 b = 3L;
341 c = a % b;
342 return c;
343 }
344
345
346 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100347 * Exercise constant folding on constant (static) condition.
David Brazdilee690a32014-12-01 17:04:16 +0000348 */
349
David Brazdila06d66a2015-05-28 11:14:54 +0100350 /// CHECK-START: int Main.StaticCondition() constant_folding (before)
351 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
352 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
353 /// CHECK-DAG: <<Cond:z\d+>> GreaterThanOrEqual [<<Const7>>,<<Const2>>]
354 /// CHECK-DAG: If [<<Cond>>]
David Brazdilee690a32014-12-01 17:04:16 +0000355
David Brazdila06d66a2015-05-28 11:14:54 +0100356 /// CHECK-START: int Main.StaticCondition() constant_folding (after)
357 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
358 /// CHECK-DAG: If [<<Const1>>]
David Brazdilee690a32014-12-01 17:04:16 +0000359
Roland Levillainb65eb502015-07-23 12:11:42 +0100360 /// CHECK-START: int Main.StaticCondition() constant_folding (after)
361 /// CHECK-NOT: GreaterThanOrEqual
362
David Brazdilee690a32014-12-01 17:04:16 +0000363 public static int StaticCondition() {
364 int a, b, c;
David Brazdil4846d132015-01-15 19:07:08 +0000365 a = 7;
David Brazdilee690a32014-12-01 17:04:16 +0000366 b = 2;
367 if (a < b)
368 c = a + b;
369 else
370 c = a - b;
371 return c;
372 }
373
Roland Levillainb65eb502015-07-23 12:11:42 +0100374
David Brazdilee690a32014-12-01 17:04:16 +0000375 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100376 * Exercise constant folding on a program with condition
377 * (i.e. jumps) leading to the creation of many blocks.
David Brazdilee690a32014-12-01 17:04:16 +0000378 *
379 * The intent of this test is to ensure that all constant expressions
380 * are actually evaluated at compile-time, thanks to the reverse
381 * (forward) post-order traversal of the the dominator tree.
382 */
383
David Brazdila06d66a2015-05-28 11:14:54 +0100384 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (before)
385 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
386 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
387 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const5>>,<<Const2>>]
388 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<Const2>>]
389 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Add>>,<<Sub>>]
390 /// CHECK-DAG: Return [<<Phi>>]
David Brazdilee690a32014-12-01 17:04:16 +0000391
David Brazdila06d66a2015-05-28 11:14:54 +0100392 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after)
393 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
394 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
395 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const7>>,<<Const3>>]
396 /// CHECK-DAG: Return [<<Phi>>]
David Brazdilee690a32014-12-01 17:04:16 +0000397
Roland Levillainb65eb502015-07-23 12:11:42 +0100398 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after)
399 /// CHECK-NOT: Add
400 /// CHECK-NOT: Sub
401
David Brazdilee690a32014-12-01 17:04:16 +0000402 public static int JumpsAndConditionals(boolean cond) {
403 int a, b, c;
404 a = 5;
405 b = 2;
406 if (cond)
407 c = a + b;
408 else
409 c = a - b;
410 return c;
411 }
David Brazdil4846d132015-01-15 19:07:08 +0000412
Roland Levillainb65eb502015-07-23 12:11:42 +0100413
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000414 /**
415 * Test optimizations of arithmetic identities yielding a constant result.
416 */
417
David Brazdila06d66a2015-05-28 11:14:54 +0100418 /// CHECK-START: int Main.And0(int) constant_folding (before)
419 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
420 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
421 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const0>>]
422 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000423
David Brazdila06d66a2015-05-28 11:14:54 +0100424 /// CHECK-START: int Main.And0(int) constant_folding (after)
425 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
426 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100427 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000428
Roland Levillainb65eb502015-07-23 12:11:42 +0100429 /// CHECK-START: int Main.And0(int) constant_folding (after)
430 /// CHECK-NOT: And
431
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000432 public static int And0(int arg) {
433 return arg & 0;
434 }
435
David Brazdila06d66a2015-05-28 11:14:54 +0100436 /// CHECK-START: long Main.Mul0(long) constant_folding (before)
437 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
438 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
439 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Arg>>,<<Const0>>]
440 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000441
David Brazdila06d66a2015-05-28 11:14:54 +0100442 /// CHECK-START: long Main.Mul0(long) constant_folding (after)
443 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
444 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100445 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000446
Roland Levillainb65eb502015-07-23 12:11:42 +0100447 /// CHECK-START: long Main.Mul0(long) constant_folding (after)
448 /// CHECK-NOT: Mul
449
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000450 public static long Mul0(long arg) {
451 return arg * 0;
452 }
453
David Brazdila06d66a2015-05-28 11:14:54 +0100454 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (before)
455 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
456 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
457 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<ConstF>>]
458 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000459
David Brazdila06d66a2015-05-28 11:14:54 +0100460 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
461 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
David Brazdila06d66a2015-05-28 11:14:54 +0100462 /// CHECK-DAG: Return [<<ConstF>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000463
Roland Levillainb65eb502015-07-23 12:11:42 +0100464 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
465 /// CHECK-NOT: Or
466
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000467 public static int OrAllOnes(int arg) {
468 return arg | -1;
469 }
470
David Brazdila06d66a2015-05-28 11:14:54 +0100471 /// CHECK-START: long Main.Rem0(long) constant_folding (before)
472 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
473 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
474 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<Arg>>]
475 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const0>>,<<DivZeroCheck>>]
476 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000477
David Brazdila06d66a2015-05-28 11:14:54 +0100478 /// CHECK-START: long Main.Rem0(long) constant_folding (after)
479 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100480 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000481
Roland Levillainb65eb502015-07-23 12:11:42 +0100482 /// CHECK-START: long Main.Rem0(long) constant_folding (after)
483 /// CHECK-NOT: Rem
484
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000485 public static long Rem0(long arg) {
486 return 0 % arg;
487 }
488
David Brazdila06d66a2015-05-28 11:14:54 +0100489 /// CHECK-START: int Main.Rem1(int) constant_folding (before)
490 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
491 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
492 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Arg>>,<<Const1>>]
493 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000494
David Brazdila06d66a2015-05-28 11:14:54 +0100495 /// CHECK-START: int Main.Rem1(int) constant_folding (after)
496 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100497 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000498
Roland Levillainb65eb502015-07-23 12:11:42 +0100499 /// CHECK-START: int Main.Rem1(int) constant_folding (after)
500 /// CHECK-NOT: Rem
501
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000502 public static int Rem1(int arg) {
503 return arg % 1;
504 }
505
David Brazdila06d66a2015-05-28 11:14:54 +0100506 /// CHECK-START: long Main.RemN1(long) constant_folding (before)
507 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
508 /// CHECK-DAG: <<ConstN1:j\d+>> LongConstant -1
509 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<ConstN1>>]
510 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Arg>>,<<DivZeroCheck>>]
511 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000512
David Brazdila06d66a2015-05-28 11:14:54 +0100513 /// CHECK-START: long Main.RemN1(long) constant_folding (after)
514 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100515 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000516
Roland Levillainb65eb502015-07-23 12:11:42 +0100517 /// CHECK-START: long Main.RemN1(long) constant_folding (after)
518 /// CHECK-NOT: Rem
519
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000520 public static long RemN1(long arg) {
521 return arg % -1;
522 }
523
David Brazdila06d66a2015-05-28 11:14:54 +0100524 /// CHECK-START: int Main.Shl0(int) constant_folding (before)
525 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
526 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
527 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const0>>,<<Arg>>]
528 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000529
David Brazdila06d66a2015-05-28 11:14:54 +0100530 /// CHECK-START: int Main.Shl0(int) constant_folding (after)
531 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
532 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100533 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000534
Roland Levillainb65eb502015-07-23 12:11:42 +0100535 /// CHECK-START: int Main.Shl0(int) constant_folding (after)
536 /// CHECK-NOT: Shl
537
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000538 public static int Shl0(int arg) {
539 return 0 << arg;
540 }
541
David Brazdila06d66a2015-05-28 11:14:54 +0100542 /// CHECK-START: long Main.Shr0(int) constant_folding (before)
543 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
544 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
545 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const0>>,<<Arg>>]
546 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000547
David Brazdila06d66a2015-05-28 11:14:54 +0100548 /// CHECK-START: long Main.Shr0(int) constant_folding (after)
549 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
550 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100551 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000552
Roland Levillainb65eb502015-07-23 12:11:42 +0100553 /// CHECK-START: long Main.Shr0(int) constant_folding (after)
554 /// CHECK-NOT: Shr
555
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000556 public static long Shr0(int arg) {
557 return (long)0 >> arg;
558 }
559
David Brazdila06d66a2015-05-28 11:14:54 +0100560 /// CHECK-START: long Main.SubSameLong(long) constant_folding (before)
561 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
562 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Arg>>]
563 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000564
David Brazdila06d66a2015-05-28 11:14:54 +0100565 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
566 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
567 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100568 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000569
Roland Levillainb65eb502015-07-23 12:11:42 +0100570 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
571 /// CHECK-NOT: Sub
572
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000573 public static long SubSameLong(long arg) {
574 return arg - arg;
575 }
576
David Brazdila06d66a2015-05-28 11:14:54 +0100577 /// CHECK-START: int Main.UShr0(int) constant_folding (before)
578 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
579 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
580 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Const0>>,<<Arg>>]
581 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000582
David Brazdila06d66a2015-05-28 11:14:54 +0100583 /// CHECK-START: int Main.UShr0(int) constant_folding (after)
584 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
585 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100586 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000587
Roland Levillainb65eb502015-07-23 12:11:42 +0100588 /// CHECK-START: int Main.UShr0(int) constant_folding (after)
589 /// CHECK-NOT: UShr
590
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000591 public static int UShr0(int arg) {
592 return 0 >>> arg;
593 }
594
David Brazdila06d66a2015-05-28 11:14:54 +0100595 /// CHECK-START: int Main.XorSameInt(int) constant_folding (before)
596 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
597 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Arg>>]
598 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000599
David Brazdila06d66a2015-05-28 11:14:54 +0100600 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
601 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
602 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100603 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000604
Roland Levillainb65eb502015-07-23 12:11:42 +0100605 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
606 /// CHECK-NOT: Xor
607
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000608 public static int XorSameInt(int arg) {
609 return arg ^ arg;
610 }
611
David Brazdila06d66a2015-05-28 11:14:54 +0100612 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (before)
613 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
614 /// CHECK-DAG: <<ConstNan:f\d+>> FloatConstant nan
615 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
616 /// CHECK-DAG: IntConstant 1
617 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>]
618 /// CHECK-DAG: <<Le:z\d+>> LessThanOrEqual [<<Cmp>>,<<Const0>>]
619 /// CHECK-DAG: If [<<Le>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100620
David Brazdila06d66a2015-05-28 11:14:54 +0100621 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
622 /// CHECK-DAG: ParameterValue
623 /// CHECK-DAG: FloatConstant nan
624 /// CHECK-DAG: IntConstant 0
625 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
626 /// CHECK-DAG: If [<<Const1>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100627
David Brazdila06d66a2015-05-28 11:14:54 +0100628 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
629 /// CHECK-NOT: Compare
630 /// CHECK-NOT: LessThanOrEqual
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100631
632 public static boolean CmpFloatGreaterThanNaN(float arg) {
633 return arg > Float.NaN;
634 }
635
David Brazdila06d66a2015-05-28 11:14:54 +0100636 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (before)
637 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
638 /// CHECK-DAG: <<ConstNan:d\d+>> DoubleConstant nan
639 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
640 /// CHECK-DAG: IntConstant 1
641 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>]
642 /// CHECK-DAG: <<Ge:z\d+>> GreaterThanOrEqual [<<Cmp>>,<<Const0>>]
643 /// CHECK-DAG: If [<<Ge>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100644
David Brazdila06d66a2015-05-28 11:14:54 +0100645 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
646 /// CHECK-DAG: ParameterValue
647 /// CHECK-DAG: DoubleConstant nan
648 /// CHECK-DAG: IntConstant 0
649 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
650 /// CHECK-DAG: If [<<Const1>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100651
David Brazdila06d66a2015-05-28 11:14:54 +0100652 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
653 /// CHECK-NOT: Compare
654 /// CHECK-NOT: GreaterThanOrEqual
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100655
656 public static boolean CmpDoubleLessThanNaN(double arg) {
657 return arg < Double.NaN;
658 }
659
Roland Levillainb65eb502015-07-23 12:11:42 +0100660
661 /**
662 * Exercise constant folding on type conversions.
663 */
664
David Brazdila06d66a2015-05-28 11:14:54 +0100665 /// CHECK-START: int Main.ReturnInt33() constant_folding (before)
666 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
667 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<Const33>>]
668 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400669
David Brazdila06d66a2015-05-28 11:14:54 +0100670 /// CHECK-START: int Main.ReturnInt33() constant_folding (after)
671 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
672 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400673
Roland Levillainb65eb502015-07-23 12:11:42 +0100674 /// CHECK-START: int Main.ReturnInt33() constant_folding (after)
675 /// CHECK-NOT: TypeConversion
676
Mark Mendelle82549b2015-05-06 10:55:34 -0400677 public static int ReturnInt33() {
678 long imm = 33L;
679 return (int) imm;
680 }
681
David Brazdila06d66a2015-05-28 11:14:54 +0100682 /// CHECK-START: int Main.ReturnIntMax() constant_folding (before)
683 /// CHECK-DAG: <<ConstMax:f\d+>> FloatConstant 1e+34
684 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstMax>>]
685 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400686
David Brazdila06d66a2015-05-28 11:14:54 +0100687 /// CHECK-START: int Main.ReturnIntMax() constant_folding (after)
688 /// CHECK-DAG: <<ConstMax:i\d+>> IntConstant 2147483647
689 /// CHECK-DAG: Return [<<ConstMax>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400690
Roland Levillainb65eb502015-07-23 12:11:42 +0100691 /// CHECK-START: int Main.ReturnIntMax() constant_folding (after)
692 /// CHECK-NOT: TypeConversion
693
Mark Mendelle82549b2015-05-06 10:55:34 -0400694 public static int ReturnIntMax() {
695 float imm = 1.0e34f;
696 return (int) imm;
697 }
698
David Brazdila06d66a2015-05-28 11:14:54 +0100699 /// CHECK-START: int Main.ReturnInt0() constant_folding (before)
700 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan
701 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstNaN>>]
702 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400703
David Brazdila06d66a2015-05-28 11:14:54 +0100704 /// CHECK-START: int Main.ReturnInt0() constant_folding (after)
705 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
706 /// CHECK-DAG: Return [<<Const0>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400707
Roland Levillainb65eb502015-07-23 12:11:42 +0100708 /// CHECK-START: int Main.ReturnInt0() constant_folding (after)
709 /// CHECK-NOT: TypeConversion
710
Mark Mendelle82549b2015-05-06 10:55:34 -0400711 public static int ReturnInt0() {
712 double imm = Double.NaN;
713 return (int) imm;
714 }
715
David Brazdila06d66a2015-05-28 11:14:54 +0100716 /// CHECK-START: long Main.ReturnLong33() constant_folding (before)
717 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
718 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const33>>]
719 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400720
David Brazdila06d66a2015-05-28 11:14:54 +0100721 /// CHECK-START: long Main.ReturnLong33() constant_folding (after)
722 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
723 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400724
Roland Levillainb65eb502015-07-23 12:11:42 +0100725 /// CHECK-START: long Main.ReturnLong33() constant_folding (after)
726 /// CHECK-NOT: TypeConversion
727
Mark Mendelle82549b2015-05-06 10:55:34 -0400728 public static long ReturnLong33() {
729 int imm = 33;
730 return (long) imm;
731 }
732
David Brazdila06d66a2015-05-28 11:14:54 +0100733 /// CHECK-START: long Main.ReturnLong34() constant_folding (before)
734 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34
735 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const34>>]
736 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400737
David Brazdila06d66a2015-05-28 11:14:54 +0100738 /// CHECK-START: long Main.ReturnLong34() constant_folding (after)
739 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
740 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400741
Roland Levillainb65eb502015-07-23 12:11:42 +0100742 /// CHECK-START: long Main.ReturnLong34() constant_folding (after)
743 /// CHECK-NOT: TypeConversion
744
Mark Mendelle82549b2015-05-06 10:55:34 -0400745 public static long ReturnLong34() {
746 float imm = 34.0f;
747 return (long) imm;
748 }
749
David Brazdila06d66a2015-05-28 11:14:54 +0100750 /// CHECK-START: long Main.ReturnLong0() constant_folding (before)
751 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan
752 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<ConstNaN>>]
753 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400754
David Brazdila06d66a2015-05-28 11:14:54 +0100755 /// CHECK-START: long Main.ReturnLong0() constant_folding (after)
756 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
757 /// CHECK-DAG: Return [<<Const0>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400758
Roland Levillainb65eb502015-07-23 12:11:42 +0100759 /// CHECK-START: long Main.ReturnLong0() constant_folding (after)
760 /// CHECK-NOT: TypeConversion
761
Mark Mendelle82549b2015-05-06 10:55:34 -0400762 public static long ReturnLong0() {
763 double imm = -Double.NaN;
764 return (long) imm;
765 }
766
David Brazdila06d66a2015-05-28 11:14:54 +0100767 /// CHECK-START: float Main.ReturnFloat33() constant_folding (before)
768 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
769 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const33>>]
770 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400771
David Brazdila06d66a2015-05-28 11:14:54 +0100772 /// CHECK-START: float Main.ReturnFloat33() constant_folding (after)
773 /// CHECK-DAG: <<Const33:f\d+>> FloatConstant 33
774 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400775
Roland Levillainb65eb502015-07-23 12:11:42 +0100776 /// CHECK-START: float Main.ReturnFloat33() constant_folding (after)
777 /// CHECK-NOT: TypeConversion
778
Mark Mendelle82549b2015-05-06 10:55:34 -0400779 public static float ReturnFloat33() {
780 int imm = 33;
781 return (float) imm;
782 }
783
David Brazdila06d66a2015-05-28 11:14:54 +0100784 /// CHECK-START: float Main.ReturnFloat34() constant_folding (before)
785 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
786 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const34>>]
787 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400788
David Brazdila06d66a2015-05-28 11:14:54 +0100789 /// CHECK-START: float Main.ReturnFloat34() constant_folding (after)
790 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34
791 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400792
Roland Levillainb65eb502015-07-23 12:11:42 +0100793 /// CHECK-START: float Main.ReturnFloat34() constant_folding (after)
794 /// CHECK-NOT: TypeConversion
795
Mark Mendelle82549b2015-05-06 10:55:34 -0400796 public static float ReturnFloat34() {
797 long imm = 34L;
798 return (float) imm;
799 }
800
David Brazdila06d66a2015-05-28 11:14:54 +0100801 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (before)
802 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25
803 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const>>]
804 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400805
David Brazdila06d66a2015-05-28 11:14:54 +0100806 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after)
807 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25
808 /// CHECK-DAG: Return [<<Const>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400809
Roland Levillainb65eb502015-07-23 12:11:42 +0100810 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after)
811 /// CHECK-NOT: TypeConversion
812
Mark Mendelle82549b2015-05-06 10:55:34 -0400813 public static float ReturnFloat99P25() {
814 double imm = 99.25;
815 return (float) imm;
816 }
817
David Brazdila06d66a2015-05-28 11:14:54 +0100818 /// CHECK-START: double Main.ReturnDouble33() constant_folding (before)
819 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
820 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const33>>]
821 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400822
David Brazdila06d66a2015-05-28 11:14:54 +0100823 /// CHECK-START: double Main.ReturnDouble33() constant_folding (after)
824 /// CHECK-DAG: <<Const33:d\d+>> DoubleConstant 33
825 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400826
827 public static double ReturnDouble33() {
828 int imm = 33;
829 return (double) imm;
830 }
831
David Brazdila06d66a2015-05-28 11:14:54 +0100832 /// CHECK-START: double Main.ReturnDouble34() constant_folding (before)
833 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
834 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const34>>]
835 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400836
David Brazdila06d66a2015-05-28 11:14:54 +0100837 /// CHECK-START: double Main.ReturnDouble34() constant_folding (after)
838 /// CHECK-DAG: <<Const34:d\d+>> DoubleConstant 34
839 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400840
Roland Levillainb65eb502015-07-23 12:11:42 +0100841 /// CHECK-START: double Main.ReturnDouble34() constant_folding (after)
842 /// CHECK-NOT: TypeConversion
843
Mark Mendelle82549b2015-05-06 10:55:34 -0400844 public static double ReturnDouble34() {
845 long imm = 34L;
846 return (double) imm;
847 }
848
David Brazdila06d66a2015-05-28 11:14:54 +0100849 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (before)
850 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25
851 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const>>]
852 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400853
David Brazdila06d66a2015-05-28 11:14:54 +0100854 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after)
855 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25
856 /// CHECK-DAG: Return [<<Const>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400857
Roland Levillainb65eb502015-07-23 12:11:42 +0100858 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after)
859 /// CHECK-NOT: TypeConversion
860
Mark Mendelle82549b2015-05-06 10:55:34 -0400861 public static double ReturnDouble99P25() {
862 float imm = 99.25f;
863 return (double) imm;
864 }
865
Roland Levillainb65eb502015-07-23 12:11:42 +0100866
David Brazdil4846d132015-01-15 19:07:08 +0000867 public static void main(String[] args) {
Roland Levillainb65eb502015-07-23 12:11:42 +0100868 assertIntEquals(-42, IntNegation());
869
870 assertIntEquals(3, IntAddition1());
871 assertIntEquals(14, IntAddition2());
872 assertLongEquals(3L, LongAddition());
873
874 assertIntEquals(4, IntSubtraction());
875 assertLongEquals(4L, LongSubtraction());
876
Roland Levillainf7746ad2015-07-22 14:12:01 +0100877 assertIntEquals(21, IntMultiplication());
878 assertLongEquals(21L, LongMultiplication());
879
880 assertIntEquals(2, IntDivision());
881 assertLongEquals(2L, LongDivision());
882
883 assertIntEquals(2, IntRemainder());
884 assertLongEquals(2L, LongRemainder());
885
Roland Levillainb65eb502015-07-23 12:11:42 +0100886 assertIntEquals(5, StaticCondition());
887
888 assertIntEquals(7, JumpsAndConditionals(true));
889 assertIntEquals(3, JumpsAndConditionals(false));
890
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100891 int arbitrary = 123456; // Value chosen arbitrarily.
Roland Levillainb65eb502015-07-23 12:11:42 +0100892
893 assertIntEquals(0, And0(arbitrary));
894 assertLongEquals(0, Mul0(arbitrary));
895 assertIntEquals(-1, OrAllOnes(arbitrary));
896 assertLongEquals(0, Rem0(arbitrary));
897 assertIntEquals(0, Rem1(arbitrary));
898 assertLongEquals(0, RemN1(arbitrary));
899 assertIntEquals(0, Shl0(arbitrary));
900 assertLongEquals(0, Shr0(arbitrary));
901 assertLongEquals(0, SubSameLong(arbitrary));
902 assertIntEquals(0, UShr0(arbitrary));
903 assertIntEquals(0, XorSameInt(arbitrary));
904
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100905 assertFalse(CmpFloatGreaterThanNaN(arbitrary));
906 assertFalse(CmpDoubleLessThanNaN(arbitrary));
Roland Levillainb65eb502015-07-23 12:11:42 +0100907
908 assertIntEquals(33, ReturnInt33());
909 assertIntEquals(2147483647, ReturnIntMax());
910 assertIntEquals(0, ReturnInt0());
911
912 assertLongEquals(33, ReturnLong33());
913 assertLongEquals(34, ReturnLong34());
914 assertLongEquals(0, ReturnLong0());
915
916 assertFloatEquals(33, ReturnFloat33());
917 assertFloatEquals(34, ReturnFloat34());
918 assertFloatEquals(99.25f, ReturnFloat99P25());
919
920 assertDoubleEquals(33, ReturnDouble33());
921 assertDoubleEquals(34, ReturnDouble34());
922 assertDoubleEquals(99.25, ReturnDouble99P25());
David Brazdil4846d132015-01-15 19:07:08 +0000923 }
David Brazdilee690a32014-12-01 17:04:16 +0000924}