blob: 33ef10bf7f039863443b8c8da5310e2ff1ecf016 [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
David Brazdilf02c3cf2016-02-29 09:14:51 +000054 private static int $inline$int(int x) {
55 return x;
56 }
57
58 private static long $inline$long(long x) {
59 return x;
60 }
61
62 private static float $inline$float(float x) {
63 return x;
64 }
65
66 private static double $inline$double(double x) {
67 return x;
68 }
Roland Levillainb65eb502015-07-23 12:11:42 +010069
Roland Levillain31dd3d62016-02-16 12:21:02 +000070 // Wrappers around methods located in file TestCmp.smali.
71
72 public int smaliCmpLongConstants() throws Exception {
73 Method m = testCmp.getMethod("$opt$CmpLongConstants");
74 return (Integer)m.invoke(null);
75 }
76 public int smaliCmpGtFloatConstants() throws Exception {
77 Method m = testCmp.getMethod("$opt$CmpGtFloatConstants");
78 return (Integer)m.invoke(null);
79 }
80 public int smaliCmpLtFloatConstants() throws Exception {
81 Method m = testCmp.getMethod("$opt$CmpLtFloatConstants");
82 return (Integer)m.invoke(null);
83 }
84 public int smaliCmpGtDoubleConstants() throws Exception {
85 Method m = testCmp.getMethod("$opt$CmpGtDoubleConstants");
86 return (Integer)m.invoke(null);
87 }
88 public int smaliCmpLtDoubleConstants() throws Exception {
89 Method m = testCmp.getMethod("$opt$CmpLtDoubleConstants");
90 return (Integer)m.invoke(null);
91 }
92
93 public int smaliCmpLongSameConstant() throws Exception {
94 Method m = testCmp.getMethod("$opt$CmpLongSameConstant");
95 return (Integer)m.invoke(null);
96 }
97 public int smaliCmpGtFloatSameConstant() throws Exception {
98 Method m = testCmp.getMethod("$opt$CmpGtFloatSameConstant");
99 return (Integer)m.invoke(null);
100 }
101 public int smaliCmpLtFloatSameConstant() throws Exception {
102 Method m = testCmp.getMethod("$opt$CmpLtFloatSameConstant");
103 return (Integer)m.invoke(null);
104 }
105 public int smaliCmpGtDoubleSameConstant() throws Exception {
106 Method m = testCmp.getMethod("$opt$CmpGtDoubleSameConstant");
107 return (Integer)m.invoke(null);
108 }
109 public int smaliCmpLtDoubleSameConstant() throws Exception {
110 Method m = testCmp.getMethod("$opt$CmpLtDoubleSameConstant");
111 return (Integer)m.invoke(null);
112 }
113
114 public int smaliCmpGtFloatConstantWithNaN() throws Exception {
115 Method m = testCmp.getMethod("$opt$CmpGtFloatConstantWithNaN");
116 return (Integer)m.invoke(null);
117 }
118 public int smaliCmpLtFloatConstantWithNaN() throws Exception {
119 Method m = testCmp.getMethod("$opt$CmpLtFloatConstantWithNaN");
120 return (Integer)m.invoke(null);
121 }
122 public int smaliCmpGtDoubleConstantWithNaN() throws Exception {
123 Method m = testCmp.getMethod("$opt$CmpGtDoubleConstantWithNaN");
124 return (Integer)m.invoke(null);
125 }
126 public int smaliCmpLtDoubleConstantWithNaN() throws Exception {
127 Method m = testCmp.getMethod("$opt$CmpLtDoubleConstantWithNaN");
128 return (Integer)m.invoke(null);
129 }
130
131
David Brazdilee690a32014-12-01 17:04:16 +0000132 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100133 * Exercise constant folding on negation.
David Brazdilee690a32014-12-01 17:04:16 +0000134 */
135
David Brazdila06d66a2015-05-28 11:14:54 +0100136 /// CHECK-START: int Main.IntNegation() constant_folding (before)
137 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
138 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Const42>>]
139 /// CHECK-DAG: Return [<<Neg>>]
David Brazdilee690a32014-12-01 17:04:16 +0000140
David Brazdila06d66a2015-05-28 11:14:54 +0100141 /// CHECK-START: int Main.IntNegation() constant_folding (after)
142 /// CHECK-DAG: <<ConstN42:i\d+>> IntConstant -42
143 /// CHECK-DAG: Return [<<ConstN42>>]
David Brazdilee690a32014-12-01 17:04:16 +0000144
Roland Levillainb65eb502015-07-23 12:11:42 +0100145 /// CHECK-START: int Main.IntNegation() constant_folding (after)
146 /// CHECK-NOT: Neg
147
David Brazdilee690a32014-12-01 17:04:16 +0000148 public static int IntNegation() {
149 int x, y;
150 x = 42;
151 y = -x;
152 return y;
153 }
154
Roland Levillainc90bc7c2014-12-11 12:14:33 +0000155 /// CHECK-START: long Main.LongNegation() constant_folding (before)
156 /// CHECK-DAG: <<Const42:j\d+>> LongConstant 42
157 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Const42>>]
158 /// CHECK-DAG: Return [<<Neg>>]
159
160 /// CHECK-START: long Main.LongNegation() constant_folding (after)
161 /// CHECK-DAG: <<ConstN42:j\d+>> LongConstant -42
162 /// CHECK-DAG: Return [<<ConstN42>>]
163
164 /// CHECK-START: long Main.LongNegation() constant_folding (after)
165 /// CHECK-NOT: Neg
166
167 public static long LongNegation() {
168 long x, y;
169 x = 42L;
170 y = -x;
171 return y;
172 }
173
Roland Levillain31dd3d62016-02-16 12:21:02 +0000174 /// CHECK-START: float Main.FloatNegation() constant_folding (before)
175 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
176 /// CHECK-DAG: <<Neg:f\d+>> Neg [<<Const42>>]
177 /// CHECK-DAG: Return [<<Neg>>]
178
179 /// CHECK-START: float Main.FloatNegation() constant_folding (after)
180 /// CHECK-DAG: <<ConstN42:f\d+>> FloatConstant -42
181 /// CHECK-DAG: Return [<<ConstN42>>]
182
183 /// CHECK-START: float Main.FloatNegation() constant_folding (after)
184 /// CHECK-NOT: Neg
185
186 public static float FloatNegation() {
187 float x, y;
188 x = 42F;
189 y = -x;
190 return y;
191 }
192
193 /// CHECK-START: double Main.DoubleNegation() constant_folding (before)
194 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
195 /// CHECK-DAG: <<Neg:d\d+>> Neg [<<Const42>>]
196 /// CHECK-DAG: Return [<<Neg>>]
197
198 /// CHECK-START: double Main.DoubleNegation() constant_folding (after)
199 /// CHECK-DAG: <<ConstN42:d\d+>> DoubleConstant -42
200 /// CHECK-DAG: Return [<<ConstN42>>]
201
202 /// CHECK-START: double Main.DoubleNegation() constant_folding (after)
203 /// CHECK-NOT: Neg
204
205 public static double DoubleNegation() {
206 double x, y;
207 x = 42D;
208 y = -x;
209 return y;
210 }
211
David Brazdilee690a32014-12-01 17:04:16 +0000212 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100213 * Exercise constant folding on addition.
David Brazdilee690a32014-12-01 17:04:16 +0000214 */
215
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700216 /// CHECK-START: int Main.IntAddition1() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100217 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
218 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
219 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const1>>,<<Const2>>]
220 /// CHECK-DAG: Return [<<Add>>]
David Brazdilee690a32014-12-01 17:04:16 +0000221
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700222 /// CHECK-START: int Main.IntAddition1() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100223 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
224 /// CHECK-DAG: Return [<<Const3>>]
David Brazdilee690a32014-12-01 17:04:16 +0000225
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700226 /// CHECK-START: int Main.IntAddition1() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +0100227 /// CHECK-NOT: Add
228
David Brazdilee690a32014-12-01 17:04:16 +0000229 public static int IntAddition1() {
230 int a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000231 a = $inline$int(1);
232 b = $inline$int(2);
David Brazdilee690a32014-12-01 17:04:16 +0000233 c = a + b;
234 return c;
235 }
236
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700237 /// CHECK-START: int Main.IntAddition2() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100238 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
239 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
240 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
241 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
242 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Const1>>,<<Const2>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +0000243 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Const5>>,<<Const6>>]
244 /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add1>>,<<Add2>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100245 /// CHECK-DAG: Return [<<Add3>>]
David Brazdilee690a32014-12-01 17:04:16 +0000246
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700247 /// CHECK-START: int Main.IntAddition2() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100248 /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14
249 /// CHECK-DAG: Return [<<Const14>>]
David Brazdilee690a32014-12-01 17:04:16 +0000250
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700251 /// CHECK-START: int Main.IntAddition2() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +0100252 /// CHECK-NOT: Add
253
David Brazdilee690a32014-12-01 17:04:16 +0000254 public static int IntAddition2() {
255 int a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000256 a = $inline$int(1);
257 b = $inline$int(2);
David Brazdilee690a32014-12-01 17:04:16 +0000258 a += b;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000259 b = $inline$int(5);
260 c = $inline$int(6);
David Brazdilee690a32014-12-01 17:04:16 +0000261 b += c;
262 c = a + b;
263 return c;
264 }
265
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700266 /// CHECK-START: long Main.LongAddition() constant_folding$after_inlining (before)
Roland Levillainb65eb502015-07-23 12:11:42 +0100267 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
268 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
269 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const1>>,<<Const2>>]
270 /// CHECK-DAG: Return [<<Add>>]
271
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700272 /// CHECK-START: long Main.LongAddition() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +0100273 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
274 /// CHECK-DAG: Return [<<Const3>>]
275
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700276 /// CHECK-START: long Main.LongAddition() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +0100277 /// CHECK-NOT: Add
278
279 public static long LongAddition() {
280 long a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000281 a = $inline$long(1L);
282 b = $inline$long(2L);
Roland Levillainb65eb502015-07-23 12:11:42 +0100283 c = a + b;
284 return c;
285 }
286
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700287 /// CHECK-START: float Main.FloatAddition() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000288 /// CHECK-DAG: <<Const1:f\d+>> FloatConstant 1
289 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
290 /// CHECK-DAG: <<Add:f\d+>> Add [<<Const1>>,<<Const2>>]
291 /// CHECK-DAG: Return [<<Add>>]
292
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700293 /// CHECK-START: float Main.FloatAddition() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000294 /// CHECK-DAG: <<Const3:f\d+>> FloatConstant 3
295 /// CHECK-DAG: Return [<<Const3>>]
296
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700297 /// CHECK-START: float Main.FloatAddition() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000298 /// CHECK-NOT: Add
299
300 public static float FloatAddition() {
301 float a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000302 a = $inline$float(1F);
303 b = $inline$float(2F);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000304 c = a + b;
305 return c;
306 }
307
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700308 /// CHECK-START: double Main.DoubleAddition() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000309 /// CHECK-DAG: <<Const1:d\d+>> DoubleConstant 1
310 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
311 /// CHECK-DAG: <<Add:d\d+>> Add [<<Const1>>,<<Const2>>]
312 /// CHECK-DAG: Return [<<Add>>]
313
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700314 /// CHECK-START: double Main.DoubleAddition() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000315 /// CHECK-DAG: <<Const3:d\d+>> DoubleConstant 3
316 /// CHECK-DAG: Return [<<Const3>>]
317
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700318 /// CHECK-START: double Main.DoubleAddition() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000319 /// CHECK-NOT: Add
320
321 public static double DoubleAddition() {
322 double a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000323 a = $inline$double(1D);
324 b = $inline$double(2D);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000325 c = a + b;
326 return c;
327 }
328
Roland Levillainb65eb502015-07-23 12:11:42 +0100329
David Brazdilee690a32014-12-01 17:04:16 +0000330 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100331 * Exercise constant folding on subtraction.
David Brazdilee690a32014-12-01 17:04:16 +0000332 */
333
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700334 /// CHECK-START: int Main.IntSubtraction() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100335 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
336 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
337 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const6>>,<<Const2>>]
338 /// CHECK-DAG: Return [<<Sub>>]
David Brazdilee690a32014-12-01 17:04:16 +0000339
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700340 /// CHECK-START: int Main.IntSubtraction() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100341 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
342 /// CHECK-DAG: Return [<<Const4>>]
David Brazdilee690a32014-12-01 17:04:16 +0000343
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700344 /// CHECK-START: int Main.IntSubtraction() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +0100345 /// CHECK-NOT: Sub
346
David Brazdilee690a32014-12-01 17:04:16 +0000347 public static int IntSubtraction() {
348 int a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000349 a = $inline$int(6);
350 b = $inline$int(2);
David Brazdilee690a32014-12-01 17:04:16 +0000351 c = a - b;
352 return c;
353 }
354
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700355 /// CHECK-START: long Main.LongSubtraction() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100356 /// CHECK-DAG: <<Const6:j\d+>> LongConstant 6
357 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
358 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const6>>,<<Const2>>]
359 /// CHECK-DAG: Return [<<Sub>>]
David Brazdilee690a32014-12-01 17:04:16 +0000360
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700361 /// CHECK-START: long Main.LongSubtraction() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100362 /// CHECK-DAG: <<Const4:j\d+>> LongConstant 4
363 /// CHECK-DAG: Return [<<Const4>>]
David Brazdilee690a32014-12-01 17:04:16 +0000364
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700365 /// CHECK-START: long Main.LongSubtraction() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +0100366 /// CHECK-NOT: Sub
367
David Brazdilee690a32014-12-01 17:04:16 +0000368 public static long LongSubtraction() {
369 long a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000370 a = $inline$long(6L);
371 b = $inline$long(2L);
David Brazdilee690a32014-12-01 17:04:16 +0000372 c = a - b;
373 return c;
374 }
375
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700376 /// CHECK-START: float Main.FloatSubtraction() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000377 /// CHECK-DAG: <<Const6:f\d+>> FloatConstant 6
378 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
379 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<Const6>>,<<Const2>>]
380 /// CHECK-DAG: Return [<<Sub>>]
381
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700382 /// CHECK-START: float Main.FloatSubtraction() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000383 /// CHECK-DAG: <<Const4:f\d+>> FloatConstant 4
384 /// CHECK-DAG: Return [<<Const4>>]
385
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700386 /// CHECK-START: float Main.FloatSubtraction() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000387 /// CHECK-NOT: Sub
388
389 public static float FloatSubtraction() {
390 float a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000391 a = $inline$float(6F);
392 b = $inline$float(2F);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000393 c = a - b;
394 return c;
395 }
396
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700397 /// CHECK-START: double Main.DoubleSubtraction() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000398 /// CHECK-DAG: <<Const6:d\d+>> DoubleConstant 6
399 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
400 /// CHECK-DAG: <<Sub:d\d+>> Sub [<<Const6>>,<<Const2>>]
401 /// CHECK-DAG: Return [<<Sub>>]
402
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700403 /// CHECK-START: double Main.DoubleSubtraction() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000404 /// CHECK-DAG: <<Const4:d\d+>> DoubleConstant 4
405 /// CHECK-DAG: Return [<<Const4>>]
406
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700407 /// CHECK-START: double Main.DoubleSubtraction() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000408 /// CHECK-NOT: Sub
409
410 public static double DoubleSubtraction() {
411 double a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000412 a = $inline$double(6D);
413 b = $inline$double(2D);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000414 c = a - b;
415 return c;
416 }
417
Roland Levillainb65eb502015-07-23 12:11:42 +0100418
David Brazdilee690a32014-12-01 17:04:16 +0000419 /**
Roland Levillainf7746ad2015-07-22 14:12:01 +0100420 * Exercise constant folding on multiplication.
421 */
422
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700423 /// CHECK-START: int Main.IntMultiplication() constant_folding$after_inlining (before)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100424 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
425 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
426 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Const7>>,<<Const3>>]
427 /// CHECK-DAG: Return [<<Mul>>]
428
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700429 /// CHECK-START: int Main.IntMultiplication() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100430 /// CHECK-DAG: <<Const21:i\d+>> IntConstant 21
431 /// CHECK-DAG: Return [<<Const21>>]
432
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700433 /// CHECK-START: int Main.IntMultiplication() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100434 /// CHECK-NOT: Mul
435
436 public static int IntMultiplication() {
437 int a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000438 a = $inline$int(7);
439 b = $inline$int(3);
Roland Levillainf7746ad2015-07-22 14:12:01 +0100440 c = a * b;
441 return c;
442 }
443
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700444 /// CHECK-START: long Main.LongMultiplication() constant_folding$after_inlining (before)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100445 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
446 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
447 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const7>>,<<Const3>>]
448 /// CHECK-DAG: Return [<<Mul>>]
449
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700450 /// CHECK-START: long Main.LongMultiplication() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100451 /// CHECK-DAG: <<Const21:j\d+>> LongConstant 21
452 /// CHECK-DAG: Return [<<Const21>>]
453
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700454 /// CHECK-START: long Main.LongMultiplication() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100455 /// CHECK-NOT: Mul
456
457 public static long LongMultiplication() {
458 long a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000459 a = $inline$long(7L);
460 b = $inline$long(3L);
Roland Levillainf7746ad2015-07-22 14:12:01 +0100461 c = a * b;
462 return c;
463 }
464
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700465 /// CHECK-START: float Main.FloatMultiplication() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000466 /// CHECK-DAG: <<Const7:f\d+>> FloatConstant 7
467 /// CHECK-DAG: <<Const3:f\d+>> FloatConstant 3
468 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Const7>>,<<Const3>>]
469 /// CHECK-DAG: Return [<<Mul>>]
470
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700471 /// CHECK-START: float Main.FloatMultiplication() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000472 /// CHECK-DAG: <<Const21:f\d+>> FloatConstant 21
473 /// CHECK-DAG: Return [<<Const21>>]
474
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700475 /// CHECK-START: float Main.FloatMultiplication() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000476 /// CHECK-NOT: Mul
477
478 public static float FloatMultiplication() {
479 float a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000480 a = $inline$float(7F);
481 b = $inline$float(3F);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000482 c = a * b;
483 return c;
484 }
485
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700486 /// CHECK-START: double Main.DoubleMultiplication() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000487 /// CHECK-DAG: <<Const7:d\d+>> DoubleConstant 7
488 /// CHECK-DAG: <<Const3:d\d+>> DoubleConstant 3
489 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Const7>>,<<Const3>>]
490 /// CHECK-DAG: Return [<<Mul>>]
491
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700492 /// CHECK-START: double Main.DoubleMultiplication() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000493 /// CHECK-DAG: <<Const21:d\d+>> DoubleConstant 21
494 /// CHECK-DAG: Return [<<Const21>>]
495
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700496 /// CHECK-START: double Main.DoubleMultiplication() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000497 /// CHECK-NOT: Mul
498
499 public static double DoubleMultiplication() {
500 double a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000501 a = $inline$double(7D);
502 b = $inline$double(3D);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000503 c = a * b;
504 return c;
505 }
506
Roland Levillainf7746ad2015-07-22 14:12:01 +0100507
508 /**
509 * Exercise constant folding on division.
510 */
511
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700512 /// CHECK-START: int Main.IntDivision() constant_folding$after_inlining (before)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100513 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
514 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
515 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>]
516 /// CHECK-DAG: <<Div:i\d+>> Div [<<Const8>>,<<Div0Chk>>]
517 /// CHECK-DAG: Return [<<Div>>]
518
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700519 /// CHECK-START: int Main.IntDivision() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100520 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
521 /// CHECK-DAG: Return [<<Const2>>]
522
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700523 /// CHECK-START: int Main.IntDivision() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100524 /// CHECK-NOT: DivZeroCheck
525 /// CHECK-NOT: Div
526
527 public static int IntDivision() {
528 int a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000529 a = $inline$int(8);
530 b = $inline$int(3);
Roland Levillainf7746ad2015-07-22 14:12:01 +0100531 c = a / b;
532 return c;
533 }
534
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700535 /// CHECK-START: long Main.LongDivision() constant_folding$after_inlining (before)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100536 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8
537 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
538 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>]
539 /// CHECK-DAG: <<Div:j\d+>> Div [<<Const8>>,<<Div0Chk>>]
540 /// CHECK-DAG: Return [<<Div>>]
541
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700542 /// CHECK-START: long Main.LongDivision() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100543 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
544 /// CHECK-DAG: Return [<<Const2>>]
545
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700546 /// CHECK-START: long Main.LongDivision() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100547 /// CHECK-NOT: DivZeroCheck
548 /// CHECK-NOT: Div
549
550 public static long LongDivision() {
551 long a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000552 a = $inline$long(8L);
553 b = $inline$long(3L);
Roland Levillainf7746ad2015-07-22 14:12:01 +0100554 c = a / b;
555 return c;
556 }
557
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700558 /// CHECK-START: float Main.FloatDivision() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000559 /// CHECK-DAG: <<Const8:f\d+>> FloatConstant 8
560 /// CHECK-DAG: <<Const2P5:f\d+>> FloatConstant 2.5
561 /// CHECK-DAG: <<Div:f\d+>> Div [<<Const8>>,<<Const2P5>>]
562 /// CHECK-DAG: Return [<<Div>>]
563
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700564 /// CHECK-START: float Main.FloatDivision() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000565 /// CHECK-DAG: <<Const3P2:f\d+>> FloatConstant 3.2
566 /// CHECK-DAG: Return [<<Const3P2>>]
567
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700568 /// CHECK-START: float Main.FloatDivision() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000569 /// CHECK-NOT: Div
570
571 public static float FloatDivision() {
572 float a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000573 a = $inline$float(8F);
574 b = $inline$float(2.5F);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000575 c = a / b;
576 return c;
577 }
578
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700579 /// CHECK-START: double Main.DoubleDivision() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000580 /// CHECK-DAG: <<Const8:d\d+>> DoubleConstant 8
581 /// CHECK-DAG: <<Const2P5:d\d+>> DoubleConstant 2.5
582 /// CHECK-DAG: <<Div:d\d+>> Div [<<Const8>>,<<Const2P5>>]
583 /// CHECK-DAG: Return [<<Div>>]
584
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700585 /// CHECK-START: double Main.DoubleDivision() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000586 /// CHECK-DAG: <<Const3P2:d\d+>> DoubleConstant 3.2
587 /// CHECK-DAG: Return [<<Const3P2>>]
588
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700589 /// CHECK-START: double Main.DoubleDivision() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000590 /// CHECK-NOT: Div
591
592 public static double DoubleDivision() {
593 double a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000594 a = $inline$double(8D);
595 b = $inline$double(2.5D);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000596 c = a / b;
597 return c;
598 }
599
Roland Levillainf7746ad2015-07-22 14:12:01 +0100600
601 /**
602 * Exercise constant folding on remainder.
603 */
604
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700605 /// CHECK-START: int Main.IntRemainder() constant_folding$after_inlining (before)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100606 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
607 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
608 /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>]
609 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Const8>>,<<Div0Chk>>]
610 /// CHECK-DAG: Return [<<Rem>>]
611
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700612 /// CHECK-START: int Main.IntRemainder() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100613 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
614 /// CHECK-DAG: Return [<<Const2>>]
615
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700616 /// CHECK-START: int Main.IntRemainder() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100617 /// CHECK-NOT: DivZeroCheck
618 /// CHECK-NOT: Rem
619
620 public static int IntRemainder() {
621 int a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000622 a = $inline$int(8);
623 b = $inline$int(3);
Roland Levillainf7746ad2015-07-22 14:12:01 +0100624 c = a % b;
625 return c;
626 }
627
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700628 /// CHECK-START: long Main.LongRemainder() constant_folding$after_inlining (before)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100629 /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8
630 /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3
631 /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>]
632 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const8>>,<<Div0Chk>>]
633 /// CHECK-DAG: Return [<<Rem>>]
634
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700635 /// CHECK-START: long Main.LongRemainder() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100636 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
637 /// CHECK-DAG: Return [<<Const2>>]
638
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700639 /// CHECK-START: long Main.LongRemainder() constant_folding$after_inlining (after)
Roland Levillainf7746ad2015-07-22 14:12:01 +0100640 /// CHECK-NOT: DivZeroCheck
641 /// CHECK-NOT: Rem
642
643 public static long LongRemainder() {
644 long a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000645 a = $inline$long(8L);
646 b = $inline$long(3L);
Roland Levillainf7746ad2015-07-22 14:12:01 +0100647 c = a % b;
648 return c;
649 }
650
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700651 /// CHECK-START: float Main.FloatRemainder() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000652 /// CHECK-DAG: <<Const8:f\d+>> FloatConstant 8
653 /// CHECK-DAG: <<Const2P5:f\d+>> FloatConstant 2.5
654 /// CHECK-DAG: <<Rem:f\d+>> Rem [<<Const8>>,<<Const2P5>>]
655 /// CHECK-DAG: Return [<<Rem>>]
656
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700657 /// CHECK-START: float Main.FloatRemainder() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000658 /// CHECK-DAG: <<Const0P5:f\d+>> FloatConstant 0.5
659 /// CHECK-DAG: Return [<<Const0P5>>]
660
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700661 /// CHECK-START: float Main.FloatRemainder() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000662 /// CHECK-NOT: Rem
663
664 public static float FloatRemainder() {
665 float a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000666 a = $inline$float(8F);
667 b = $inline$float(2.5F);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000668 c = a % b;
669 return c;
670 }
671
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700672 /// CHECK-START: double Main.DoubleRemainder() constant_folding$after_inlining (before)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000673 /// CHECK-DAG: <<Const8:d\d+>> DoubleConstant 8
674 /// CHECK-DAG: <<Const2P5:d\d+>> DoubleConstant 2.5
675 /// CHECK-DAG: <<Rem:d\d+>> Rem [<<Const8>>,<<Const2P5>>]
676 /// CHECK-DAG: Return [<<Rem>>]
677
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700678 /// CHECK-START: double Main.DoubleRemainder() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000679 /// CHECK-DAG: <<Const0P5:d\d+>> DoubleConstant 0.5
680 /// CHECK-DAG: Return [<<Const0P5>>]
681
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700682 /// CHECK-START: double Main.DoubleRemainder() constant_folding$after_inlining (after)
Roland Levillain31dd3d62016-02-16 12:21:02 +0000683 /// CHECK-NOT: Rem
684
685 public static double DoubleRemainder() {
686 double a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000687 a = $inline$double(8D);
688 b = $inline$double(2.5D);
Roland Levillain31dd3d62016-02-16 12:21:02 +0000689 c = a % b;
690 return c;
691 }
692
Roland Levillainf7746ad2015-07-22 14:12:01 +0100693
694 /**
Roland Levillain9867bc72015-08-05 10:21:34 +0100695 * Exercise constant folding on left shift.
696 */
697
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700698 /// CHECK-START: int Main.ShlIntLong() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100699 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
700 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2
701 /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>]
702 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const1>>,<<TypeConv>>]
703 /// CHECK-DAG: Return [<<Shl>>]
704
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700705 /// CHECK-START: int Main.ShlIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100706 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
707 /// CHECK-DAG: Return [<<Const4>>]
708
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700709 /// CHECK-START: int Main.ShlIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100710 /// CHECK-NOT: Shl
711
712 public static int ShlIntLong() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000713 int lhs = $inline$int(1);
714 long rhs = $inline$long(2L);
Roland Levillain9867bc72015-08-05 10:21:34 +0100715 return lhs << rhs;
716 }
717
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700718 /// CHECK-START: long Main.ShlLongInt() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100719 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3
720 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
721 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Const3L>>,<<Const2>>]
722 /// CHECK-DAG: Return [<<Shl>>]
723
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700724 /// CHECK-START: long Main.ShlLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100725 /// CHECK-DAG: <<Const12L:j\d+>> LongConstant 12
726 /// CHECK-DAG: Return [<<Const12L>>]
727
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700728 /// CHECK-START: long Main.ShlLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100729 /// CHECK-NOT: Shl
730
731 public static long ShlLongInt() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000732 long lhs = $inline$long(3L);
733 int rhs = $inline$int(2);
Roland Levillain9867bc72015-08-05 10:21:34 +0100734 return lhs << rhs;
735 }
736
737
738 /**
739 * Exercise constant folding on right shift.
740 */
741
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700742 /// CHECK-START: int Main.ShrIntLong() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100743 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
744 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2
745 /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>]
746 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Const7>>,<<TypeConv>>]
747 /// CHECK-DAG: Return [<<Shr>>]
748
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700749 /// CHECK-START: int Main.ShrIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100750 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
751 /// CHECK-DAG: Return [<<Const1>>]
752
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700753 /// CHECK-START: int Main.ShrIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100754 /// CHECK-NOT: Shr
755
756 public static int ShrIntLong() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000757 int lhs = $inline$int(7);
758 long rhs = $inline$long(2L);
Roland Levillain9867bc72015-08-05 10:21:34 +0100759 return lhs >> rhs;
760 }
761
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700762 /// CHECK-START: long Main.ShrLongInt() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100763 /// CHECK-DAG: <<Const9L:j\d+>> LongConstant 9
764 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
765 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const9L>>,<<Const2>>]
766 /// CHECK-DAG: Return [<<Shr>>]
767
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700768 /// CHECK-START: long Main.ShrLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100769 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2
770 /// CHECK-DAG: Return [<<Const2L>>]
771
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700772 /// CHECK-START: long Main.ShrLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100773 /// CHECK-NOT: Shr
774
775 public static long ShrLongInt() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000776 long lhs = $inline$long(9);
777 int rhs = $inline$int(2);
Roland Levillain9867bc72015-08-05 10:21:34 +0100778 return lhs >> rhs;
779 }
780
781
782 /**
783 * Exercise constant folding on unsigned right shift.
784 */
785
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700786 /// CHECK-START: int Main.UShrIntLong() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100787 /// CHECK-DAG: <<ConstM7:i\d+>> IntConstant -7
788 /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2
789 /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>]
790 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<ConstM7>>,<<TypeConv>>]
791 /// CHECK-DAG: Return [<<UShr>>]
792
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700793 /// CHECK-START: int Main.UShrIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100794 /// CHECK-DAG: <<ConstRes:i\d+>> IntConstant 1073741822
795 /// CHECK-DAG: Return [<<ConstRes>>]
796
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700797 /// CHECK-START: int Main.UShrIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100798 /// CHECK-NOT: UShr
799
800 public static int UShrIntLong() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000801 int lhs = $inline$int(-7);
802 long rhs = $inline$long(2L);
Roland Levillain9867bc72015-08-05 10:21:34 +0100803 return lhs >>> rhs;
804 }
805
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700806 /// CHECK-START: long Main.UShrLongInt() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100807 /// CHECK-DAG: <<ConstM9L:j\d+>> LongConstant -9
808 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
809 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<ConstM9L>>,<<Const2>>]
810 /// CHECK-DAG: Return [<<UShr>>]
811
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700812 /// CHECK-START: long Main.UShrLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100813 /// CHECK-DAG: <<ConstRes:j\d+>> LongConstant 4611686018427387901
814 /// CHECK-DAG: Return [<<ConstRes>>]
815
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700816 /// CHECK-START: long Main.UShrLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100817 /// CHECK-NOT: UShr
818
819 public static long UShrLongInt() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000820 long lhs = $inline$long(-9);
821 int rhs = $inline$int(2);
Roland Levillain9867bc72015-08-05 10:21:34 +0100822 return lhs >>> rhs;
823 }
824
825
826 /**
827 * Exercise constant folding on logical and.
828 */
829
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700830 /// CHECK-START: long Main.AndIntLong() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100831 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10
832 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3
833 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>]
834 /// CHECK-DAG: <<And:j\d+>> And [<<TypeConv>>,<<Const3L>>]
835 /// CHECK-DAG: Return [<<And>>]
836
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700837 /// CHECK-START: long Main.AndIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100838 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
839 /// CHECK-DAG: Return [<<Const2>>]
840
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700841 /// CHECK-START: long Main.AndIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100842 /// CHECK-NOT: And
843
844 public static long AndIntLong() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000845 int lhs = $inline$int(10);
846 long rhs = $inline$long(3L);
Roland Levillain9867bc72015-08-05 10:21:34 +0100847 return lhs & rhs;
848 }
849
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700850 /// CHECK-START: long Main.AndLongInt() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100851 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10
852 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
853 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000854 /// CHECK-DAG: <<And:j\d+>> And [<<TypeConv>>,<<Const10L>>]
Roland Levillain9867bc72015-08-05 10:21:34 +0100855 /// CHECK-DAG: Return [<<And>>]
856
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700857 /// CHECK-START: long Main.AndLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100858 /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2
859 /// CHECK-DAG: Return [<<Const2>>]
860
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700861 /// CHECK-START: long Main.AndLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100862 /// CHECK-NOT: And
863
864 public static long AndLongInt() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000865 long lhs = $inline$long(10L);
866 int rhs = $inline$int(3);
Roland Levillain9867bc72015-08-05 10:21:34 +0100867 return lhs & rhs;
868 }
869
870
871 /**
872 * Exercise constant folding on logical or.
873 */
874
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700875 /// CHECK-START: long Main.OrIntLong() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100876 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10
877 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3
878 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>]
879 /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const3L>>]
880 /// CHECK-DAG: Return [<<Or>>]
881
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700882 /// CHECK-START: long Main.OrIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100883 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11
884 /// CHECK-DAG: Return [<<Const11>>]
885
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700886 /// CHECK-START: long Main.OrIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100887 /// CHECK-NOT: Or
888
889 public static long OrIntLong() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000890 int lhs = $inline$int(10);
891 long rhs = $inline$long(3L);
Roland Levillain9867bc72015-08-05 10:21:34 +0100892 return lhs | rhs;
893 }
894
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700895 /// CHECK-START: long Main.OrLongInt() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100896 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10
897 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
898 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000899 /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const10L>>]
Roland Levillain9867bc72015-08-05 10:21:34 +0100900 /// CHECK-DAG: Return [<<Or>>]
901
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700902 /// CHECK-START: long Main.OrLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100903 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11
904 /// CHECK-DAG: Return [<<Const11>>]
905
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700906 /// CHECK-START: long Main.OrLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100907 /// CHECK-NOT: Or
908
909 public static long OrLongInt() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000910 long lhs = $inline$long(10L);
911 int rhs = $inline$int(3);
Roland Levillain9867bc72015-08-05 10:21:34 +0100912 return lhs | rhs;
913 }
914
915
916 /**
917 * Exercise constant folding on logical exclusive or.
918 */
919
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700920 /// CHECK-START: long Main.XorIntLong() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100921 /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10
922 /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3
923 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>]
924 /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const3L>>]
925 /// CHECK-DAG: Return [<<Xor>>]
926
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700927 /// CHECK-START: long Main.XorIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100928 /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9
929 /// CHECK-DAG: Return [<<Const9>>]
930
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700931 /// CHECK-START: long Main.XorIntLong() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100932 /// CHECK-NOT: Xor
933
934 public static long XorIntLong() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000935 int lhs = $inline$int(10);
936 long rhs = $inline$long(3L);
Roland Levillain9867bc72015-08-05 10:21:34 +0100937 return lhs ^ rhs;
938 }
939
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700940 /// CHECK-START: long Main.XorLongInt() constant_folding$after_inlining (before)
Roland Levillain9867bc72015-08-05 10:21:34 +0100941 /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10
942 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
943 /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000944 /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const10L>>]
Roland Levillain9867bc72015-08-05 10:21:34 +0100945 /// CHECK-DAG: Return [<<Xor>>]
946
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700947 /// CHECK-START: long Main.XorLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100948 /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9
949 /// CHECK-DAG: Return [<<Const9>>]
950
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700951 /// CHECK-START: long Main.XorLongInt() constant_folding$after_inlining (after)
Roland Levillain9867bc72015-08-05 10:21:34 +0100952 /// CHECK-NOT: Xor
953
954 public static long XorLongInt() {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000955 long lhs = $inline$long(10L);
956 int rhs = $inline$int(3);
Roland Levillain9867bc72015-08-05 10:21:34 +0100957 return lhs ^ rhs;
958 }
959
960
961 /**
Roland Levillainb65eb502015-07-23 12:11:42 +0100962 * Exercise constant folding on constant (static) condition.
David Brazdilee690a32014-12-01 17:04:16 +0000963 */
964
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700965 /// CHECK-START: int Main.StaticCondition() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100966 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
967 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
968 /// CHECK-DAG: <<Cond:z\d+>> GreaterThanOrEqual [<<Const7>>,<<Const2>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +0000969 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Cond>>]
David Brazdilee690a32014-12-01 17:04:16 +0000970
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700971 /// CHECK-START: int Main.StaticCondition() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100972 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdilf02c3cf2016-02-29 09:14:51 +0000973 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Const1>>]
David Brazdilee690a32014-12-01 17:04:16 +0000974
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700975 /// CHECK-START: int Main.StaticCondition() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +0100976 /// CHECK-NOT: GreaterThanOrEqual
977
David Brazdilee690a32014-12-01 17:04:16 +0000978 public static int StaticCondition() {
979 int a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000980 a = $inline$int(7);
981 b = $inline$int(2);
David Brazdilee690a32014-12-01 17:04:16 +0000982 if (a < b)
983 c = a + b;
984 else
985 c = a - b;
986 return c;
987 }
988
Roland Levillainb65eb502015-07-23 12:11:42 +0100989
David Brazdilee690a32014-12-01 17:04:16 +0000990 /**
Vladimir Marko9e23df52015-11-10 17:14:35 +0000991 * Exercise constant folding on constant (static) condition for null references.
992 */
993
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700994 /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (before)
Vladimir Marko9e23df52015-11-10 17:14:35 +0000995 /// CHECK-DAG: <<Null:l\d+>> NullConstant
996 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Null>>,<<Null>>]
David Brazdil74eb1b22015-12-14 11:44:01 +0000997 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Cond>>]
Vladimir Marko9e23df52015-11-10 17:14:35 +0000998
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700999 /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (after)
Vladimir Marko9e23df52015-11-10 17:14:35 +00001000 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001001 /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Const0>>]
Vladimir Marko9e23df52015-11-10 17:14:35 +00001002
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001003 /// CHECK-START: int Main.StaticConditionNulls() constant_folding$after_inlining (after)
Vladimir Marko9e23df52015-11-10 17:14:35 +00001004 /// CHECK-NOT: NotEqual
1005
1006 private static Object getNull() {
1007 return null;
1008 }
1009
1010 public static int StaticConditionNulls() {
1011 Object a = getNull();
1012 Object b = getNull();
1013 return (a == b) ? 5 : 2;
1014 }
1015
1016
1017 /**
Roland Levillainb65eb502015-07-23 12:11:42 +01001018 * Exercise constant folding on a program with condition
1019 * (i.e. jumps) leading to the creation of many blocks.
David Brazdilee690a32014-12-01 17:04:16 +00001020 *
1021 * The intent of this test is to ensure that all constant expressions
1022 * are actually evaluated at compile-time, thanks to the reverse
1023 * (forward) post-order traversal of the the dominator tree.
1024 */
1025
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001026 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding$after_inlining (before)
David Brazdilf02c3cf2016-02-29 09:14:51 +00001027 /// CHECK-DAG: <<Cond:z\d+>> ParameterValue
David Brazdila06d66a2015-05-28 11:14:54 +01001028 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
1029 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1030 /// CHECK-DAG: <<Add:i\d+>> Add [<<Const5>>,<<Const2>>]
1031 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<Const2>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +00001032 /// CHECK-DAG: <<Phi:i\d+>> Select [<<Sub>>,<<Add>>,<<Cond>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001033 /// CHECK-DAG: Return [<<Phi>>]
David Brazdilee690a32014-12-01 17:04:16 +00001034
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001035 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding$after_inlining (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +00001036 /// CHECK-DAG: <<Cond:z\d+>> ParameterValue
David Brazdila06d66a2015-05-28 11:14:54 +01001037 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1038 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
David Brazdilf02c3cf2016-02-29 09:14:51 +00001039 /// CHECK-DAG: <<Phi:i\d+>> Select [<<Const3>>,<<Const7>>,<<Cond>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001040 /// CHECK-DAG: Return [<<Phi>>]
David Brazdilee690a32014-12-01 17:04:16 +00001041
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001042 /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001043 /// CHECK-NOT: Add
1044 /// CHECK-NOT: Sub
1045
David Brazdilee690a32014-12-01 17:04:16 +00001046 public static int JumpsAndConditionals(boolean cond) {
1047 int a, b, c;
David Brazdilf02c3cf2016-02-29 09:14:51 +00001048 a = $inline$int(5);
1049 b = $inline$int(2);
David Brazdilee690a32014-12-01 17:04:16 +00001050 if (cond)
1051 c = a + b;
1052 else
1053 c = a - b;
1054 return c;
1055 }
David Brazdil4846d132015-01-15 19:07:08 +00001056
Roland Levillainb65eb502015-07-23 12:11:42 +01001057
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001058 /**
1059 * Test optimizations of arithmetic identities yielding a constant result.
1060 */
1061
David Brazdila06d66a2015-05-28 11:14:54 +01001062 /// CHECK-START: int Main.And0(int) constant_folding (before)
1063 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1064 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1065 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const0>>]
1066 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001067
David Brazdila06d66a2015-05-28 11:14:54 +01001068 /// CHECK-START: int Main.And0(int) constant_folding (after)
1069 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1070 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001071 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001072
Roland Levillainb65eb502015-07-23 12:11:42 +01001073 /// CHECK-START: int Main.And0(int) constant_folding (after)
1074 /// CHECK-NOT: And
1075
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001076 public static int And0(int arg) {
1077 return arg & 0;
1078 }
1079
David Brazdila06d66a2015-05-28 11:14:54 +01001080 /// CHECK-START: long Main.Mul0(long) constant_folding (before)
1081 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1082 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdil57e863c2016-01-11 10:27:13 +00001083 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const0>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001084 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001085
David Brazdila06d66a2015-05-28 11:14:54 +01001086 /// CHECK-START: long Main.Mul0(long) constant_folding (after)
1087 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1088 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001089 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001090
Roland Levillainb65eb502015-07-23 12:11:42 +01001091 /// CHECK-START: long Main.Mul0(long) constant_folding (after)
1092 /// CHECK-NOT: Mul
1093
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001094 public static long Mul0(long arg) {
1095 return arg * 0;
1096 }
1097
David Brazdila06d66a2015-05-28 11:14:54 +01001098 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (before)
1099 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1100 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
1101 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<ConstF>>]
1102 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001103
David Brazdila06d66a2015-05-28 11:14:54 +01001104 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
1105 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
David Brazdila06d66a2015-05-28 11:14:54 +01001106 /// CHECK-DAG: Return [<<ConstF>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001107
Roland Levillainb65eb502015-07-23 12:11:42 +01001108 /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after)
1109 /// CHECK-NOT: Or
1110
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001111 public static int OrAllOnes(int arg) {
1112 return arg | -1;
1113 }
1114
David Brazdila06d66a2015-05-28 11:14:54 +01001115 /// CHECK-START: long Main.Rem0(long) constant_folding (before)
1116 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1117 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
1118 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<Arg>>]
1119 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const0>>,<<DivZeroCheck>>]
1120 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001121
David Brazdila06d66a2015-05-28 11:14:54 +01001122 /// CHECK-START: long Main.Rem0(long) constant_folding (after)
1123 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001124 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001125
Roland Levillainb65eb502015-07-23 12:11:42 +01001126 /// CHECK-START: long Main.Rem0(long) constant_folding (after)
1127 /// CHECK-NOT: Rem
1128
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001129 public static long Rem0(long arg) {
1130 return 0 % arg;
1131 }
1132
David Brazdila06d66a2015-05-28 11:14:54 +01001133 /// CHECK-START: int Main.Rem1(int) constant_folding (before)
1134 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1135 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1136 /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Arg>>,<<Const1>>]
1137 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001138
David Brazdila06d66a2015-05-28 11:14:54 +01001139 /// CHECK-START: int Main.Rem1(int) constant_folding (after)
1140 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001141 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001142
Roland Levillainb65eb502015-07-23 12:11:42 +01001143 /// CHECK-START: int Main.Rem1(int) constant_folding (after)
1144 /// CHECK-NOT: Rem
1145
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001146 public static int Rem1(int arg) {
1147 return arg % 1;
1148 }
1149
David Brazdila06d66a2015-05-28 11:14:54 +01001150 /// CHECK-START: long Main.RemN1(long) constant_folding (before)
1151 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1152 /// CHECK-DAG: <<ConstN1:j\d+>> LongConstant -1
1153 /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<ConstN1>>]
1154 /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Arg>>,<<DivZeroCheck>>]
1155 /// CHECK-DAG: Return [<<Rem>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001156
David Brazdila06d66a2015-05-28 11:14:54 +01001157 /// CHECK-START: long Main.RemN1(long) constant_folding (after)
1158 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001159 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001160
Roland Levillainb65eb502015-07-23 12:11:42 +01001161 /// CHECK-START: long Main.RemN1(long) constant_folding (after)
1162 /// CHECK-NOT: Rem
1163
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001164 public static long RemN1(long arg) {
1165 return arg % -1;
1166 }
1167
David Brazdila06d66a2015-05-28 11:14:54 +01001168 /// CHECK-START: int Main.Shl0(int) constant_folding (before)
1169 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1170 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1171 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const0>>,<<Arg>>]
1172 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001173
David Brazdila06d66a2015-05-28 11:14:54 +01001174 /// CHECK-START: int Main.Shl0(int) constant_folding (after)
1175 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1176 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001177 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001178
Roland Levillainb65eb502015-07-23 12:11:42 +01001179 /// CHECK-START: int Main.Shl0(int) constant_folding (after)
1180 /// CHECK-NOT: Shl
1181
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001182 public static int Shl0(int arg) {
1183 return 0 << arg;
1184 }
1185
Roland Levillain9867bc72015-08-05 10:21:34 +01001186 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (before)
1187 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1188 /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0
1189 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Const0L>>,<<Arg>>]
1190 /// CHECK-DAG: Return [<<Shl>>]
1191
1192 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after)
1193 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1194 /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0
1195 /// CHECK-DAG: Return [<<Const0L>>]
1196
1197 /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after)
1198 /// CHECK-NOT: Shl
1199
1200 public static long ShlLong0WithInt(int arg) {
1201 long long_zero = 0;
1202 return long_zero << arg;
1203 }
1204
David Brazdila06d66a2015-05-28 11:14:54 +01001205 /// CHECK-START: long Main.Shr0(int) constant_folding (before)
1206 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1207 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
1208 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const0>>,<<Arg>>]
1209 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001210
David Brazdila06d66a2015-05-28 11:14:54 +01001211 /// CHECK-START: long Main.Shr0(int) constant_folding (after)
1212 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1213 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001214 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001215
Roland Levillainb65eb502015-07-23 12:11:42 +01001216 /// CHECK-START: long Main.Shr0(int) constant_folding (after)
1217 /// CHECK-NOT: Shr
1218
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001219 public static long Shr0(int arg) {
1220 return (long)0 >> arg;
1221 }
1222
David Brazdila06d66a2015-05-28 11:14:54 +01001223 /// CHECK-START: long Main.SubSameLong(long) constant_folding (before)
1224 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1225 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Arg>>]
1226 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001227
David Brazdila06d66a2015-05-28 11:14:54 +01001228 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
1229 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1230 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001231 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001232
Roland Levillainb65eb502015-07-23 12:11:42 +01001233 /// CHECK-START: long Main.SubSameLong(long) constant_folding (after)
1234 /// CHECK-NOT: Sub
1235
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001236 public static long SubSameLong(long arg) {
1237 return arg - arg;
1238 }
1239
David Brazdila06d66a2015-05-28 11:14:54 +01001240 /// CHECK-START: int Main.UShr0(int) constant_folding (before)
1241 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1242 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1243 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Const0>>,<<Arg>>]
1244 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001245
David Brazdila06d66a2015-05-28 11:14:54 +01001246 /// CHECK-START: int Main.UShr0(int) constant_folding (after)
1247 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1248 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001249 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001250
Roland Levillainb65eb502015-07-23 12:11:42 +01001251 /// CHECK-START: int Main.UShr0(int) constant_folding (after)
1252 /// CHECK-NOT: UShr
1253
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001254 public static int UShr0(int arg) {
1255 return 0 >>> arg;
1256 }
1257
David Brazdila06d66a2015-05-28 11:14:54 +01001258 /// CHECK-START: int Main.XorSameInt(int) constant_folding (before)
1259 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1260 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Arg>>]
1261 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001262
David Brazdila06d66a2015-05-28 11:14:54 +01001263 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
1264 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1265 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdila06d66a2015-05-28 11:14:54 +01001266 /// CHECK-DAG: Return [<<Const0>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001267
Roland Levillainb65eb502015-07-23 12:11:42 +01001268 /// CHECK-START: int Main.XorSameInt(int) constant_folding (after)
1269 /// CHECK-NOT: Xor
1270
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001271 public static int XorSameInt(int arg) {
1272 return arg ^ arg;
1273 }
1274
David Brazdila06d66a2015-05-28 11:14:54 +01001275 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (before)
1276 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1277 /// CHECK-DAG: <<ConstNan:f\d+>> FloatConstant nan
1278 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1279 /// CHECK-DAG: IntConstant 1
1280 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>]
1281 /// CHECK-DAG: <<Le:z\d+>> LessThanOrEqual [<<Cmp>>,<<Const0>>]
1282 /// CHECK-DAG: If [<<Le>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001283
David Brazdila06d66a2015-05-28 11:14:54 +01001284 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
1285 /// CHECK-DAG: ParameterValue
1286 /// CHECK-DAG: FloatConstant nan
1287 /// CHECK-DAG: IntConstant 0
1288 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1289 /// CHECK-DAG: If [<<Const1>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001290
David Brazdila06d66a2015-05-28 11:14:54 +01001291 /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after)
1292 /// CHECK-NOT: Compare
1293 /// CHECK-NOT: LessThanOrEqual
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001294
1295 public static boolean CmpFloatGreaterThanNaN(float arg) {
1296 return arg > Float.NaN;
1297 }
1298
David Brazdila06d66a2015-05-28 11:14:54 +01001299 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (before)
1300 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1301 /// CHECK-DAG: <<ConstNan:d\d+>> DoubleConstant nan
1302 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1303 /// CHECK-DAG: IntConstant 1
1304 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>]
1305 /// CHECK-DAG: <<Ge:z\d+>> GreaterThanOrEqual [<<Cmp>>,<<Const0>>]
1306 /// CHECK-DAG: If [<<Ge>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001307
David Brazdila06d66a2015-05-28 11:14:54 +01001308 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
1309 /// CHECK-DAG: ParameterValue
1310 /// CHECK-DAG: DoubleConstant nan
1311 /// CHECK-DAG: IntConstant 0
1312 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1313 /// CHECK-DAG: If [<<Const1>>]
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001314
David Brazdila06d66a2015-05-28 11:14:54 +01001315 /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after)
1316 /// CHECK-NOT: Compare
1317 /// CHECK-NOT: GreaterThanOrEqual
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001318
1319 public static boolean CmpDoubleLessThanNaN(double arg) {
1320 return arg < Double.NaN;
1321 }
1322
Roland Levillainb65eb502015-07-23 12:11:42 +01001323
1324 /**
1325 * Exercise constant folding on type conversions.
1326 */
1327
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001328 /// CHECK-START: int Main.ReturnInt33() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001329 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
1330 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<Const33>>]
1331 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001332
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001333 /// CHECK-START: int Main.ReturnInt33() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001334 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
1335 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001336
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001337 /// CHECK-START: int Main.ReturnInt33() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001338 /// CHECK-NOT: TypeConversion
1339
Mark Mendelle82549b2015-05-06 10:55:34 -04001340 public static int ReturnInt33() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001341 long imm = $inline$long(33L);
Mark Mendelle82549b2015-05-06 10:55:34 -04001342 return (int) imm;
1343 }
1344
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001345 /// CHECK-START: int Main.ReturnIntMax() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001346 /// CHECK-DAG: <<ConstMax:f\d+>> FloatConstant 1e+34
1347 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstMax>>]
1348 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001349
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001350 /// CHECK-START: int Main.ReturnIntMax() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001351 /// CHECK-DAG: <<ConstMax:i\d+>> IntConstant 2147483647
1352 /// CHECK-DAG: Return [<<ConstMax>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001353
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001354 /// CHECK-START: int Main.ReturnIntMax() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001355 /// CHECK-NOT: TypeConversion
1356
Mark Mendelle82549b2015-05-06 10:55:34 -04001357 public static int ReturnIntMax() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001358 float imm = $inline$float(1.0e34f);
Mark Mendelle82549b2015-05-06 10:55:34 -04001359 return (int) imm;
1360 }
1361
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001362 /// CHECK-START: int Main.ReturnInt0() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001363 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan
1364 /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstNaN>>]
1365 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001366
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001367 /// CHECK-START: int Main.ReturnInt0() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001368 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1369 /// CHECK-DAG: Return [<<Const0>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001370
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001371 /// CHECK-START: int Main.ReturnInt0() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001372 /// CHECK-NOT: TypeConversion
1373
Mark Mendelle82549b2015-05-06 10:55:34 -04001374 public static int ReturnInt0() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001375 double imm = $inline$double(Double.NaN);
Mark Mendelle82549b2015-05-06 10:55:34 -04001376 return (int) imm;
1377 }
1378
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001379 /// CHECK-START: long Main.ReturnLong33() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001380 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
1381 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const33>>]
1382 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001383
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001384 /// CHECK-START: long Main.ReturnLong33() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001385 /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33
1386 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001387
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001388 /// CHECK-START: long Main.ReturnLong33() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001389 /// CHECK-NOT: TypeConversion
1390
Mark Mendelle82549b2015-05-06 10:55:34 -04001391 public static long ReturnLong33() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001392 int imm = $inline$int(33);
Mark Mendelle82549b2015-05-06 10:55:34 -04001393 return (long) imm;
1394 }
1395
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001396 /// CHECK-START: long Main.ReturnLong34() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001397 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34
1398 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const34>>]
1399 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001400
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001401 /// CHECK-START: long Main.ReturnLong34() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001402 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
1403 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001404
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001405 /// CHECK-START: long Main.ReturnLong34() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001406 /// CHECK-NOT: TypeConversion
1407
Mark Mendelle82549b2015-05-06 10:55:34 -04001408 public static long ReturnLong34() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001409 float imm = $inline$float(34.0f);
Mark Mendelle82549b2015-05-06 10:55:34 -04001410 return (long) imm;
1411 }
1412
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001413 /// CHECK-START: long Main.ReturnLong0() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001414 /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan
1415 /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<ConstNaN>>]
1416 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001417
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001418 /// CHECK-START: long Main.ReturnLong0() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001419 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
1420 /// CHECK-DAG: Return [<<Const0>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001421
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001422 /// CHECK-START: long Main.ReturnLong0() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001423 /// CHECK-NOT: TypeConversion
1424
Mark Mendelle82549b2015-05-06 10:55:34 -04001425 public static long ReturnLong0() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001426 double imm = $inline$double(-Double.NaN);
Mark Mendelle82549b2015-05-06 10:55:34 -04001427 return (long) imm;
1428 }
1429
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001430 /// CHECK-START: float Main.ReturnFloat33() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001431 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
1432 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const33>>]
1433 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001434
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001435 /// CHECK-START: float Main.ReturnFloat33() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001436 /// CHECK-DAG: <<Const33:f\d+>> FloatConstant 33
1437 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001438
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001439 /// CHECK-START: float Main.ReturnFloat33() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001440 /// CHECK-NOT: TypeConversion
1441
Mark Mendelle82549b2015-05-06 10:55:34 -04001442 public static float ReturnFloat33() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001443 int imm = $inline$int(33);
Mark Mendelle82549b2015-05-06 10:55:34 -04001444 return (float) imm;
1445 }
1446
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001447 /// CHECK-START: float Main.ReturnFloat34() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001448 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
1449 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const34>>]
1450 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001451
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001452 /// CHECK-START: float Main.ReturnFloat34() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001453 /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34
1454 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001455
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001456 /// CHECK-START: float Main.ReturnFloat34() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001457 /// CHECK-NOT: TypeConversion
1458
Mark Mendelle82549b2015-05-06 10:55:34 -04001459 public static float ReturnFloat34() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001460 long imm = $inline$long(34L);
Mark Mendelle82549b2015-05-06 10:55:34 -04001461 return (float) imm;
1462 }
1463
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001464 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001465 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25
1466 /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const>>]
1467 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001468
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001469 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001470 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25
1471 /// CHECK-DAG: Return [<<Const>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001472
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001473 /// CHECK-START: float Main.ReturnFloat99P25() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001474 /// CHECK-NOT: TypeConversion
1475
Mark Mendelle82549b2015-05-06 10:55:34 -04001476 public static float ReturnFloat99P25() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001477 double imm = $inline$double(99.25);
Mark Mendelle82549b2015-05-06 10:55:34 -04001478 return (float) imm;
1479 }
1480
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001481 /// CHECK-START: double Main.ReturnDouble33() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001482 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
1483 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const33>>]
1484 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001485
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001486 /// CHECK-START: double Main.ReturnDouble33() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001487 /// CHECK-DAG: <<Const33:d\d+>> DoubleConstant 33
1488 /// CHECK-DAG: Return [<<Const33>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001489
1490 public static double ReturnDouble33() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001491 int imm = $inline$int(33);
Mark Mendelle82549b2015-05-06 10:55:34 -04001492 return (double) imm;
1493 }
1494
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001495 /// CHECK-START: double Main.ReturnDouble34() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001496 /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34
1497 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const34>>]
1498 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001499
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001500 /// CHECK-START: double Main.ReturnDouble34() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001501 /// CHECK-DAG: <<Const34:d\d+>> DoubleConstant 34
1502 /// CHECK-DAG: Return [<<Const34>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001503
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001504 /// CHECK-START: double Main.ReturnDouble34() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001505 /// CHECK-NOT: TypeConversion
1506
Mark Mendelle82549b2015-05-06 10:55:34 -04001507 public static double ReturnDouble34() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001508 long imm = $inline$long(34L);
Mark Mendelle82549b2015-05-06 10:55:34 -04001509 return (double) imm;
1510 }
1511
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001512 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001513 /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25
1514 /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const>>]
1515 /// CHECK-DAG: Return [<<Convert>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001516
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001517 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001518 /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25
1519 /// CHECK-DAG: Return [<<Const>>]
Mark Mendelle82549b2015-05-06 10:55:34 -04001520
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001521 /// CHECK-START: double Main.ReturnDouble99P25() constant_folding$after_inlining (after)
Roland Levillainb65eb502015-07-23 12:11:42 +01001522 /// CHECK-NOT: TypeConversion
1523
Mark Mendelle82549b2015-05-06 10:55:34 -04001524 public static double ReturnDouble99P25() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001525 float imm = $inline$float(99.25f);
Mark Mendelle82549b2015-05-06 10:55:34 -04001526 return (double) imm;
1527 }
1528
Roland Levillainb65eb502015-07-23 12:11:42 +01001529
Roland Levillain31dd3d62016-02-16 12:21:02 +00001530 public static void main(String[] args) throws Exception {
Roland Levillainb65eb502015-07-23 12:11:42 +01001531 assertIntEquals(-42, IntNegation());
Roland Levillainc90bc7c2014-12-11 12:14:33 +00001532 assertLongEquals(-42L, LongNegation());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001533 assertFloatEquals(-42F, FloatNegation());
1534 assertDoubleEquals(-42D, DoubleNegation());
Roland Levillainb65eb502015-07-23 12:11:42 +01001535
1536 assertIntEquals(3, IntAddition1());
1537 assertIntEquals(14, IntAddition2());
1538 assertLongEquals(3L, LongAddition());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001539 assertFloatEquals(3F, FloatAddition());
1540 assertDoubleEquals(3D, DoubleAddition());
Roland Levillainb65eb502015-07-23 12:11:42 +01001541
1542 assertIntEquals(4, IntSubtraction());
1543 assertLongEquals(4L, LongSubtraction());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001544 assertFloatEquals(4F, FloatSubtraction());
1545 assertDoubleEquals(4D, DoubleSubtraction());
Roland Levillainb65eb502015-07-23 12:11:42 +01001546
Roland Levillainf7746ad2015-07-22 14:12:01 +01001547 assertIntEquals(21, IntMultiplication());
1548 assertLongEquals(21L, LongMultiplication());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001549 assertFloatEquals(21F, FloatMultiplication());
1550 assertDoubleEquals(21D, DoubleMultiplication());
Roland Levillainf7746ad2015-07-22 14:12:01 +01001551
1552 assertIntEquals(2, IntDivision());
1553 assertLongEquals(2L, LongDivision());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001554 assertFloatEquals(3.2F, FloatDivision());
1555 assertDoubleEquals(3.2D, DoubleDivision());
Roland Levillainf7746ad2015-07-22 14:12:01 +01001556
1557 assertIntEquals(2, IntRemainder());
1558 assertLongEquals(2L, LongRemainder());
Roland Levillain31dd3d62016-02-16 12:21:02 +00001559 assertFloatEquals(0.5F, FloatRemainder());
1560 assertDoubleEquals(0.5D, DoubleRemainder());
Roland Levillainf7746ad2015-07-22 14:12:01 +01001561
Roland Levillain9867bc72015-08-05 10:21:34 +01001562 assertIntEquals(4, ShlIntLong());
1563 assertLongEquals(12L, ShlLongInt());
1564
1565 assertIntEquals(1, ShrIntLong());
1566 assertLongEquals(2L, ShrLongInt());
1567
1568 assertIntEquals(1073741822, UShrIntLong());
1569 assertLongEquals(4611686018427387901L, UShrLongInt());
1570
1571 assertLongEquals(2, AndIntLong());
1572 assertLongEquals(2, AndLongInt());
1573
1574 assertLongEquals(11, OrIntLong());
1575 assertLongEquals(11, OrLongInt());
1576
1577 assertLongEquals(9, XorIntLong());
1578 assertLongEquals(9, XorLongInt());
1579
Roland Levillainb65eb502015-07-23 12:11:42 +01001580 assertIntEquals(5, StaticCondition());
Vladimir Marko9e23df52015-11-10 17:14:35 +00001581 assertIntEquals(5, StaticConditionNulls());
Roland Levillainb65eb502015-07-23 12:11:42 +01001582
1583 assertIntEquals(7, JumpsAndConditionals(true));
1584 assertIntEquals(3, JumpsAndConditionals(false));
1585
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001586 int arbitrary = 123456; // Value chosen arbitrarily.
Roland Levillainb65eb502015-07-23 12:11:42 +01001587
1588 assertIntEquals(0, And0(arbitrary));
1589 assertLongEquals(0, Mul0(arbitrary));
1590 assertIntEquals(-1, OrAllOnes(arbitrary));
1591 assertLongEquals(0, Rem0(arbitrary));
1592 assertIntEquals(0, Rem1(arbitrary));
1593 assertLongEquals(0, RemN1(arbitrary));
1594 assertIntEquals(0, Shl0(arbitrary));
Roland Levillain9867bc72015-08-05 10:21:34 +01001595 assertLongEquals(0, ShlLong0WithInt(arbitrary));
Roland Levillainb65eb502015-07-23 12:11:42 +01001596 assertLongEquals(0, Shr0(arbitrary));
1597 assertLongEquals(0, SubSameLong(arbitrary));
1598 assertIntEquals(0, UShr0(arbitrary));
1599 assertIntEquals(0, XorSameInt(arbitrary));
1600
Roland Levillain3b55ebb2015-05-08 13:13:19 +01001601 assertFalse(CmpFloatGreaterThanNaN(arbitrary));
1602 assertFalse(CmpDoubleLessThanNaN(arbitrary));
Roland Levillainb65eb502015-07-23 12:11:42 +01001603
Roland Levillain31dd3d62016-02-16 12:21:02 +00001604 Main main = new Main();
1605 assertIntEquals(1, main.smaliCmpLongConstants());
1606 assertIntEquals(-1, main.smaliCmpGtFloatConstants());
1607 assertIntEquals(-1, main.smaliCmpLtFloatConstants());
1608 assertIntEquals(-1, main.smaliCmpGtDoubleConstants());
1609 assertIntEquals(-1, main.smaliCmpLtDoubleConstants());
1610
1611 assertIntEquals(0, main.smaliCmpLongSameConstant());
1612 assertIntEquals(0, main.smaliCmpGtFloatSameConstant());
1613 assertIntEquals(0, main.smaliCmpLtFloatSameConstant());
1614 assertIntEquals(0, main.smaliCmpGtDoubleSameConstant());
1615 assertIntEquals(0, main.smaliCmpLtDoubleSameConstant());
1616
1617 assertIntEquals(1, main.smaliCmpGtFloatConstantWithNaN());
1618 assertIntEquals(-1, main.smaliCmpLtFloatConstantWithNaN());
1619 assertIntEquals(1, main.smaliCmpGtDoubleConstantWithNaN());
1620 assertIntEquals(-1, main.smaliCmpLtDoubleConstantWithNaN());
1621
Roland Levillainb65eb502015-07-23 12:11:42 +01001622 assertIntEquals(33, ReturnInt33());
1623 assertIntEquals(2147483647, ReturnIntMax());
1624 assertIntEquals(0, ReturnInt0());
1625
1626 assertLongEquals(33, ReturnLong33());
1627 assertLongEquals(34, ReturnLong34());
1628 assertLongEquals(0, ReturnLong0());
1629
1630 assertFloatEquals(33, ReturnFloat33());
1631 assertFloatEquals(34, ReturnFloat34());
1632 assertFloatEquals(99.25f, ReturnFloat99P25());
1633
1634 assertDoubleEquals(33, ReturnDouble33());
1635 assertDoubleEquals(34, ReturnDouble34());
1636 assertDoubleEquals(99.25, ReturnDouble99P25());
David Brazdil4846d132015-01-15 19:07:08 +00001637 }
Roland Levillain31dd3d62016-02-16 12:21:02 +00001638
1639 Main() throws ClassNotFoundException {
1640 testCmp = Class.forName("TestCmp");
1641 }
1642
1643 private Class<?> testCmp;
David Brazdilee690a32014-12-01 17:04:16 +00001644}