blob: 4805d7759f7a2803115bd2087285f1a4d4946b05 [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 Levillainc90bc7c2014-12-11 12:14:33 +000073 /// CHECK-START: long Main.LongNegation() constant_folding (before)
74 /// CHECK-DAG: <<Const42:j\d+>> LongConstant 42
75 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Const42>>]
76 /// CHECK-DAG: Return [<<Neg>>]
77
78 /// CHECK-START: long Main.LongNegation() constant_folding (after)
79 /// CHECK-DAG: <<ConstN42:j\d+>> LongConstant -42
80 /// CHECK-DAG: Return [<<ConstN42>>]
81
82 /// CHECK-START: long Main.LongNegation() constant_folding (after)
83 /// CHECK-NOT: Neg
84
85 public static long LongNegation() {
86 long x, y;
87 x = 42L;
88 y = -x;
89 return y;
90 }
91
Roland Levillainb65eb502015-07-23 12:11:42 +010092
David Brazdilee690a32014-12-01 17:04:16 +000093 /**
Roland Levillainb65eb502015-07-23 12:11:42 +010094 * Exercise constant folding on addition.
David Brazdilee690a32014-12-01 17:04:16 +000095 */
96
David Brazdila06d66a2015-05-28 11:14:54 +010097 /// CHECK-START: int Main.IntAddition1() constant_folding (before)
98 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
99 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
100 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const1>>,<<Const2>>]
101 /// CHECK-DAG: Return [<<Add>>]
David Brazdilee690a32014-12-01 17:04:16 +0000102
David Brazdila06d66a2015-05-28 11:14:54 +0100103 /// CHECK-START: int Main.IntAddition1() constant_folding (after)
104 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
105 /// CHECK-DAG: Return [<<Const3>>]
David Brazdilee690a32014-12-01 17:04:16 +0000106
Roland Levillainb65eb502015-07-23 12:11:42 +0100107 /// CHECK-START: int Main.IntAddition1() constant_folding (after)
108 /// CHECK-NOT: Add
109
David Brazdilee690a32014-12-01 17:04:16 +0000110 public static int IntAddition1() {
111 int a, b, c;
112 a = 1;
113 b = 2;
114 c = a + b;
115 return c;
116 }
117
David Brazdila06d66a2015-05-28 11:14:54 +0100118 /// CHECK-START: int Main.IntAddition2() constant_folding (before)
119 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
120 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
121 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
122 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
123 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Const1>>,<<Const2>>]
124 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Const5>>,<<Const6>>]
125 /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add1>>,<<Add2>>]
126 /// CHECK-DAG: Return [<<Add3>>]
David Brazdilee690a32014-12-01 17:04:16 +0000127
David Brazdila06d66a2015-05-28 11:14:54 +0100128 /// CHECK-START: int Main.IntAddition2() constant_folding (after)
129 /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14
130 /// CHECK-DAG: Return [<<Const14>>]
David Brazdilee690a32014-12-01 17:04:16 +0000131
Roland Levillainb65eb502015-07-23 12:11:42 +0100132 /// CHECK-START: int Main.IntAddition2() constant_folding (after)
133 /// CHECK-NOT: Add
134
David Brazdilee690a32014-12-01 17:04:16 +0000135 public static int IntAddition2() {
136 int a, b, c;
137 a = 1;
138 b = 2;
139 a += b;
140 b = 5;
141 c = 6;
142 b += c;
143 c = a + b;
144 return c;
145 }
146
Roland Levillainb65eb502015-07-23 12:11:42 +0100147 /// CHECK-START: long Main.LongAddition() constant_folding (before)
148 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
149 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
150 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const1>>,<<Const2>>]
151 /// CHECK-DAG: Return [<<Add>>]
152
153 /// CHECK-START: long Main.LongAddition() constant_folding (after)
154 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
155 /// CHECK-DAG: Return [<<Const3>>]
156
157 /// CHECK-START: long Main.LongAddition() constant_folding (after)
158 /// CHECK-NOT: Add
159
160 public static long LongAddition() {
161 long a, b, c;
162 a = 1L;
163 b = 2L;
164 c = a + b;
165 return c;
166 }
167
168
David Brazdilee690a32014-12-01 17:04:16 +0000169 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100170 * Exercise constant folding on subtraction.
David Brazdilee690a32014-12-01 17:04:16 +0000171 */
172
David Brazdila06d66a2015-05-28 11:14:54 +0100173 /// CHECK-START: int Main.IntSubtraction() constant_folding (before)
174 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
175 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
176 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const6>>,<<Const2>>]
177 /// CHECK-DAG: Return [<<Sub>>]
David Brazdilee690a32014-12-01 17:04:16 +0000178
David Brazdila06d66a2015-05-28 11:14:54 +0100179 /// CHECK-START: int Main.IntSubtraction() constant_folding (after)
180 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
181 /// CHECK-DAG: Return [<<Const4>>]
David Brazdilee690a32014-12-01 17:04:16 +0000182
Roland Levillainb65eb502015-07-23 12:11:42 +0100183 /// CHECK-START: int Main.IntSubtraction() constant_folding (after)
184 /// CHECK-NOT: Sub
185
David Brazdilee690a32014-12-01 17:04:16 +0000186 public static int IntSubtraction() {
187 int a, b, c;
David Brazdil4846d132015-01-15 19:07:08 +0000188 a = 6;
David Brazdilee690a32014-12-01 17:04:16 +0000189 b = 2;
190 c = a - b;
191 return c;
192 }
193
David Brazdila06d66a2015-05-28 11:14:54 +0100194 /// CHECK-START: long Main.LongSubtraction() constant_folding (before)
195 /// CHECK-DAG: <<Const6:j\d+>> LongConstant 6
196 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
197 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const6>>,<<Const2>>]
198 /// CHECK-DAG: Return [<<Sub>>]
David Brazdilee690a32014-12-01 17:04:16 +0000199
David Brazdila06d66a2015-05-28 11:14:54 +0100200 /// CHECK-START: long Main.LongSubtraction() constant_folding (after)
201 /// CHECK-DAG: <<Const4:j\d+>> LongConstant 4
202 /// CHECK-DAG: Return [<<Const4>>]
David Brazdilee690a32014-12-01 17:04:16 +0000203
Roland Levillainb65eb502015-07-23 12:11:42 +0100204 /// CHECK-START: long Main.LongSubtraction() constant_folding (after)
205 /// CHECK-NOT: Sub
206
David Brazdilee690a32014-12-01 17:04:16 +0000207 public static long LongSubtraction() {
208 long a, b, c;
David Brazdil4846d132015-01-15 19:07:08 +0000209 a = 6L;
David Brazdilee690a32014-12-01 17:04:16 +0000210 b = 2L;
211 c = a - b;
212 return c;
213 }
214
Roland Levillainb65eb502015-07-23 12:11:42 +0100215
David Brazdilee690a32014-12-01 17:04:16 +0000216 /**
Roland Levillainf7746ad2015-07-22 14:12:01 +0100217 * Exercise constant folding on multiplication.
218 */
219
220 /// CHECK-START: int Main.IntMultiplication() constant_folding (before)
221 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
222 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
223 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Const7>>,<<Const3>>]
224 /// CHECK-DAG: Return [<<Mul>>]
225
226 /// CHECK-START: int Main.IntMultiplication() constant_folding (after)
227 /// CHECK-DAG: <<Const21:i\d+>> IntConstant 21
228 /// CHECK-DAG: Return [<<Const21>>]
229
230 /// CHECK-START: int Main.IntMultiplication() constant_folding (after)
231 /// CHECK-NOT: Mul
232
233 public static int IntMultiplication() {
234 int a, b, c;
235 a = 7;
236 b = 3;
237 c = a * b;
238 return c;
239 }
240
241 /// CHECK-START: long Main.LongMultiplication() constant_folding (before)
242 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
243 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
244 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const7>>,<<Const3>>]
245 /// CHECK-DAG: Return [<<Mul>>]
246
247 /// CHECK-START: long Main.LongMultiplication() constant_folding (after)
248 /// CHECK-DAG: <<Const21:j\d+>> LongConstant 21
249 /// CHECK-DAG: Return [<<Const21>>]
250
251 /// CHECK-START: long Main.LongMultiplication() constant_folding (after)
252 /// CHECK-NOT: Mul
253
254 public static long LongMultiplication() {
255 long a, b, c;
256 a = 7L;
257 b = 3L;
258 c = a * b;
259 return c;
260 }
261
262
263 /**
264 * Exercise constant folding on division.
265 */
266
267 /// CHECK-START: int Main.IntDivision() constant_folding (before)
268 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
269 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
270 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>]
271 /// CHECK-DAG: <<Div:i\d+>> Div [<<Const8>>,<<Div0Chk>>]
272 /// CHECK-DAG: Return [<<Div>>]
273
274 /// CHECK-START: int Main.IntDivision() constant_folding (after)
275 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
276 /// CHECK-DAG: Return [<<Const2>>]
277
278 /// CHECK-START: int Main.IntDivision() constant_folding (after)
279 /// CHECK-NOT: DivZeroCheck
280 /// CHECK-NOT: Div
281
282 public static int IntDivision() {
283 int a, b, c;
284 a = 8;
285 b = 3;
286 c = a / b;
287 return c;
288 }
289
290 /// CHECK-START: long Main.LongDivision() constant_folding (before)
291 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8
292 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
293 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>]
294 /// CHECK-DAG: <<Div:j\d+>> Div [<<Const8>>,<<Div0Chk>>]
295 /// CHECK-DAG: Return [<<Div>>]
296
297 /// CHECK-START: long Main.LongDivision() constant_folding (after)
298 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
299 /// CHECK-DAG: Return [<<Const2>>]
300
301 /// CHECK-START: long Main.LongDivision() constant_folding (after)
302 /// CHECK-NOT: DivZeroCheck
303 /// CHECK-NOT: Div
304
305 public static long LongDivision() {
306 long a, b, c;
307 a = 8L;
308 b = 3L;
309 c = a / b;
310 return c;
311 }
312
313
314 /**
315 * Exercise constant folding on remainder.
316 */
317
318 /// CHECK-START: int Main.IntRemainder() constant_folding (before)
319 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
320 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
321 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>]
322 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Const8>>,<<Div0Chk>>]
323 /// CHECK-DAG: Return [<<Rem>>]
324
325 /// CHECK-START: int Main.IntRemainder() constant_folding (after)
326 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
327 /// CHECK-DAG: Return [<<Const2>>]
328
329 /// CHECK-START: int Main.IntRemainder() constant_folding (after)
330 /// CHECK-NOT: DivZeroCheck
331 /// CHECK-NOT: Rem
332
333 public static int IntRemainder() {
334 int a, b, c;
335 a = 8;
336 b = 3;
337 c = a % b;
338 return c;
339 }
340
341 /// CHECK-START: long Main.LongRemainder() constant_folding (before)
342 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8
343 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
344 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>]
345 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const8>>,<<Div0Chk>>]
346 /// CHECK-DAG: Return [<<Rem>>]
347
348 /// CHECK-START: long Main.LongRemainder() constant_folding (after)
349 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
350 /// CHECK-DAG: Return [<<Const2>>]
351
352 /// CHECK-START: long Main.LongRemainder() constant_folding (after)
353 /// CHECK-NOT: DivZeroCheck
354 /// CHECK-NOT: Rem
355
356 public static long LongRemainder() {
357 long a, b, c;
358 a = 8L;
359 b = 3L;
360 c = a % b;
361 return c;
362 }
363
364
365 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100366 * Exercise constant folding on constant (static) condition.
David Brazdilee690a32014-12-01 17:04:16 +0000367 */
368
David Brazdila06d66a2015-05-28 11:14:54 +0100369 /// CHECK-START: int Main.StaticCondition() constant_folding (before)
370 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
371 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
372 /// CHECK-DAG: <<Cond:z\d+>> GreaterThanOrEqual [<<Const7>>,<<Const2>>]
373 /// CHECK-DAG: If [<<Cond>>]
David Brazdilee690a32014-12-01 17:04:16 +0000374
David Brazdila06d66a2015-05-28 11:14:54 +0100375 /// CHECK-START: int Main.StaticCondition() constant_folding (after)
376 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
377 /// CHECK-DAG: If [<<Const1>>]
David Brazdilee690a32014-12-01 17:04:16 +0000378
Roland Levillainb65eb502015-07-23 12:11:42 +0100379 /// CHECK-START: int Main.StaticCondition() constant_folding (after)
380 /// CHECK-NOT: GreaterThanOrEqual
381
David Brazdilee690a32014-12-01 17:04:16 +0000382 public static int StaticCondition() {
383 int a, b, c;
David Brazdil4846d132015-01-15 19:07:08 +0000384 a = 7;
David Brazdilee690a32014-12-01 17:04:16 +0000385 b = 2;
386 if (a < b)
387 c = a + b;
388 else
389 c = a - b;
390 return c;
391 }
392
Roland Levillainb65eb502015-07-23 12:11:42 +0100393
David Brazdilee690a32014-12-01 17:04:16 +0000394 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100395 * Exercise constant folding on a program with condition
396 * (i.e. jumps) leading to the creation of many blocks.
David Brazdilee690a32014-12-01 17:04:16 +0000397 *
398 * The intent of this test is to ensure that all constant expressions
399 * are actually evaluated at compile-time, thanks to the reverse
400 * (forward) post-order traversal of the the dominator tree.
401 */
402
David Brazdila06d66a2015-05-28 11:14:54 +0100403 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (before)
404 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
405 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
406 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const5>>,<<Const2>>]
407 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<Const2>>]
408 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Add>>,<<Sub>>]
409 /// CHECK-DAG: Return [<<Phi>>]
David Brazdilee690a32014-12-01 17:04:16 +0000410
David Brazdila06d66a2015-05-28 11:14:54 +0100411 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after)
412 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
413 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
414 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const7>>,<<Const3>>]
415 /// CHECK-DAG: Return [<<Phi>>]
David Brazdilee690a32014-12-01 17:04:16 +0000416
Roland Levillainb65eb502015-07-23 12:11:42 +0100417 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after)
418 /// CHECK-NOT: Add
419 /// CHECK-NOT: Sub
420
David Brazdilee690a32014-12-01 17:04:16 +0000421 public static int JumpsAndConditionals(boolean cond) {
422 int a, b, c;
423 a = 5;
424 b = 2;
425 if (cond)
426 c = a + b;
427 else
428 c = a - b;
429 return c;
430 }
David Brazdil4846d132015-01-15 19:07:08 +0000431
Roland Levillainb65eb502015-07-23 12:11:42 +0100432
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000433 /**
434 * Test optimizations of arithmetic identities yielding a constant result.
435 */
436
David Brazdila06d66a2015-05-28 11:14:54 +0100437 /// CHECK-START: int Main.And0(int) constant_folding (before)
438 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
439 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
440 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const0>>]
441 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000442
David Brazdila06d66a2015-05-28 11:14:54 +0100443 /// CHECK-START: int Main.And0(int) constant_folding (after)
444 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
445 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100446 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000447
Roland Levillainb65eb502015-07-23 12:11:42 +0100448 /// CHECK-START: int Main.And0(int) constant_folding (after)
449 /// CHECK-NOT: And
450
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000451 public static int And0(int arg) {
452 return arg & 0;
453 }
454
David Brazdila06d66a2015-05-28 11:14:54 +0100455 /// CHECK-START: long Main.Mul0(long) constant_folding (before)
456 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
457 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
458 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Arg>>,<<Const0>>]
459 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000460
David Brazdila06d66a2015-05-28 11:14:54 +0100461 /// CHECK-START: long Main.Mul0(long) constant_folding (after)
462 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
463 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100464 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000465
Roland Levillainb65eb502015-07-23 12:11:42 +0100466 /// CHECK-START: long Main.Mul0(long) constant_folding (after)
467 /// CHECK-NOT: Mul
468
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000469 public static long Mul0(long arg) {
470 return arg * 0;
471 }
472
David Brazdila06d66a2015-05-28 11:14:54 +0100473 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (before)
474 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
475 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
476 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<ConstF>>]
477 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000478
David Brazdila06d66a2015-05-28 11:14:54 +0100479 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
480 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
David Brazdila06d66a2015-05-28 11:14:54 +0100481 /// CHECK-DAG: Return [<<ConstF>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000482
Roland Levillainb65eb502015-07-23 12:11:42 +0100483 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
484 /// CHECK-NOT: Or
485
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000486 public static int OrAllOnes(int arg) {
487 return arg | -1;
488 }
489
David Brazdila06d66a2015-05-28 11:14:54 +0100490 /// CHECK-START: long Main.Rem0(long) constant_folding (before)
491 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
492 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
493 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<Arg>>]
494 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const0>>,<<DivZeroCheck>>]
495 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000496
David Brazdila06d66a2015-05-28 11:14:54 +0100497 /// CHECK-START: long Main.Rem0(long) constant_folding (after)
498 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100499 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000500
Roland Levillainb65eb502015-07-23 12:11:42 +0100501 /// CHECK-START: long Main.Rem0(long) constant_folding (after)
502 /// CHECK-NOT: Rem
503
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000504 public static long Rem0(long arg) {
505 return 0 % arg;
506 }
507
David Brazdila06d66a2015-05-28 11:14:54 +0100508 /// CHECK-START: int Main.Rem1(int) constant_folding (before)
509 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
510 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
511 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Arg>>,<<Const1>>]
512 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000513
David Brazdila06d66a2015-05-28 11:14:54 +0100514 /// CHECK-START: int Main.Rem1(int) constant_folding (after)
515 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100516 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000517
Roland Levillainb65eb502015-07-23 12:11:42 +0100518 /// CHECK-START: int Main.Rem1(int) constant_folding (after)
519 /// CHECK-NOT: Rem
520
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000521 public static int Rem1(int arg) {
522 return arg % 1;
523 }
524
David Brazdila06d66a2015-05-28 11:14:54 +0100525 /// CHECK-START: long Main.RemN1(long) constant_folding (before)
526 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
527 /// CHECK-DAG: <<ConstN1:j\d+>> LongConstant -1
528 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<ConstN1>>]
529 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Arg>>,<<DivZeroCheck>>]
530 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000531
David Brazdila06d66a2015-05-28 11:14:54 +0100532 /// CHECK-START: long Main.RemN1(long) constant_folding (after)
533 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100534 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000535
Roland Levillainb65eb502015-07-23 12:11:42 +0100536 /// CHECK-START: long Main.RemN1(long) constant_folding (after)
537 /// CHECK-NOT: Rem
538
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000539 public static long RemN1(long arg) {
540 return arg % -1;
541 }
542
David Brazdila06d66a2015-05-28 11:14:54 +0100543 /// CHECK-START: int Main.Shl0(int) constant_folding (before)
544 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
545 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
546 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const0>>,<<Arg>>]
547 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000548
David Brazdila06d66a2015-05-28 11:14:54 +0100549 /// CHECK-START: int Main.Shl0(int) constant_folding (after)
550 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
551 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100552 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000553
Roland Levillainb65eb502015-07-23 12:11:42 +0100554 /// CHECK-START: int Main.Shl0(int) constant_folding (after)
555 /// CHECK-NOT: Shl
556
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000557 public static int Shl0(int arg) {
558 return 0 << arg;
559 }
560
David Brazdila06d66a2015-05-28 11:14:54 +0100561 /// CHECK-START: long Main.Shr0(int) constant_folding (before)
562 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
563 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
564 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const0>>,<<Arg>>]
565 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000566
David Brazdila06d66a2015-05-28 11:14:54 +0100567 /// CHECK-START: long Main.Shr0(int) constant_folding (after)
568 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
569 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100570 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000571
Roland Levillainb65eb502015-07-23 12:11:42 +0100572 /// CHECK-START: long Main.Shr0(int) constant_folding (after)
573 /// CHECK-NOT: Shr
574
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000575 public static long Shr0(int arg) {
576 return (long)0 >> arg;
577 }
578
David Brazdila06d66a2015-05-28 11:14:54 +0100579 /// CHECK-START: long Main.SubSameLong(long) constant_folding (before)
580 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
581 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Arg>>]
582 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000583
David Brazdila06d66a2015-05-28 11:14:54 +0100584 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
585 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
586 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100587 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000588
Roland Levillainb65eb502015-07-23 12:11:42 +0100589 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
590 /// CHECK-NOT: Sub
591
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000592 public static long SubSameLong(long arg) {
593 return arg - arg;
594 }
595
David Brazdila06d66a2015-05-28 11:14:54 +0100596 /// CHECK-START: int Main.UShr0(int) constant_folding (before)
597 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
598 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
599 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Const0>>,<<Arg>>]
600 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000601
David Brazdila06d66a2015-05-28 11:14:54 +0100602 /// CHECK-START: int Main.UShr0(int) constant_folding (after)
603 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
604 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100605 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000606
Roland Levillainb65eb502015-07-23 12:11:42 +0100607 /// CHECK-START: int Main.UShr0(int) constant_folding (after)
608 /// CHECK-NOT: UShr
609
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000610 public static int UShr0(int arg) {
611 return 0 >>> arg;
612 }
613
David Brazdila06d66a2015-05-28 11:14:54 +0100614 /// CHECK-START: int Main.XorSameInt(int) constant_folding (before)
615 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
616 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Arg>>]
617 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000618
David Brazdila06d66a2015-05-28 11:14:54 +0100619 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
620 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
621 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +0100622 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000623
Roland Levillainb65eb502015-07-23 12:11:42 +0100624 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
625 /// CHECK-NOT: Xor
626
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000627 public static int XorSameInt(int arg) {
628 return arg ^ arg;
629 }
630
David Brazdila06d66a2015-05-28 11:14:54 +0100631 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (before)
632 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
633 /// CHECK-DAG: <<ConstNan:f\d+>> FloatConstant nan
634 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
635 /// CHECK-DAG: IntConstant 1
636 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>]
637 /// CHECK-DAG: <<Le:z\d+>> LessThanOrEqual [<<Cmp>>,<<Const0>>]
638 /// CHECK-DAG: If [<<Le>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100639
David Brazdila06d66a2015-05-28 11:14:54 +0100640 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
641 /// CHECK-DAG: ParameterValue
642 /// CHECK-DAG: FloatConstant nan
643 /// CHECK-DAG: IntConstant 0
644 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
645 /// CHECK-DAG: If [<<Const1>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100646
David Brazdila06d66a2015-05-28 11:14:54 +0100647 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
648 /// CHECK-NOT: Compare
649 /// CHECK-NOT: LessThanOrEqual
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100650
651 public static boolean CmpFloatGreaterThanNaN(float arg) {
652 return arg > Float.NaN;
653 }
654
David Brazdila06d66a2015-05-28 11:14:54 +0100655 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (before)
656 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
657 /// CHECK-DAG: <<ConstNan:d\d+>> DoubleConstant nan
658 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
659 /// CHECK-DAG: IntConstant 1
660 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>]
661 /// CHECK-DAG: <<Ge:z\d+>> GreaterThanOrEqual [<<Cmp>>,<<Const0>>]
662 /// CHECK-DAG: If [<<Ge>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100663
David Brazdila06d66a2015-05-28 11:14:54 +0100664 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
665 /// CHECK-DAG: ParameterValue
666 /// CHECK-DAG: DoubleConstant nan
667 /// CHECK-DAG: IntConstant 0
668 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
669 /// CHECK-DAG: If [<<Const1>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100670
David Brazdila06d66a2015-05-28 11:14:54 +0100671 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
672 /// CHECK-NOT: Compare
673 /// CHECK-NOT: GreaterThanOrEqual
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100674
675 public static boolean CmpDoubleLessThanNaN(double arg) {
676 return arg < Double.NaN;
677 }
678
Roland Levillainb65eb502015-07-23 12:11:42 +0100679
680 /**
681 * Exercise constant folding on type conversions.
682 */
683
David Brazdila06d66a2015-05-28 11:14:54 +0100684 /// CHECK-START: int Main.ReturnInt33() constant_folding (before)
685 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
686 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<Const33>>]
687 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400688
David Brazdila06d66a2015-05-28 11:14:54 +0100689 /// CHECK-START: int Main.ReturnInt33() constant_folding (after)
690 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
691 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400692
Roland Levillainb65eb502015-07-23 12:11:42 +0100693 /// CHECK-START: int Main.ReturnInt33() constant_folding (after)
694 /// CHECK-NOT: TypeConversion
695
Mark Mendelle82549b2015-05-06 10:55:34 -0400696 public static int ReturnInt33() {
697 long imm = 33L;
698 return (int) imm;
699 }
700
David Brazdila06d66a2015-05-28 11:14:54 +0100701 /// CHECK-START: int Main.ReturnIntMax() constant_folding (before)
702 /// CHECK-DAG: <<ConstMax:f\d+>> FloatConstant 1e+34
703 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstMax>>]
704 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400705
David Brazdila06d66a2015-05-28 11:14:54 +0100706 /// CHECK-START: int Main.ReturnIntMax() constant_folding (after)
707 /// CHECK-DAG: <<ConstMax:i\d+>> IntConstant 2147483647
708 /// CHECK-DAG: Return [<<ConstMax>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400709
Roland Levillainb65eb502015-07-23 12:11:42 +0100710 /// CHECK-START: int Main.ReturnIntMax() constant_folding (after)
711 /// CHECK-NOT: TypeConversion
712
Mark Mendelle82549b2015-05-06 10:55:34 -0400713 public static int ReturnIntMax() {
714 float imm = 1.0e34f;
715 return (int) imm;
716 }
717
David Brazdila06d66a2015-05-28 11:14:54 +0100718 /// CHECK-START: int Main.ReturnInt0() constant_folding (before)
719 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan
720 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstNaN>>]
721 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400722
David Brazdila06d66a2015-05-28 11:14:54 +0100723 /// CHECK-START: int Main.ReturnInt0() constant_folding (after)
724 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
725 /// CHECK-DAG: Return [<<Const0>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400726
Roland Levillainb65eb502015-07-23 12:11:42 +0100727 /// CHECK-START: int Main.ReturnInt0() constant_folding (after)
728 /// CHECK-NOT: TypeConversion
729
Mark Mendelle82549b2015-05-06 10:55:34 -0400730 public static int ReturnInt0() {
731 double imm = Double.NaN;
732 return (int) imm;
733 }
734
David Brazdila06d66a2015-05-28 11:14:54 +0100735 /// CHECK-START: long Main.ReturnLong33() constant_folding (before)
736 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
737 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const33>>]
738 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400739
David Brazdila06d66a2015-05-28 11:14:54 +0100740 /// CHECK-START: long Main.ReturnLong33() constant_folding (after)
741 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
742 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400743
Roland Levillainb65eb502015-07-23 12:11:42 +0100744 /// CHECK-START: long Main.ReturnLong33() constant_folding (after)
745 /// CHECK-NOT: TypeConversion
746
Mark Mendelle82549b2015-05-06 10:55:34 -0400747 public static long ReturnLong33() {
748 int imm = 33;
749 return (long) imm;
750 }
751
David Brazdila06d66a2015-05-28 11:14:54 +0100752 /// CHECK-START: long Main.ReturnLong34() constant_folding (before)
753 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34
754 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const34>>]
755 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400756
David Brazdila06d66a2015-05-28 11:14:54 +0100757 /// CHECK-START: long Main.ReturnLong34() constant_folding (after)
758 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
759 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400760
Roland Levillainb65eb502015-07-23 12:11:42 +0100761 /// CHECK-START: long Main.ReturnLong34() constant_folding (after)
762 /// CHECK-NOT: TypeConversion
763
Mark Mendelle82549b2015-05-06 10:55:34 -0400764 public static long ReturnLong34() {
765 float imm = 34.0f;
766 return (long) imm;
767 }
768
David Brazdila06d66a2015-05-28 11:14:54 +0100769 /// CHECK-START: long Main.ReturnLong0() constant_folding (before)
770 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan
771 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<ConstNaN>>]
772 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400773
David Brazdila06d66a2015-05-28 11:14:54 +0100774 /// CHECK-START: long Main.ReturnLong0() constant_folding (after)
775 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
776 /// CHECK-DAG: Return [<<Const0>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400777
Roland Levillainb65eb502015-07-23 12:11:42 +0100778 /// CHECK-START: long Main.ReturnLong0() constant_folding (after)
779 /// CHECK-NOT: TypeConversion
780
Mark Mendelle82549b2015-05-06 10:55:34 -0400781 public static long ReturnLong0() {
782 double imm = -Double.NaN;
783 return (long) imm;
784 }
785
David Brazdila06d66a2015-05-28 11:14:54 +0100786 /// CHECK-START: float Main.ReturnFloat33() constant_folding (before)
787 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
788 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const33>>]
789 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400790
David Brazdila06d66a2015-05-28 11:14:54 +0100791 /// CHECK-START: float Main.ReturnFloat33() constant_folding (after)
792 /// CHECK-DAG: <<Const33:f\d+>> FloatConstant 33
793 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400794
Roland Levillainb65eb502015-07-23 12:11:42 +0100795 /// CHECK-START: float Main.ReturnFloat33() constant_folding (after)
796 /// CHECK-NOT: TypeConversion
797
Mark Mendelle82549b2015-05-06 10:55:34 -0400798 public static float ReturnFloat33() {
799 int imm = 33;
800 return (float) imm;
801 }
802
David Brazdila06d66a2015-05-28 11:14:54 +0100803 /// CHECK-START: float Main.ReturnFloat34() constant_folding (before)
804 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
805 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const34>>]
806 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400807
David Brazdila06d66a2015-05-28 11:14:54 +0100808 /// CHECK-START: float Main.ReturnFloat34() constant_folding (after)
809 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34
810 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400811
Roland Levillainb65eb502015-07-23 12:11:42 +0100812 /// CHECK-START: float Main.ReturnFloat34() constant_folding (after)
813 /// CHECK-NOT: TypeConversion
814
Mark Mendelle82549b2015-05-06 10:55:34 -0400815 public static float ReturnFloat34() {
816 long imm = 34L;
817 return (float) imm;
818 }
819
David Brazdila06d66a2015-05-28 11:14:54 +0100820 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (before)
821 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25
822 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const>>]
823 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400824
David Brazdila06d66a2015-05-28 11:14:54 +0100825 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after)
826 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25
827 /// CHECK-DAG: Return [<<Const>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400828
Roland Levillainb65eb502015-07-23 12:11:42 +0100829 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after)
830 /// CHECK-NOT: TypeConversion
831
Mark Mendelle82549b2015-05-06 10:55:34 -0400832 public static float ReturnFloat99P25() {
833 double imm = 99.25;
834 return (float) imm;
835 }
836
David Brazdila06d66a2015-05-28 11:14:54 +0100837 /// CHECK-START: double Main.ReturnDouble33() constant_folding (before)
838 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
839 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const33>>]
840 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400841
David Brazdila06d66a2015-05-28 11:14:54 +0100842 /// CHECK-START: double Main.ReturnDouble33() constant_folding (after)
843 /// CHECK-DAG: <<Const33:d\d+>> DoubleConstant 33
844 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400845
846 public static double ReturnDouble33() {
847 int imm = 33;
848 return (double) imm;
849 }
850
David Brazdila06d66a2015-05-28 11:14:54 +0100851 /// CHECK-START: double Main.ReturnDouble34() constant_folding (before)
852 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
853 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const34>>]
854 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400855
David Brazdila06d66a2015-05-28 11:14:54 +0100856 /// CHECK-START: double Main.ReturnDouble34() constant_folding (after)
857 /// CHECK-DAG: <<Const34:d\d+>> DoubleConstant 34
858 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400859
Roland Levillainb65eb502015-07-23 12:11:42 +0100860 /// CHECK-START: double Main.ReturnDouble34() constant_folding (after)
861 /// CHECK-NOT: TypeConversion
862
Mark Mendelle82549b2015-05-06 10:55:34 -0400863 public static double ReturnDouble34() {
864 long imm = 34L;
865 return (double) imm;
866 }
867
David Brazdila06d66a2015-05-28 11:14:54 +0100868 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (before)
869 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25
870 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const>>]
871 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400872
David Brazdila06d66a2015-05-28 11:14:54 +0100873 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after)
874 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25
875 /// CHECK-DAG: Return [<<Const>>]
Mark Mendelle82549b2015-05-06 10:55:34 -0400876
Roland Levillainb65eb502015-07-23 12:11:42 +0100877 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after)
878 /// CHECK-NOT: TypeConversion
879
Mark Mendelle82549b2015-05-06 10:55:34 -0400880 public static double ReturnDouble99P25() {
881 float imm = 99.25f;
882 return (double) imm;
883 }
884
Roland Levillainb65eb502015-07-23 12:11:42 +0100885
David Brazdil4846d132015-01-15 19:07:08 +0000886 public static void main(String[] args) {
Roland Levillainb65eb502015-07-23 12:11:42 +0100887 assertIntEquals(-42, IntNegation());
Roland Levillainc90bc7c2014-12-11 12:14:33 +0000888 assertLongEquals(-42L, LongNegation());
Roland Levillainb65eb502015-07-23 12:11:42 +0100889
890 assertIntEquals(3, IntAddition1());
891 assertIntEquals(14, IntAddition2());
892 assertLongEquals(3L, LongAddition());
893
894 assertIntEquals(4, IntSubtraction());
895 assertLongEquals(4L, LongSubtraction());
896
Roland Levillainf7746ad2015-07-22 14:12:01 +0100897 assertIntEquals(21, IntMultiplication());
898 assertLongEquals(21L, LongMultiplication());
899
900 assertIntEquals(2, IntDivision());
901 assertLongEquals(2L, LongDivision());
902
903 assertIntEquals(2, IntRemainder());
904 assertLongEquals(2L, LongRemainder());
905
Roland Levillainb65eb502015-07-23 12:11:42 +0100906 assertIntEquals(5, StaticCondition());
907
908 assertIntEquals(7, JumpsAndConditionals(true));
909 assertIntEquals(3, JumpsAndConditionals(false));
910
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100911 int arbitrary = 123456; // Value chosen arbitrarily.
Roland Levillainb65eb502015-07-23 12:11:42 +0100912
913 assertIntEquals(0, And0(arbitrary));
914 assertLongEquals(0, Mul0(arbitrary));
915 assertIntEquals(-1, OrAllOnes(arbitrary));
916 assertLongEquals(0, Rem0(arbitrary));
917 assertIntEquals(0, Rem1(arbitrary));
918 assertLongEquals(0, RemN1(arbitrary));
919 assertIntEquals(0, Shl0(arbitrary));
920 assertLongEquals(0, Shr0(arbitrary));
921 assertLongEquals(0, SubSameLong(arbitrary));
922 assertIntEquals(0, UShr0(arbitrary));
923 assertIntEquals(0, XorSameInt(arbitrary));
924
Roland Levillain3b55ebb2015-05-08 13:13:19 +0100925 assertFalse(CmpFloatGreaterThanNaN(arbitrary));
926 assertFalse(CmpDoubleLessThanNaN(arbitrary));
Roland Levillainb65eb502015-07-23 12:11:42 +0100927
928 assertIntEquals(33, ReturnInt33());
929 assertIntEquals(2147483647, ReturnIntMax());
930 assertIntEquals(0, ReturnInt0());
931
932 assertLongEquals(33, ReturnLong33());
933 assertLongEquals(34, ReturnLong34());
934 assertLongEquals(0, ReturnLong0());
935
936 assertFloatEquals(33, ReturnFloat33());
937 assertFloatEquals(34, ReturnFloat34());
938 assertFloatEquals(99.25f, ReturnFloat99P25());
939
940 assertDoubleEquals(33, ReturnDouble33());
941 assertDoubleEquals(34, ReturnDouble34());
942 assertDoubleEquals(99.25, ReturnDouble99P25());
David Brazdil4846d132015-01-15 19:07:08 +0000943 }
David Brazdilee690a32014-12-01 17:04:16 +0000944}