blob: 95b1a93b8898ada41b4b4151130deff450a3b920 [file] [log] [blame]
Mark Mendell3b9f3042015-09-24 08:43:40 -04001/*
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
17public class Main {
18
19 public static int $inline$method() {
20 return 5;
21 }
22
Aart Bik2767f4b2016-10-28 15:03:53 -070023 /// CHECK-START: int Main.wholeSwitchDead(int) dead_code_elimination$after_inlining (before)
Mark Mendell3b9f3042015-09-24 08:43:40 -040024 /// CHECK-DAG: PackedSwitch
25
Aart Bik2767f4b2016-10-28 15:03:53 -070026 /// CHECK-START: int Main.wholeSwitchDead(int) dead_code_elimination$after_inlining (after)
Mark Mendell3b9f3042015-09-24 08:43:40 -040027 /// CHECK-DAG: <<Const100:i\d+>> IntConstant 100
28 /// CHECK-DAG: Return [<<Const100>>]
29
Aart Bik2767f4b2016-10-28 15:03:53 -070030 /// CHECK-START: int Main.wholeSwitchDead(int) dead_code_elimination$after_inlining (after)
Mark Mendell3b9f3042015-09-24 08:43:40 -040031 /// CHECK-NOT: PackedSwitch
32
33 public static int wholeSwitchDead(int j) {
34 int i = $inline$method();
35 int l = 100;
36 if (i > 100) {
37 switch(j) {
38 case 1:
39 i++;
40 break;
41 case 2:
42 i = 99;
43 break;
44 case 3:
45 i = 100;
46 break;
47 case 4:
48 i = -100;
49 break;
50 case 5:
51 i = 7;
52 break;
53 case 6:
54 i = -9;
55 break;
56 }
57 l += i;
58 }
59
60 return l;
61 }
62
Aart Bik2767f4b2016-10-28 15:03:53 -070063 /// CHECK-START: int Main.constantSwitch_InRange() dead_code_elimination$after_inlining (before)
Mark Mendell3b9f3042015-09-24 08:43:40 -040064 /// CHECK-DAG: PackedSwitch
65
Aart Bik2767f4b2016-10-28 15:03:53 -070066 /// CHECK-START: int Main.constantSwitch_InRange() dead_code_elimination$after_inlining (after)
Mark Mendell3b9f3042015-09-24 08:43:40 -040067 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
68 /// CHECK-DAG: Return [<<Const7>>]
69
Aart Bik2767f4b2016-10-28 15:03:53 -070070 /// CHECK-START: int Main.constantSwitch_InRange() dead_code_elimination$after_inlining (after)
Mark Mendell3b9f3042015-09-24 08:43:40 -040071 /// CHECK-NOT: PackedSwitch
72
73 public static int constantSwitch_InRange() {
74 int i = $inline$method();
75 switch(i) {
76 case 1:
77 i++;
78 break;
79 case 2:
80 i = 99;
81 break;
82 case 3:
83 i = 100;
84 break;
85 case 4:
86 i = -100;
87 break;
88 case 5:
89 i = 7;
90 break;
91 case 6:
92 i = -9;
93 break;
94 }
95
96 return i;
97 }
98
Aart Bik2767f4b2016-10-28 15:03:53 -070099 /// CHECK-START: int Main.constantSwitch_AboveRange() dead_code_elimination$after_inlining (before)
Mark Mendell3b9f3042015-09-24 08:43:40 -0400100 /// CHECK-DAG: PackedSwitch
101
Aart Bik2767f4b2016-10-28 15:03:53 -0700102 /// CHECK-START: int Main.constantSwitch_AboveRange() dead_code_elimination$after_inlining (after)
Mark Mendell3b9f3042015-09-24 08:43:40 -0400103 /// CHECK-DAG: <<Const15:i\d+>> IntConstant 15
104 /// CHECK-DAG: Return [<<Const15>>]
105
Aart Bik2767f4b2016-10-28 15:03:53 -0700106 /// CHECK-START: int Main.constantSwitch_AboveRange() dead_code_elimination$after_inlining (after)
Mark Mendell3b9f3042015-09-24 08:43:40 -0400107 /// CHECK-NOT: PackedSwitch
108
109 public static int constantSwitch_AboveRange() {
110 int i = $inline$method() + 10;
111 switch(i) {
112 case 1:
113 i++;
114 break;
115 case 2:
116 i = 99;
117 break;
118 case 3:
119 i = 100;
120 break;
121 case 4:
122 i = -100;
123 break;
124 case 5:
125 i = 7;
126 break;
127 case 6:
128 i = -9;
129 break;
130 }
131
132 return i;
133 }
134
Aart Bik2767f4b2016-10-28 15:03:53 -0700135 /// CHECK-START: int Main.constantSwitch_BelowRange() dead_code_elimination$after_inlining (before)
Mark Mendell3b9f3042015-09-24 08:43:40 -0400136 /// CHECK-DAG: PackedSwitch
137
Aart Bik2767f4b2016-10-28 15:03:53 -0700138 /// CHECK-START: int Main.constantSwitch_BelowRange() dead_code_elimination$after_inlining (after)
Mark Mendell3b9f3042015-09-24 08:43:40 -0400139 /// CHECK-DAG: <<ConstM5:i\d+>> IntConstant -5
140 /// CHECK-DAG: Return [<<ConstM5>>]
141
Aart Bik2767f4b2016-10-28 15:03:53 -0700142 /// CHECK-START: int Main.constantSwitch_BelowRange() dead_code_elimination$after_inlining (after)
Mark Mendell3b9f3042015-09-24 08:43:40 -0400143 /// CHECK-NOT: PackedSwitch
144
145 public static int constantSwitch_BelowRange() {
146 int i = $inline$method() - 10;
147 switch(i) {
148 case 1:
149 i++;
150 break;
151 case 2:
152 i = 99;
153 break;
154 case 3:
155 i = 100;
156 break;
157 case 4:
158 i = -100;
159 break;
160 case 5:
161 i = 7;
162 break;
163 case 6:
164 i = -9;
165 break;
166 }
167
168 return i;
169 }
170
171 public static void main(String[] args) throws Exception {
172 int ret_val = wholeSwitchDead(10);
173 if (ret_val != 100) {
174 throw new Error("Incorrect return value from wholeSwitchDead:" + ret_val);
175 }
176
177 ret_val = constantSwitch_InRange();
178 if (ret_val != 7) {
179 throw new Error("Incorrect return value from constantSwitch_InRange:" + ret_val);
180 }
181
182 ret_val = constantSwitch_AboveRange();
183 if (ret_val != 15) {
184 throw new Error("Incorrect return value from constantSwitch_AboveRange:" + ret_val);
185 }
186
187 ret_val = constantSwitch_BelowRange();
188 if (ret_val != -5) {
189 throw new Error("Incorrect return value from constantSwitch_BelowRange:" + ret_val);
190 }
191 }
192}