• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 {
main(String[] args)18     public static void main(String[] args) {
19         $noinline$assertEquals(0, $noinline$pathologicalCase());
20     }
21 
$noinline$assertEquals(int expected, int result)22     public static void $noinline$assertEquals(int expected, int result) {
23         if (expected != result) {
24             throw new Error("Expected: " + expected + ", found: " + result);
25         }
26     }
27 
28     // Empty $noinline$ method so that it doesn't get removed.
$noinline$emptyMethod(int val)29     private static void $noinline$emptyMethod(int val) {}
30 
31     // A pathological case which has > 15 loop header phis in a row.
32     /// CHECK-START: int Main.$noinline$pathologicalCase() induction_var_analysis (before)
33     /// CHECK: <<Const0:i\d+>> IntConstant 0
34     /// CHECK: <<Phi1:i\d+>>  Phi [<<Const0>>,<<Add1:i\d+>>]
35     /// CHECK: <<Phi2:i\d+>>  Phi [<<Phi1>>,<<Add2:i\d+>>]
36     /// CHECK: <<Phi3:i\d+>>  Phi [<<Phi2>>,<<Add3:i\d+>>]
37     /// CHECK: <<Phi4:i\d+>>  Phi [<<Phi3>>,<<Add4:i\d+>>]
38     /// CHECK: <<Phi5:i\d+>>  Phi [<<Phi4>>,<<Add5:i\d+>>]
39     /// CHECK: <<Phi6:i\d+>>  Phi [<<Phi5>>,<<Add6:i\d+>>]
40     /// CHECK: <<Phi7:i\d+>>  Phi [<<Phi6>>,<<Add7:i\d+>>]
41     /// CHECK: <<Phi8:i\d+>>  Phi [<<Phi7>>,<<Add8:i\d+>>]
42     /// CHECK: <<Phi9:i\d+>>  Phi [<<Phi8>>,<<Add9:i\d+>>]
43     /// CHECK: <<Phi10:i\d+>> Phi [<<Phi9>>,<<Add10:i\d+>>]
44     /// CHECK: <<Phi11:i\d+>> Phi [<<Phi10>>,<<Add11:i\d+>>]
45     /// CHECK: <<Phi12:i\d+>> Phi [<<Phi11>>,<<Add12:i\d+>>]
46     /// CHECK: <<Phi13:i\d+>> Phi [<<Phi12>>,<<Add13:i\d+>>]
47     /// CHECK: <<Phi14:i\d+>> Phi [<<Phi13>>,<<Add14:i\d+>>]
48     /// CHECK: <<Phi15:i\d+>> Phi [<<Phi14>>,<<Add15:i\d+>>]
49     /// CHECK: <<Phi16:i\d+>> Phi [<<Phi15>>,<<Add16:i\d+>>]
$noinline$pathologicalCase()50     private static int $noinline$pathologicalCase() {
51         int value = 0;
52         for (; value < 3; value++) {
53             $noinline$emptyMethod(value);
54         }
55 
56         for (; value < 5; value++) {
57             $noinline$emptyMethod(value);
58         }
59 
60         for (; value < 7; value++) {
61             $noinline$emptyMethod(value);
62         }
63 
64         for (; value < 9; value++) {
65             $noinline$emptyMethod(value);
66         }
67 
68         for (; value < 11; value++) {
69             $noinline$emptyMethod(value);
70         }
71 
72         for (; value < 13; value++) {
73             $noinline$emptyMethod(value);
74         }
75 
76         for (; value < 15; value++) {
77             $noinline$emptyMethod(value);
78         }
79 
80         for (; value < 17; value++) {
81             $noinline$emptyMethod(value);
82         }
83 
84         for (; value < 19; value++) {
85             $noinline$emptyMethod(value);
86         }
87 
88         for (; value < 21; value++) {
89             $noinline$emptyMethod(value);
90         }
91 
92         for (; value < 23; value++) {
93             $noinline$emptyMethod(value);
94         }
95 
96         for (; value < 25; value++) {
97             $noinline$emptyMethod(value);
98         }
99 
100         for (; value < 27; value++) {
101             $noinline$emptyMethod(value);
102         }
103 
104         for (; value < 29; value++) {
105             $noinline$emptyMethod(value);
106         }
107 
108         for (; value < 31; value++) {
109             $noinline$emptyMethod(value);
110         }
111 
112         for (; value < 33; value++) {
113             $noinline$emptyMethod(value);
114         }
115 
116         return 0;
117     }
118 }
119