• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 public class Main {
18 
19   static int static_variable = 0;
20 
21   /// CHECK-START-ARM64: int Main.arrayAccess() scheduler (before)
22   /// CHECK:    <<Const1:i\d+>>       IntConstant 1
23   /// CHECK:    <<i0:i\d+>>           Phi
24   /// CHECK:    <<res0:i\d+>>         Phi
25   /// CHECK:    <<Array:i\d+>>        IntermediateAddress
26   /// CHECK:    <<ArrayGet1:i\d+>>    ArrayGet [<<Array>>,<<i0>>]
27   /// CHECK:    <<res1:i\d+>>         Add [<<res0>>,<<ArrayGet1>>]
28   /// CHECK:    <<i1:i\d+>>           Add [<<i0>>,<<Const1>>]
29   /// CHECK:    <<ArrayGet2:i\d+>>    ArrayGet [<<Array>>,<<i1>>]
30   /// CHECK:                          Add [<<res1>>,<<ArrayGet2>>]
31 
32   /// CHECK-START-ARM64: int Main.arrayAccess() scheduler (after)
33   /// CHECK:    <<Const1:i\d+>>       IntConstant 1
34   /// CHECK:    <<i0:i\d+>>           Phi
35   /// CHECK:    <<res0:i\d+>>         Phi
36   /// CHECK:    <<Array:i\d+>>        IntermediateAddress
37   /// CHECK:    <<ArrayGet1:i\d+>>    ArrayGet [<<Array>>,<<i0>>]
38   /// CHECK:    <<i1:i\d+>>           Add [<<i0>>,<<Const1>>]
39   /// CHECK:    <<ArrayGet2:i\d+>>    ArrayGet [<<Array>>,<<i1>>]
40   /// CHECK:    <<res1:i\d+>>         Add [<<res0>>,<<ArrayGet1>>]
41   /// CHECK:                          Add [<<res1>>,<<ArrayGet2>>]
42 
arrayAccess()43   public static int arrayAccess() {
44     int res = 0;
45     int [] array = new int[10];
46     for (int i = 0; i < 9; i++) {
47       res += array[i];
48       res += array[i + 1];
49     }
50     return res;
51   }
52 
53   /// CHECK-START-ARM64: int Main.intDiv(int) scheduler (before)
54   /// CHECK:               Sub
55   /// CHECK:               DivZeroCheck
56   /// CHECK:               Div
57   /// CHECK:               StaticFieldSet
58 
59   /// CHECK-START-ARM64: int Main.intDiv(int) scheduler (after)
60   /// CHECK:               Sub
61   /// CHECK-NOT:           StaticFieldSet
62   /// CHECK:               DivZeroCheck
63   /// CHECK-NOT:           Sub
64   /// CHECK:               Div
intDiv(int arg)65   public static int intDiv(int arg) {
66     int res = 0;
67     int tmp = arg;
68     for (int i = 1; i < arg; i++) {
69       tmp -= i;
70       res = res / i;  // div-zero check barrier.
71       static_variable++;
72     }
73     res += tmp;
74     return res;
75   }
76 
main(String[] args)77   public static void main(String[] args) {
78     if ((arrayAccess() + intDiv(10)) != -35) {
79       System.out.println("FAIL");
80     }
81   }
82 }
83