blob: c4cc3b012143dff0d3e4c46fc60d9bb10f525192 [file] [log] [blame]
Mingyao Yang8df69d42015-10-22 15:40:58 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17class Circle {
18 Circle(double radius) {
19 this.radius = radius;
20 }
Mingyao Yange58bdca2016-10-28 11:07:24 -070021 public double getRadius() {
22 return radius;
23 }
Mingyao Yang8df69d42015-10-22 15:40:58 -070024 public double getArea() {
25 return radius * radius * Math.PI;
26 }
27 private double radius;
Mingyao Yangfb8464a2015-11-02 10:56:59 -080028}
Mingyao Yang8df69d42015-10-22 15:40:58 -070029
30class TestClass {
Mingyao Yang8ab1d642015-12-03 14:11:15 -080031 static {
32 sTestClassObj = new TestClass(-1, -2);
33 }
Mingyao Yang8df69d42015-10-22 15:40:58 -070034 TestClass() {
35 }
36 TestClass(int i, int j) {
37 this.i = i;
38 this.j = j;
39 }
40 int i;
41 int j;
42 volatile int k;
43 TestClass next;
Mingyao Yangfb8464a2015-11-02 10:56:59 -080044 String str;
Mingyao Yang8df69d42015-10-22 15:40:58 -070045 static int si;
Mingyao Yang8ab1d642015-12-03 14:11:15 -080046 static TestClass sTestClassObj;
Mingyao Yangfb8464a2015-11-02 10:56:59 -080047}
Mingyao Yang8df69d42015-10-22 15:40:58 -070048
49class SubTestClass extends TestClass {
50 int k;
Mingyao Yangfb8464a2015-11-02 10:56:59 -080051}
Mingyao Yang8df69d42015-10-22 15:40:58 -070052
53class TestClass2 {
54 int i;
55 int j;
Mingyao Yangfb8464a2015-11-02 10:56:59 -080056}
57
David Brazdilecf52df2015-12-14 16:58:08 +000058class TestClass3 {
59 float floatField = 8.0f;
60 boolean test1 = true;
61}
62
Mingyao Yangfb8464a2015-11-02 10:56:59 -080063class Finalizable {
64 static boolean sVisited = false;
Mingyao Yang025c1a62017-10-30 11:19:57 -070065 static final int VALUE1 = 0xbeef;
66 static final int VALUE2 = 0xcafe;
Mingyao Yangfb8464a2015-11-02 10:56:59 -080067 int i;
68
69 protected void finalize() {
Mingyao Yang025c1a62017-10-30 11:19:57 -070070 if (i != VALUE1) {
Mingyao Yangfb8464a2015-11-02 10:56:59 -080071 System.out.println("Where is the beef?");
72 }
73 sVisited = true;
74 }
75}
Mingyao Yang8df69d42015-10-22 15:40:58 -070076
Mingyao Yang062157f2016-03-02 10:15:36 -080077interface Filter {
78 public boolean isValid(int i);
79}
80
Mingyao Yang8df69d42015-10-22 15:40:58 -070081public class Main {
82
83 /// CHECK-START: double Main.calcCircleArea(double) load_store_elimination (before)
84 /// CHECK: NewInstance
85 /// CHECK: InstanceFieldSet
86 /// CHECK: InstanceFieldGet
87
88 /// CHECK-START: double Main.calcCircleArea(double) load_store_elimination (after)
Mingyao Yang062157f2016-03-02 10:15:36 -080089 /// CHECK-NOT: NewInstance
Mingyao Yangfb8464a2015-11-02 10:56:59 -080090 /// CHECK-NOT: InstanceFieldSet
Mingyao Yang8df69d42015-10-22 15:40:58 -070091 /// CHECK-NOT: InstanceFieldGet
92
93 static double calcCircleArea(double radius) {
94 return new Circle(radius).getArea();
95 }
96
97 /// CHECK-START: int Main.test1(TestClass, TestClass) load_store_elimination (before)
98 /// CHECK: InstanceFieldSet
99 /// CHECK: InstanceFieldSet
100 /// CHECK: InstanceFieldGet
101 /// CHECK: InstanceFieldGet
102
103 /// CHECK-START: int Main.test1(TestClass, TestClass) load_store_elimination (after)
104 /// CHECK: InstanceFieldSet
105 /// CHECK: InstanceFieldSet
106 /// CHECK-NOT: NullCheck
107 /// CHECK-NOT: InstanceFieldGet
108
109 // Different fields shouldn't alias.
110 static int test1(TestClass obj1, TestClass obj2) {
111 obj1.i = 1;
112 obj2.j = 2;
113 return obj1.i + obj2.j;
114 }
115
116 /// CHECK-START: int Main.test2(TestClass) load_store_elimination (before)
117 /// CHECK: InstanceFieldSet
118 /// CHECK: InstanceFieldSet
119 /// CHECK: InstanceFieldGet
120
121 /// CHECK-START: int Main.test2(TestClass) load_store_elimination (after)
122 /// CHECK: InstanceFieldSet
123 /// CHECK-NOT: NullCheck
124 /// CHECK-NOT: InstanceFieldSet
125 /// CHECK-NOT: InstanceFieldGet
126
127 // Redundant store of the same value.
128 static int test2(TestClass obj) {
129 obj.j = 1;
130 obj.j = 1;
131 return obj.j;
132 }
133
134 /// CHECK-START: int Main.test3(TestClass) load_store_elimination (before)
Mingyao Yang8ab1d642015-12-03 14:11:15 -0800135 /// CHECK: StaticFieldGet
136 /// CHECK: NewInstance
137 /// CHECK: InstanceFieldSet
138 /// CHECK: InstanceFieldSet
Mingyao Yang8df69d42015-10-22 15:40:58 -0700139 /// CHECK: InstanceFieldSet
140 /// CHECK: InstanceFieldSet
141 /// CHECK: InstanceFieldGet
142 /// CHECK: InstanceFieldGet
143 /// CHECK: InstanceFieldGet
144 /// CHECK: InstanceFieldGet
145
146 /// CHECK-START: int Main.test3(TestClass) load_store_elimination (after)
Mingyao Yang8ab1d642015-12-03 14:11:15 -0800147 /// CHECK: StaticFieldGet
148 /// CHECK: NewInstance
149 /// CHECK: InstanceFieldSet
150 /// CHECK: InstanceFieldSet
151 /// CHECK: InstanceFieldSet
152 /// CHECK: InstanceFieldSet
Mingyao Yang8df69d42015-10-22 15:40:58 -0700153 /// CHECK-NOT: InstanceFieldGet
Mingyao Yang8ab1d642015-12-03 14:11:15 -0800154 /// CHECK-NOT: StaticFieldGet
Mingyao Yang8df69d42015-10-22 15:40:58 -0700155
Mingyao Yang8ab1d642015-12-03 14:11:15 -0800156 // A new allocation (even non-singleton) shouldn't alias with pre-existing values.
Mingyao Yang8df69d42015-10-22 15:40:58 -0700157 static int test3(TestClass obj) {
Mingyao Yang8ab1d642015-12-03 14:11:15 -0800158 TestClass obj1 = TestClass.sTestClassObj;
159 TestClass obj2 = new TestClass(); // Cannot alias with obj or obj1 which pre-exist.
160 obj.next = obj2; // Make obj2 a non-singleton.
161 // All stores below need to stay since obj/obj1/obj2 are not singletons.
Mingyao Yang8df69d42015-10-22 15:40:58 -0700162 obj.i = 1;
Mingyao Yang8ab1d642015-12-03 14:11:15 -0800163 obj1.j = 2;
164 // Following stores won't kill values of obj.i and obj1.j.
Mingyao Yang8df69d42015-10-22 15:40:58 -0700165 obj2.i = 3;
166 obj2.j = 4;
Mingyao Yang8ab1d642015-12-03 14:11:15 -0800167 return obj.i + obj1.j + obj2.i + obj2.j;
Mingyao Yang8df69d42015-10-22 15:40:58 -0700168 }
169
170 /// CHECK-START: int Main.test4(TestClass, boolean) load_store_elimination (before)
171 /// CHECK: InstanceFieldSet
172 /// CHECK: InstanceFieldGet
173 /// CHECK: Return
174 /// CHECK: InstanceFieldSet
175
176 /// CHECK-START: int Main.test4(TestClass, boolean) load_store_elimination (after)
177 /// CHECK: InstanceFieldSet
178 /// CHECK-NOT: NullCheck
179 /// CHECK-NOT: InstanceFieldGet
180 /// CHECK: Return
181 /// CHECK: InstanceFieldSet
182
183 // Set and merge the same value in two branches.
184 static int test4(TestClass obj, boolean b) {
185 if (b) {
186 obj.i = 1;
187 } else {
188 obj.i = 1;
189 }
190 return obj.i;
191 }
192
193 /// CHECK-START: int Main.test5(TestClass, boolean) load_store_elimination (before)
194 /// CHECK: InstanceFieldSet
195 /// CHECK: InstanceFieldGet
196 /// CHECK: Return
197 /// CHECK: InstanceFieldSet
198
199 /// CHECK-START: int Main.test5(TestClass, boolean) load_store_elimination (after)
200 /// CHECK: InstanceFieldSet
201 /// CHECK: InstanceFieldGet
202 /// CHECK: Return
203 /// CHECK: InstanceFieldSet
204
205 // Set and merge different values in two branches.
206 static int test5(TestClass obj, boolean b) {
207 if (b) {
208 obj.i = 1;
209 } else {
210 obj.i = 2;
211 }
212 return obj.i;
213 }
214
215 /// CHECK-START: int Main.test6(TestClass, TestClass, boolean) load_store_elimination (before)
216 /// CHECK: InstanceFieldSet
217 /// CHECK: InstanceFieldSet
218 /// CHECK: InstanceFieldSet
219 /// CHECK: InstanceFieldGet
220 /// CHECK: InstanceFieldGet
221
222 /// CHECK-START: int Main.test6(TestClass, TestClass, boolean) load_store_elimination (after)
223 /// CHECK: InstanceFieldSet
224 /// CHECK: InstanceFieldSet
225 /// CHECK: InstanceFieldSet
226 /// CHECK: InstanceFieldGet
227 /// CHECK-NOT: NullCheck
228 /// CHECK-NOT: InstanceFieldGet
229
230 // Setting the same value doesn't clear the value for aliased locations.
231 static int test6(TestClass obj1, TestClass obj2, boolean b) {
232 obj1.i = 1;
233 obj1.j = 2;
234 if (b) {
235 obj2.j = 2;
236 }
237 return obj1.j + obj2.j;
238 }
239
240 /// CHECK-START: int Main.test7(TestClass) load_store_elimination (before)
241 /// CHECK: InstanceFieldSet
242 /// CHECK: InstanceFieldGet
243
244 /// CHECK-START: int Main.test7(TestClass) load_store_elimination (after)
245 /// CHECK: InstanceFieldSet
246 /// CHECK: InstanceFieldGet
247
248 // Invocation should kill values in non-singleton heap locations.
249 static int test7(TestClass obj) {
250 obj.i = 1;
251 System.out.print("");
252 return obj.i;
253 }
254
255 /// CHECK-START: int Main.test8() load_store_elimination (before)
256 /// CHECK: NewInstance
257 /// CHECK: InstanceFieldSet
258 /// CHECK: InvokeVirtual
259 /// CHECK: InstanceFieldGet
260
261 /// CHECK-START: int Main.test8() load_store_elimination (after)
Mingyao Yang062157f2016-03-02 10:15:36 -0800262 /// CHECK-NOT: NewInstance
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800263 /// CHECK-NOT: InstanceFieldSet
Mingyao Yang8df69d42015-10-22 15:40:58 -0700264 /// CHECK: InvokeVirtual
265 /// CHECK-NOT: NullCheck
266 /// CHECK-NOT: InstanceFieldGet
267
268 // Invocation should not kill values in singleton heap locations.
269 static int test8() {
270 TestClass obj = new TestClass();
271 obj.i = 1;
272 System.out.print("");
273 return obj.i;
274 }
275
276 /// CHECK-START: int Main.test9(TestClass) load_store_elimination (before)
277 /// CHECK: NewInstance
278 /// CHECK: InstanceFieldSet
279 /// CHECK: InstanceFieldSet
280 /// CHECK: InstanceFieldGet
281
282 /// CHECK-START: int Main.test9(TestClass) load_store_elimination (after)
283 /// CHECK: NewInstance
284 /// CHECK: InstanceFieldSet
285 /// CHECK: InstanceFieldSet
286 /// CHECK: InstanceFieldGet
287
288 // Invocation should kill values in non-singleton heap locations.
289 static int test9(TestClass obj) {
290 TestClass obj2 = new TestClass();
291 obj2.i = 1;
292 obj.next = obj2;
293 System.out.print("");
294 return obj2.i;
295 }
296
297 /// CHECK-START: int Main.test10(TestClass) load_store_elimination (before)
298 /// CHECK: StaticFieldGet
299 /// CHECK: InstanceFieldGet
300 /// CHECK: StaticFieldSet
301 /// CHECK: InstanceFieldGet
302
303 /// CHECK-START: int Main.test10(TestClass) load_store_elimination (after)
304 /// CHECK: StaticFieldGet
305 /// CHECK: InstanceFieldGet
306 /// CHECK: StaticFieldSet
307 /// CHECK-NOT: NullCheck
308 /// CHECK-NOT: InstanceFieldGet
309
310 // Static fields shouldn't alias with instance fields.
311 static int test10(TestClass obj) {
312 TestClass.si += obj.i;
313 return obj.i;
314 }
315
316 /// CHECK-START: int Main.test11(TestClass) load_store_elimination (before)
317 /// CHECK: InstanceFieldSet
318 /// CHECK: InstanceFieldGet
319
320 /// CHECK-START: int Main.test11(TestClass) load_store_elimination (after)
321 /// CHECK: InstanceFieldSet
322 /// CHECK-NOT: NullCheck
323 /// CHECK-NOT: InstanceFieldGet
324
325 // Loop without heap writes.
326 // obj.i is actually hoisted to the loop pre-header by licm already.
327 static int test11(TestClass obj) {
328 obj.i = 1;
329 int sum = 0;
330 for (int i = 0; i < 10; i++) {
331 sum += obj.i;
332 }
333 return sum;
334 }
335
336 /// CHECK-START: int Main.test12(TestClass, TestClass) load_store_elimination (before)
337 /// CHECK: InstanceFieldSet
338 /// CHECK: InstanceFieldGet
339 /// CHECK: InstanceFieldSet
340
341 /// CHECK-START: int Main.test12(TestClass, TestClass) load_store_elimination (after)
342 /// CHECK: InstanceFieldSet
343 /// CHECK: InstanceFieldGet
344 /// CHECK: InstanceFieldSet
345
346 // Loop with heap writes.
347 static int test12(TestClass obj1, TestClass obj2) {
348 obj1.i = 1;
349 int sum = 0;
350 for (int i = 0; i < 10; i++) {
351 sum += obj1.i;
352 obj2.i = sum;
353 }
354 return sum;
355 }
356
357 /// CHECK-START: int Main.test13(TestClass, TestClass2) load_store_elimination (before)
358 /// CHECK: InstanceFieldSet
359 /// CHECK: InstanceFieldSet
360 /// CHECK: InstanceFieldGet
361 /// CHECK: InstanceFieldGet
362
363 /// CHECK-START: int Main.test13(TestClass, TestClass2) load_store_elimination (after)
364 /// CHECK: InstanceFieldSet
365 /// CHECK: InstanceFieldSet
366 /// CHECK-NOT: NullCheck
367 /// CHECK-NOT: InstanceFieldGet
368
369 // Different classes shouldn't alias.
370 static int test13(TestClass obj1, TestClass2 obj2) {
371 obj1.i = 1;
372 obj2.i = 2;
373 return obj1.i + obj2.i;
374 }
375
376 /// CHECK-START: int Main.test14(TestClass, SubTestClass) load_store_elimination (before)
377 /// CHECK: InstanceFieldSet
378 /// CHECK: InstanceFieldSet
379 /// CHECK: InstanceFieldGet
380
381 /// CHECK-START: int Main.test14(TestClass, SubTestClass) load_store_elimination (after)
382 /// CHECK: InstanceFieldSet
383 /// CHECK: InstanceFieldSet
384 /// CHECK: InstanceFieldGet
385
386 // Subclass may alias with super class.
387 static int test14(TestClass obj1, SubTestClass obj2) {
388 obj1.i = 1;
389 obj2.i = 2;
390 return obj1.i;
391 }
392
393 /// CHECK-START: int Main.test15() load_store_elimination (before)
394 /// CHECK: StaticFieldSet
395 /// CHECK: StaticFieldSet
396 /// CHECK: StaticFieldGet
397
398 /// CHECK-START: int Main.test15() load_store_elimination (after)
399 /// CHECK: <<Const2:i\d+>> IntConstant 2
400 /// CHECK: StaticFieldSet
401 /// CHECK: StaticFieldSet
402 /// CHECK-NOT: StaticFieldGet
403 /// CHECK: Return [<<Const2>>]
404
405 // Static field access from subclass's name.
406 static int test15() {
407 TestClass.si = 1;
408 SubTestClass.si = 2;
409 return TestClass.si;
410 }
411
412 /// CHECK-START: int Main.test16() load_store_elimination (before)
413 /// CHECK: NewInstance
414 /// CHECK: InstanceFieldSet
415 /// CHECK: InstanceFieldSet
416 /// CHECK: InstanceFieldGet
417 /// CHECK: InstanceFieldGet
418
419 /// CHECK-START: int Main.test16() load_store_elimination (after)
Mingyao Yang062157f2016-03-02 10:15:36 -0800420 /// CHECK-NOT: NewInstance
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800421 /// CHECK-NOT: InstanceFieldSet
422 /// CHECK-NOT: InstanceFieldGet
Mingyao Yang8df69d42015-10-22 15:40:58 -0700423
424 // Test inlined constructor.
425 static int test16() {
426 TestClass obj = new TestClass(1, 2);
427 return obj.i + obj.j;
428 }
429
430 /// CHECK-START: int Main.test17() load_store_elimination (before)
431 /// CHECK: NewInstance
432 /// CHECK: InstanceFieldSet
433 /// CHECK: InstanceFieldGet
434
435 /// CHECK-START: int Main.test17() load_store_elimination (after)
436 /// CHECK: <<Const0:i\d+>> IntConstant 0
Mingyao Yang062157f2016-03-02 10:15:36 -0800437 /// CHECK-NOT: NewInstance
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800438 /// CHECK-NOT: InstanceFieldSet
439 /// CHECK-NOT: InstanceFieldGet
Mingyao Yang8df69d42015-10-22 15:40:58 -0700440 /// CHECK: Return [<<Const0>>]
441
442 // Test getting default value.
443 static int test17() {
444 TestClass obj = new TestClass();
445 obj.j = 1;
446 return obj.i;
447 }
448
449 /// CHECK-START: int Main.test18(TestClass) load_store_elimination (before)
450 /// CHECK: InstanceFieldSet
451 /// CHECK: InstanceFieldGet
452
453 /// CHECK-START: int Main.test18(TestClass) load_store_elimination (after)
454 /// CHECK: InstanceFieldSet
455 /// CHECK: InstanceFieldGet
456
457 // Volatile field load/store shouldn't be eliminated.
458 static int test18(TestClass obj) {
459 obj.k = 1;
460 return obj.k;
461 }
462
463 /// CHECK-START: float Main.test19(float[], float[]) load_store_elimination (before)
David Brazdil4833f5a2015-12-16 10:37:39 +0000464 /// CHECK: {{f\d+}} ArrayGet
465 /// CHECK: {{f\d+}} ArrayGet
Mingyao Yang8df69d42015-10-22 15:40:58 -0700466
467 /// CHECK-START: float Main.test19(float[], float[]) load_store_elimination (after)
David Brazdil4833f5a2015-12-16 10:37:39 +0000468 /// CHECK: {{f\d+}} ArrayGet
469 /// CHECK-NOT: {{f\d+}} ArrayGet
Mingyao Yang8df69d42015-10-22 15:40:58 -0700470
David Brazdil4833f5a2015-12-16 10:37:39 +0000471 // I/F, J/D aliasing should not happen any more and LSE should eliminate the load.
Mingyao Yang8df69d42015-10-22 15:40:58 -0700472 static float test19(float[] fa1, float[] fa2) {
473 fa1[0] = fa2[0];
474 return fa1[0];
475 }
476
477 /// CHECK-START: TestClass Main.test20() load_store_elimination (before)
478 /// CHECK: NewInstance
479 /// CHECK: InstanceFieldSet
480
481 /// CHECK-START: TestClass Main.test20() load_store_elimination (after)
482 /// CHECK: NewInstance
483 /// CHECK-NOT: InstanceFieldSet
484
485 // Storing default heap value is redundant if the heap location has the
486 // default heap value.
487 static TestClass test20() {
488 TestClass obj = new TestClass();
489 obj.i = 0;
490 return obj;
491 }
492
Mingyao Yang803cbb92015-12-01 12:24:36 -0800493 /// CHECK-START: void Main.test21(TestClass) load_store_elimination (before)
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800494 /// CHECK: NewInstance
495 /// CHECK: InstanceFieldSet
Mingyao Yang803cbb92015-12-01 12:24:36 -0800496 /// CHECK: InstanceFieldSet
497 /// CHECK: InstanceFieldSet
498 /// CHECK: InstanceFieldGet
499 /// CHECK: InstanceFieldGet
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800500
Mingyao Yang803cbb92015-12-01 12:24:36 -0800501 /// CHECK-START: void Main.test21(TestClass) load_store_elimination (after)
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800502 /// CHECK: NewInstance
503 /// CHECK: InstanceFieldSet
Mingyao Yang803cbb92015-12-01 12:24:36 -0800504 /// CHECK: InstanceFieldSet
505 /// CHECK: InstanceFieldSet
506 /// CHECK: InstanceFieldGet
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800507 /// CHECK: InstanceFieldGet
508
509 // Loop side effects can kill heap values, stores need to be kept in that case.
Mingyao Yang803cbb92015-12-01 12:24:36 -0800510 static void test21(TestClass obj0) {
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800511 TestClass obj = new TestClass();
Mingyao Yang803cbb92015-12-01 12:24:36 -0800512 obj0.str = "abc";
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800513 obj.str = "abc";
514 for (int i = 0; i < 2; i++) {
Mingyao Yang803cbb92015-12-01 12:24:36 -0800515 // Generate some loop side effect that writes into obj.
516 obj.str = "def";
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800517 }
Mingyao Yang803cbb92015-12-01 12:24:36 -0800518 System.out.print(obj0.str.substring(0, 0) + obj.str.substring(0, 0));
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800519 }
520
521 /// CHECK-START: int Main.test22() load_store_elimination (before)
522 /// CHECK: NewInstance
523 /// CHECK: InstanceFieldSet
524 /// CHECK: NewInstance
525 /// CHECK: InstanceFieldSet
526 /// CHECK: InstanceFieldGet
527 /// CHECK: NewInstance
528 /// CHECK: InstanceFieldSet
529 /// CHECK: InstanceFieldGet
530 /// CHECK: InstanceFieldGet
531
532 /// CHECK-START: int Main.test22() load_store_elimination (after)
Mingyao Yang062157f2016-03-02 10:15:36 -0800533 /// CHECK-NOT: NewInstance
Mingyao Yang803cbb92015-12-01 12:24:36 -0800534 /// CHECK-NOT: InstanceFieldSet
Mingyao Yang062157f2016-03-02 10:15:36 -0800535 /// CHECK-NOT: NewInstance
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800536 /// CHECK-NOT: InstanceFieldSet
537 /// CHECK-NOT: InstanceFieldGet
Mingyao Yang062157f2016-03-02 10:15:36 -0800538 /// CHECK-NOT: NewInstance
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800539 /// CHECK-NOT: InstanceFieldSet
Mingyao Yang803cbb92015-12-01 12:24:36 -0800540 /// CHECK-NOT: InstanceFieldGet
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800541 /// CHECK-NOT: InstanceFieldGet
542
Mingyao Yang803cbb92015-12-01 12:24:36 -0800543 // For a singleton, loop side effects can kill its field values only if:
544 // (1) it dominiates the loop header, and
545 // (2) its fields are stored into inside a loop.
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800546 static int test22() {
547 int sum = 0;
548 TestClass obj1 = new TestClass();
Mingyao Yang803cbb92015-12-01 12:24:36 -0800549 obj1.i = 2; // This store can be eliminated since obj1 is never stored into inside a loop.
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800550 for (int i = 0; i < 2; i++) {
551 TestClass obj2 = new TestClass();
Mingyao Yang803cbb92015-12-01 12:24:36 -0800552 obj2.i = 3; // This store can be eliminated since the singleton is inside the loop.
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800553 sum += obj2.i;
554 }
555 TestClass obj3 = new TestClass();
Mingyao Yang803cbb92015-12-01 12:24:36 -0800556 obj3.i = 5; // This store can be eliminated since the singleton is created after the loop.
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800557 sum += obj1.i + obj3.i;
558 return sum;
559 }
560
561 /// CHECK-START: int Main.test23(boolean) load_store_elimination (before)
562 /// CHECK: NewInstance
563 /// CHECK: InstanceFieldSet
564 /// CHECK: InstanceFieldGet
565 /// CHECK: InstanceFieldSet
566 /// CHECK: InstanceFieldGet
567 /// CHECK: Return
568 /// CHECK: InstanceFieldGet
569 /// CHECK: InstanceFieldSet
570
571 /// CHECK-START: int Main.test23(boolean) load_store_elimination (after)
572 /// CHECK: NewInstance
573 /// CHECK-NOT: InstanceFieldSet
574 /// CHECK-NOT: InstanceFieldGet
575 /// CHECK: InstanceFieldSet
576 /// CHECK: InstanceFieldGet
577 /// CHECK: Return
578 /// CHECK-NOT: InstanceFieldGet
579 /// CHECK: InstanceFieldSet
580
581 // Test store elimination on merging.
582 static int test23(boolean b) {
583 TestClass obj = new TestClass();
584 obj.i = 3; // This store can be eliminated since the value flows into each branch.
585 if (b) {
586 obj.i += 1; // This store cannot be eliminated due to the merge later.
587 } else {
588 obj.i += 2; // This store cannot be eliminated due to the merge later.
589 }
590 return obj.i;
591 }
592
David Brazdilecf52df2015-12-14 16:58:08 +0000593 /// CHECK-START: float Main.test24() load_store_elimination (before)
594 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
595 /// CHECK-DAG: <<Float8:f\d+>> FloatConstant 8
596 /// CHECK-DAG: <<Float42:f\d+>> FloatConstant 42
597 /// CHECK-DAG: <<Obj:l\d+>> NewInstance
598 /// CHECK-DAG: InstanceFieldSet [<<Obj>>,<<True>>]
599 /// CHECK-DAG: InstanceFieldSet [<<Obj>>,<<Float8>>]
600 /// CHECK-DAG: <<GetTest:z\d+>> InstanceFieldGet [<<Obj>>]
David Brazdilecf52df2015-12-14 16:58:08 +0000601 /// CHECK-DAG: <<GetField:f\d+>> InstanceFieldGet [<<Obj>>]
David Brazdil74eb1b22015-12-14 11:44:01 +0000602 /// CHECK-DAG: <<Select:f\d+>> Select [<<Float42>>,<<GetField>>,<<GetTest>>]
603 /// CHECK-DAG: Return [<<Select>>]
David Brazdilecf52df2015-12-14 16:58:08 +0000604
605 /// CHECK-START: float Main.test24() load_store_elimination (after)
606 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
607 /// CHECK-DAG: <<Float8:f\d+>> FloatConstant 8
608 /// CHECK-DAG: <<Float42:f\d+>> FloatConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +0000609 /// CHECK-DAG: <<Select:f\d+>> Select [<<Float42>>,<<Float8>>,<<True>>]
610 /// CHECK-DAG: Return [<<Select>>]
David Brazdilecf52df2015-12-14 16:58:08 +0000611
612 static float test24() {
613 float a = 42.0f;
614 TestClass3 obj = new TestClass3();
615 if (obj.test1) {
616 a = obj.floatField;
617 }
618 return a;
619 }
620
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800621 /// CHECK-START: void Main.testFinalizable() load_store_elimination (before)
622 /// CHECK: NewInstance
623 /// CHECK: InstanceFieldSet
Mingyao Yang025c1a62017-10-30 11:19:57 -0700624 /// CHECK: InstanceFieldSet
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800625
626 /// CHECK-START: void Main.testFinalizable() load_store_elimination (after)
627 /// CHECK: NewInstance
628 /// CHECK: InstanceFieldSet
Mingyao Yang025c1a62017-10-30 11:19:57 -0700629 /// CHECK-NOT: InstanceFieldSet
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800630
Mingyao Yang025c1a62017-10-30 11:19:57 -0700631 // Allocations of finalizable objects cannot be eliminated.
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800632 static void testFinalizable() {
633 Finalizable finalizable = new Finalizable();
Mingyao Yang025c1a62017-10-30 11:19:57 -0700634 finalizable.i = Finalizable.VALUE2;
635 finalizable.i = Finalizable.VALUE1;
Mingyao Yangfb8464a2015-11-02 10:56:59 -0800636 }
637
638 static java.lang.ref.WeakReference<Object> getWeakReference() {
639 return new java.lang.ref.WeakReference<>(new Object());
640 }
641
642 static void testFinalizableByForcingGc() {
643 testFinalizable();
644 java.lang.ref.WeakReference<Object> reference = getWeakReference();
645
646 Runtime runtime = Runtime.getRuntime();
647 for (int i = 0; i < 20; ++i) {
648 runtime.gc();
649 System.runFinalization();
650 try {
651 Thread.sleep(1);
652 } catch (InterruptedException e) {
653 throw new AssertionError(e);
654 }
655
656 // Check to see if the weak reference has been garbage collected.
657 if (reference.get() == null) {
658 // A little bit more sleep time to make sure.
659 try {
660 Thread.sleep(100);
661 } catch (InterruptedException e) {
662 throw new AssertionError(e);
663 }
664 if (!Finalizable.sVisited) {
665 System.out.println("finalize() not called.");
666 }
667 return;
668 }
669 }
670 System.out.println("testFinalizableByForcingGc() failed to force gc.");
671 }
672
Mingyao Yang40bcb932016-02-03 05:46:57 -0800673 /// CHECK-START: int Main.$noinline$testHSelect(boolean) load_store_elimination (before)
Mingyao Yange5c71f92016-02-02 20:10:32 -0800674 /// CHECK: InstanceFieldSet
675 /// CHECK: Select
676
Mingyao Yang40bcb932016-02-03 05:46:57 -0800677 /// CHECK-START: int Main.$noinline$testHSelect(boolean) load_store_elimination (after)
Mingyao Yange5c71f92016-02-02 20:10:32 -0800678 /// CHECK: InstanceFieldSet
679 /// CHECK: Select
680
681 // Test that HSelect creates alias.
Mingyao Yang062157f2016-03-02 10:15:36 -0800682 static int $noinline$testHSelect(boolean b) {
Mingyao Yang40bcb932016-02-03 05:46:57 -0800683 if (sFlag) {
684 throw new Error();
685 }
Mingyao Yange5c71f92016-02-02 20:10:32 -0800686 TestClass obj = new TestClass();
687 TestClass obj2 = null;
688 obj.i = 0xdead;
689 if (b) {
690 obj2 = obj;
691 }
692 return obj2.i;
693 }
694
Mingyao Yang062157f2016-03-02 10:15:36 -0800695 static int sumWithFilter(int[] array, Filter f) {
696 int sum = 0;
697 for (int i = 0; i < array.length; i++) {
698 if (f.isValid(array[i])) {
699 sum += array[i];
700 }
701 }
702 return sum;
703 }
704
705 /// CHECK-START: int Main.sumWithinRange(int[], int, int) load_store_elimination (before)
706 /// CHECK: NewInstance
707 /// CHECK: InstanceFieldSet
708 /// CHECK: InstanceFieldSet
709 /// CHECK: InstanceFieldGet
710 /// CHECK: InstanceFieldGet
711
712 /// CHECK-START: int Main.sumWithinRange(int[], int, int) load_store_elimination (after)
713 /// CHECK-NOT: NewInstance
714 /// CHECK-NOT: InstanceFieldSet
715 /// CHECK-NOT: InstanceFieldGet
716
717 // A lambda-style allocation can be eliminated after inlining.
718 static int sumWithinRange(int[] array, final int low, final int high) {
719 Filter filter = new Filter() {
720 public boolean isValid(int i) {
721 return (i >= low) && (i <= high);
722 }
723 };
724 return sumWithFilter(array, filter);
725 }
726
Mingyao Yang0a845202016-10-14 16:26:08 -0700727 private static int mI = 0;
728 private static float mF = 0f;
729
730 /// CHECK-START: float Main.testAllocationEliminationWithLoops() load_store_elimination (before)
731 /// CHECK: NewInstance
732 /// CHECK: NewInstance
733 /// CHECK: NewInstance
734
735 /// CHECK-START: float Main.testAllocationEliminationWithLoops() load_store_elimination (after)
736 /// CHECK-NOT: NewInstance
737
738 private static float testAllocationEliminationWithLoops() {
739 for (int i0 = 0; i0 < 5; i0++) {
740 for (int i1 = 0; i1 < 5; i1++) {
741 for (int i2 = 0; i2 < 5; i2++) {
742 int lI0 = ((int) new Integer(((int) new Integer(mI))));
743 if (((boolean) new Boolean(false))) {
744 for (int i3 = 576 - 1; i3 >= 0; i3--) {
745 mF -= 976981405.0f;
746 }
747 }
748 }
749 }
750 }
751 return 1.0f;
752 }
753
Mingyao Yangeb2d2d346e2017-03-02 13:26:17 -0800754 /// CHECK-START: TestClass2 Main.testStoreStore() load_store_elimination (before)
755 /// CHECK: NewInstance
756 /// CHECK: InstanceFieldSet
757 /// CHECK: InstanceFieldSet
758 /// CHECK: InstanceFieldSet
759 /// CHECK: InstanceFieldSet
760
761 /// CHECK-START: TestClass2 Main.testStoreStore() load_store_elimination (after)
762 /// CHECK: NewInstance
763 /// CHECK: InstanceFieldSet
764 /// CHECK: InstanceFieldSet
765 /// CHECK-NOT: InstanceFieldSet
766
767 private static TestClass2 testStoreStore() {
768 TestClass2 obj = new TestClass2();
769 obj.i = 41;
770 obj.j = 42;
771 obj.i = 41;
772 obj.j = 43;
773 return obj;
774 }
775
776 /// CHECK-START: int Main.testStoreStoreWithDeoptimize(int[]) load_store_elimination (before)
777 /// CHECK: NewInstance
778 /// CHECK: InstanceFieldSet
779 /// CHECK: InstanceFieldSet
780 /// CHECK: InstanceFieldSet
781 /// CHECK: InstanceFieldSet
782 /// CHECK: Deoptimize
783 /// CHECK: ArraySet
784 /// CHECK: ArraySet
785 /// CHECK: ArraySet
786 /// CHECK: ArraySet
787 /// CHECK: ArrayGet
788 /// CHECK: ArrayGet
789 /// CHECK: ArrayGet
790 /// CHECK: ArrayGet
791
792 /// CHECK-START: int Main.testStoreStoreWithDeoptimize(int[]) load_store_elimination (after)
793 /// CHECK: NewInstance
794 /// CHECK: InstanceFieldSet
795 /// CHECK: InstanceFieldSet
796 /// CHECK-NOT: InstanceFieldSet
797 /// CHECK: Deoptimize
798 /// CHECK: ArraySet
799 /// CHECK: ArraySet
800 /// CHECK: ArraySet
801 /// CHECK: ArraySet
802 /// CHECK-NOT: ArrayGet
803
804 private static int testStoreStoreWithDeoptimize(int[] arr) {
805 TestClass2 obj = new TestClass2();
806 obj.i = 41;
807 obj.j = 42;
808 obj.i = 41;
809 obj.j = 43;
810 arr[0] = 1; // One HDeoptimize here.
811 arr[1] = 1;
812 arr[2] = 1;
813 arr[3] = 1;
814 return arr[0] + arr[1] + arr[2] + arr[3];
815 }
816
Mingyao Yang293f1c02017-11-08 15:22:17 -0800817 /// CHECK-START: int Main.testNoSideEffects(int[]) load_store_elimination (before)
818 /// CHECK: ArraySet
819 /// CHECK: ArraySet
820 /// CHECK: ArrayGet
821
822 /// CHECK-START: int Main.testNoSideEffects(int[]) load_store_elimination (after)
823 /// CHECK: ArraySet
824 /// CHECK: ArraySet
825 /// CHECK-NOT: ArrayGet
826
827 private static int testNoSideEffects(int[] array) {
828 array[0] = 101;
829 int bitCount = Integer.bitCount(0x3456);
830 array[1] = array[0] + 1;
831 return array[0] + bitCount;
832 }
833
Mingyao Yang58d9bfc2016-11-01 13:31:58 -0700834 /// CHECK-START: double Main.getCircleArea(double, boolean) load_store_elimination (before)
835 /// CHECK: NewInstance
836
837 /// CHECK-START: double Main.getCircleArea(double, boolean) load_store_elimination (after)
838 /// CHECK-NOT: NewInstance
839
840 private static double getCircleArea(double radius, boolean b) {
841 double area = 0d;
842 if (b) {
843 area = new Circle(radius).getArea();
844 }
845 return area;
846 }
847
Mingyao Yange58bdca2016-10-28 11:07:24 -0700848 /// CHECK-START: double Main.testDeoptimize(int[], double[], double) load_store_elimination (before)
849 /// CHECK: Deoptimize
850 /// CHECK: NewInstance
851 /// CHECK: Deoptimize
852 /// CHECK: NewInstance
853
854 /// CHECK-START: double Main.testDeoptimize(int[], double[], double) load_store_elimination (after)
855 /// CHECK: Deoptimize
856 /// CHECK: NewInstance
857 /// CHECK: Deoptimize
858 /// CHECK-NOT: NewInstance
859
860 private static double testDeoptimize(int[] iarr, double[] darr, double radius) {
861 iarr[0] = 1; // One HDeoptimize here. Not triggered.
862 iarr[1] = 1;
863 Circle circle1 = new Circle(radius);
864 iarr[2] = 1;
865 darr[0] = circle1.getRadius(); // One HDeoptimize here, which holds circle1 live. Triggered.
866 darr[1] = circle1.getRadius();
867 darr[2] = circle1.getRadius();
868 darr[3] = circle1.getRadius();
869 return new Circle(Math.PI).getArea();
870 }
871
Mingyao Yang86974902017-03-01 14:03:51 -0800872 /// CHECK-START: int Main.testAllocationEliminationOfArray1() load_store_elimination (before)
873 /// CHECK: NewArray
874 /// CHECK: ArraySet
875 /// CHECK: ArraySet
876 /// CHECK: ArrayGet
877 /// CHECK: ArrayGet
878 /// CHECK: ArrayGet
879 /// CHECK: ArrayGet
880
881 /// CHECK-START: int Main.testAllocationEliminationOfArray1() load_store_elimination (after)
882 /// CHECK-NOT: NewArray
883 /// CHECK-NOT: ArraySet
884 /// CHECK-NOT: ArrayGet
885 private static int testAllocationEliminationOfArray1() {
886 int[] array = new int[4];
887 array[2] = 4;
888 array[3] = 7;
889 return array[0] + array[1] + array[2] + array[3];
890 }
891
892 /// CHECK-START: int Main.testAllocationEliminationOfArray2() load_store_elimination (before)
893 /// CHECK: NewArray
894 /// CHECK: ArraySet
895 /// CHECK: ArraySet
896 /// CHECK: ArrayGet
897
898 /// CHECK-START: int Main.testAllocationEliminationOfArray2() load_store_elimination (after)
899 /// CHECK: NewArray
900 /// CHECK: ArraySet
901 /// CHECK: ArraySet
902 /// CHECK: ArrayGet
903 private static int testAllocationEliminationOfArray2() {
904 // Cannot eliminate array allocation since array is accessed with non-constant
Aart Bik0148de42017-09-05 09:25:01 -0700905 // index (only 3 elements to prevent vectorization of the reduction).
906 int[] array = new int[3];
907 array[1] = 4;
908 array[2] = 7;
Mingyao Yang86974902017-03-01 14:03:51 -0800909 int sum = 0;
910 for (int e : array) {
911 sum += e;
912 }
913 return sum;
914 }
915
916 /// CHECK-START: int Main.testAllocationEliminationOfArray3(int) load_store_elimination (before)
917 /// CHECK: NewArray
918 /// CHECK: ArraySet
919 /// CHECK: ArrayGet
920
921 /// CHECK-START: int Main.testAllocationEliminationOfArray3(int) load_store_elimination (after)
922 /// CHECK-NOT: NewArray
923 /// CHECK-NOT: ArraySet
924 /// CHECK-NOT: ArrayGet
925 private static int testAllocationEliminationOfArray3(int i) {
926 int[] array = new int[4];
927 array[i] = 4;
928 return array[i];
929 }
930
931 /// CHECK-START: int Main.testAllocationEliminationOfArray4(int) load_store_elimination (before)
932 /// CHECK: NewArray
933 /// CHECK: ArraySet
934 /// CHECK: ArraySet
935 /// CHECK: ArrayGet
936 /// CHECK: ArrayGet
937
938 /// CHECK-START: int Main.testAllocationEliminationOfArray4(int) load_store_elimination (after)
939 /// CHECK: NewArray
940 /// CHECK: ArraySet
941 /// CHECK: ArraySet
942 /// CHECK: ArrayGet
943 /// CHECK-NOT: ArrayGet
944 private static int testAllocationEliminationOfArray4(int i) {
945 // Cannot eliminate array allocation due to index aliasing between 1 and i.
946 int[] array = new int[4];
947 array[1] = 2;
948 array[i] = 4;
949 return array[1] + array[i];
950 }
951
Mingyao Yang46721ef2017-10-05 14:45:17 -0700952 /// CHECK-START: int Main.testExitMerge(boolean) load_store_elimination (before)
953 /// CHECK: NewInstance
954 /// CHECK: InstanceFieldSet
955 /// CHECK: InstanceFieldGet
956 /// CHECK: Return
957 /// CHECK: InstanceFieldSet
958 /// CHECK: Throw
959
960 /// CHECK-START: int Main.testExitMerge(boolean) load_store_elimination (after)
961 /// CHECK-NOT: NewInstance
962 /// CHECK-NOT: InstanceFieldSet
963 /// CHECK-NOT: InstanceFieldGet
964 /// CHECK: Return
965 /// CHECK-NOT: InstanceFieldSet
966 /// CHECK: Throw
967 private static int testExitMerge(boolean cond) {
968 TestClass obj = new TestClass();
969 if (cond) {
970 obj.i = 1;
971 return obj.i + 1;
972 } else {
973 obj.i = 2;
974 throw new Error();
975 }
976 }
977
978 /// CHECK-START: int Main.testExitMerge2(boolean) load_store_elimination (before)
979 /// CHECK: NewInstance
980 /// CHECK: InstanceFieldSet
981 /// CHECK: InstanceFieldGet
982 /// CHECK: InstanceFieldSet
983 /// CHECK: InstanceFieldGet
984
985 /// CHECK-START: int Main.testExitMerge2(boolean) load_store_elimination (after)
986 /// CHECK-NOT: NewInstance
987 /// CHECK-NOT: InstanceFieldSet
988 /// CHECK-NOT: InstanceFieldGet
989 private static int testExitMerge2(boolean cond) {
990 TestClass obj = new TestClass();
991 int res;
992 if (cond) {
993 obj.i = 1;
994 res = obj.i + 1;
995 } else {
996 obj.i = 2;
997 res = obj.j + 2;
998 }
999 return res;
1000 }
1001
Mingyao Yang062157f2016-03-02 10:15:36 -08001002 static void assertIntEquals(int result, int expected) {
Mingyao Yang8df69d42015-10-22 15:40:58 -07001003 if (expected != result) {
1004 throw new Error("Expected: " + expected + ", found: " + result);
1005 }
1006 }
1007
Mingyao Yang062157f2016-03-02 10:15:36 -08001008 static void assertFloatEquals(float result, float expected) {
Mingyao Yang8df69d42015-10-22 15:40:58 -07001009 if (expected != result) {
1010 throw new Error("Expected: " + expected + ", found: " + result);
1011 }
1012 }
1013
Mingyao Yang062157f2016-03-02 10:15:36 -08001014 static void assertDoubleEquals(double result, double expected) {
Mingyao Yang8df69d42015-10-22 15:40:58 -07001015 if (expected != result) {
1016 throw new Error("Expected: " + expected + ", found: " + result);
1017 }
1018 }
1019
1020 public static void main(String[] args) {
1021 assertDoubleEquals(Math.PI * Math.PI * Math.PI, calcCircleArea(Math.PI));
1022 assertIntEquals(test1(new TestClass(), new TestClass()), 3);
1023 assertIntEquals(test2(new TestClass()), 1);
1024 TestClass obj1 = new TestClass();
1025 TestClass obj2 = new TestClass();
1026 obj1.next = obj2;
1027 assertIntEquals(test3(obj1), 10);
1028 assertIntEquals(test4(new TestClass(), true), 1);
1029 assertIntEquals(test4(new TestClass(), false), 1);
1030 assertIntEquals(test5(new TestClass(), true), 1);
1031 assertIntEquals(test5(new TestClass(), false), 2);
1032 assertIntEquals(test6(new TestClass(), new TestClass(), true), 4);
1033 assertIntEquals(test6(new TestClass(), new TestClass(), false), 2);
1034 assertIntEquals(test7(new TestClass()), 1);
1035 assertIntEquals(test8(), 1);
1036 obj1 = new TestClass();
1037 obj2 = new TestClass();
1038 obj1.next = obj2;
1039 assertIntEquals(test9(new TestClass()), 1);
1040 assertIntEquals(test10(new TestClass(3, 4)), 3);
1041 assertIntEquals(TestClass.si, 3);
1042 assertIntEquals(test11(new TestClass()), 10);
1043 assertIntEquals(test12(new TestClass(), new TestClass()), 10);
1044 assertIntEquals(test13(new TestClass(), new TestClass2()), 3);
1045 SubTestClass obj3 = new SubTestClass();
1046 assertIntEquals(test14(obj3, obj3), 2);
1047 assertIntEquals(test15(), 2);
1048 assertIntEquals(test16(), 3);
1049 assertIntEquals(test17(), 0);
1050 assertIntEquals(test18(new TestClass()), 1);
1051 float[] fa1 = { 0.8f };
1052 float[] fa2 = { 1.8f };
1053 assertFloatEquals(test19(fa1, fa2), 1.8f);
1054 assertFloatEquals(test20().i, 0);
Mingyao Yang803cbb92015-12-01 12:24:36 -08001055 test21(new TestClass());
Mingyao Yangfb8464a2015-11-02 10:56:59 -08001056 assertIntEquals(test22(), 13);
1057 assertIntEquals(test23(true), 4);
1058 assertIntEquals(test23(false), 5);
David Brazdilecf52df2015-12-14 16:58:08 +00001059 assertFloatEquals(test24(), 8.0f);
Mingyao Yangfb8464a2015-11-02 10:56:59 -08001060 testFinalizableByForcingGc();
Mingyao Yang40bcb932016-02-03 05:46:57 -08001061 assertIntEquals($noinline$testHSelect(true), 0xdead);
Mingyao Yang062157f2016-03-02 10:15:36 -08001062 int[] array = {2, 5, 9, -1, -3, 10, 8, 4};
1063 assertIntEquals(sumWithinRange(array, 1, 5), 11);
Mingyao Yang0a845202016-10-14 16:26:08 -07001064 assertFloatEquals(testAllocationEliminationWithLoops(), 1.0f);
1065 assertFloatEquals(mF, 0f);
Mingyao Yang58d9bfc2016-11-01 13:31:58 -07001066 assertDoubleEquals(Math.PI * Math.PI * Math.PI, getCircleArea(Math.PI, true));
1067 assertDoubleEquals(0d, getCircleArea(Math.PI, false));
Mingyao Yange58bdca2016-10-28 11:07:24 -07001068
1069 int[] iarray = {0, 0, 0};
1070 double[] darray = {0d, 0d, 0d};
1071 try {
1072 assertDoubleEquals(Math.PI * Math.PI * Math.PI, testDeoptimize(iarray, darray, Math.PI));
1073 } catch (Exception e) {
1074 System.out.println(e);
1075 }
1076 assertIntEquals(iarray[0], 1);
1077 assertIntEquals(iarray[1], 1);
1078 assertIntEquals(iarray[2], 1);
1079 assertDoubleEquals(darray[0], Math.PI);
1080 assertDoubleEquals(darray[1], Math.PI);
1081 assertDoubleEquals(darray[2], Math.PI);
Mingyao Yang86974902017-03-01 14:03:51 -08001082
1083 assertIntEquals(testAllocationEliminationOfArray1(), 11);
1084 assertIntEquals(testAllocationEliminationOfArray2(), 11);
1085 assertIntEquals(testAllocationEliminationOfArray3(2), 4);
1086 assertIntEquals(testAllocationEliminationOfArray4(2), 6);
Mingyao Yangeb2d2d346e2017-03-02 13:26:17 -08001087
1088 assertIntEquals(testStoreStore().i, 41);
1089 assertIntEquals(testStoreStore().j, 43);
1090 assertIntEquals(testStoreStoreWithDeoptimize(new int[4]), 4);
Mingyao Yang293f1c02017-11-08 15:22:17 -08001091
Mingyao Yang46721ef2017-10-05 14:45:17 -07001092 assertIntEquals(testExitMerge(true), 2);
1093 assertIntEquals(testExitMerge2(true), 2);
1094 assertIntEquals(testExitMerge2(false), 2);
1095
Mingyao Yang293f1c02017-11-08 15:22:17 -08001096 int ret = testNoSideEffects(iarray);
1097 assertIntEquals(iarray[0], 101);
1098 assertIntEquals(iarray[1], 102);
1099 assertIntEquals(ret, 108);
Mingyao Yang8df69d42015-10-22 15:40:58 -07001100 }
Mingyao Yang40bcb932016-02-03 05:46:57 -08001101
1102 static boolean sFlag;
Mingyao Yang8df69d42015-10-22 15:40:58 -07001103}