blob: cc1e07cabf7653a312212f4c841b26734fa38323 [file] [log] [blame]
Aart Bik08ec1802016-11-10 18:21:30 -08001/*
2 * Copyright (C) 2016 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
17/**
18 * Regression tests for LICM.
19 */
20public class Main {
21
22 static int sA;
23
24 //
25 // We cannot hoist the null check (can throw) above the field
26 // assignment (has write side effects) because that would result
27 // in throwing an exception before the assignment is done.
28 //
29 /// CHECK-START: void Main.foo(int[]) licm (before)
30 /// CHECK-DAG: LoadClass loop:<<Loop:B\d+>> outer_loop:none
31 /// CHECK-DAG: StaticFieldSet loop:<<Loop>> outer_loop:none
32 /// CHECK-DAG: NullCheck loop:<<Loop>> outer_loop:none
33 /// CHECK-DAG: ArrayLength loop:<<Loop>> outer_loop:none
34 //
35 /// CHECK-START: void Main.foo(int[]) licm (after)
36 /// CHECK-DAG: LoadClass loop:none
37 /// CHECK-DAG: StaticFieldSet loop:<<Loop:B\d+>> outer_loop:none
38 /// CHECK-DAG: NullCheck loop:<<Loop>> outer_loop:none
39 /// CHECK-DAG: ArrayLength loop:<<Loop>> outer_loop:none
40 //
41 /// CHECK-START: void Main.foo(int[]) licm (after)
42 /// CHECK-NOT: LoadClass loop:{{B\d+}} outer_loop:none
43 static void foo(int[] arr) {
44 int j = 0;
45 do {
46 sA = 1;
47 } while (j < arr.length);
48 }
49
50 public static void main(String[] args) {
51 sA = 0;
52 try {
53 foo(null);
54 } catch (Exception e) {
55 }
56 expectEquals(1, sA);
57
58 System.out.println("passed");
59 }
60
61 private static void expectEquals(int expected, int result) {
62 if (expected != result) {
63 throw new Error("Expected: " + expected + ", found: " + result);
64 }
65 }
66}