blob: 262d2c1983a0f74dd61ac84a037f54cf844de4bc [file] [log] [blame]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * 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 */
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000016
David Brazdilf02c3cf2016-02-29 09:14:51 +000017import java.lang.reflect.Method;
18
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000019public class Main {
20
David Brazdil0d13fee2015-04-17 14:52:19 +010021 public static void assertBooleanEquals(boolean expected, boolean result) {
22 if (expected != result) {
23 throw new Error("Expected: " + expected + ", found: " + result);
24 }
25 }
26
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000027 public static void assertIntEquals(int expected, int result) {
28 if (expected != result) {
29 throw new Error("Expected: " + expected + ", found: " + result);
30 }
31 }
32
33 public static void assertLongEquals(long expected, long result) {
34 if (expected != result) {
35 throw new Error("Expected: " + expected + ", found: " + result);
36 }
37 }
38
Nicolas Geoffray0d221842015-04-27 08:53:46 +000039 public static void assertFloatEquals(float expected, float result) {
40 if (expected != result) {
41 throw new Error("Expected: " + expected + ", found: " + result);
42 }
43 }
44
45 public static void assertDoubleEquals(double expected, double result) {
46 if (expected != result) {
47 throw new Error("Expected: " + expected + ", found: " + result);
48 }
49 }
50
Vladimir Markob52bbde2016-02-12 12:06:05 +000051 public static void assertStringEquals(String expected, String result) {
52 if (expected == null ? result != null : !expected.equals(result)) {
53 throw new Error("Expected: " + expected + ", found: " + result);
54 }
55 }
56
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000057 /**
58 * Tiny programs exercising optimizations of arithmetic identities.
59 */
60
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010061 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +010062 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
63 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
64 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const0>>,<<Arg>>]
65 /// CHECK-DAG: Return [<<Add>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000066
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010067 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +010068 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
69 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +010070
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010071 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +010072 /// CHECK-NOT: Add
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000073
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010074 public static long $noinline$Add0(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000075 return 0 + arg;
76 }
77
Anton Kirilove14dc862016-05-13 17:56:15 +010078 /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (before)
79 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
80 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
81 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
82 /// CHECK-DAG: <<ConstM3:i\d+>> IntConstant -3
83 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
84 /// CHECK-DAG: <<Add1:i\d+>> Add [<<ArgValue>>,<<Const1>>]
85 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Add1>>,<<Const2>>]
86 /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add2>>,<<ConstM3>>]
87 /// CHECK-DAG: <<Add4:i\d+>> Add [<<Add3>>,<<Const4>>]
88 /// CHECK-DAG: Return [<<Add4>>]
89
90 /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (after)
91 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
92 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
93 /// CHECK-DAG: <<Add:i\d+>> Add [<<ArgValue>>,<<Const4>>]
94 /// CHECK-DAG: Return [<<Add>>]
95
96 public static int $noinline$AddAddSubAddConst(int arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +010097 return arg + 1 + 2 - 3 + 4;
98 }
99
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100100 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100101 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
102 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
103 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<ConstF>>]
104 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000105
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100106 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100107 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
108 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000109
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100110 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100111 /// CHECK-NOT: And
Alexandre Rames74417692015-04-09 15:21:41 +0100112
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100113 public static int $noinline$AndAllOnes(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000114 return arg & -1;
115 }
116
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100117 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100118 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
119 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
120 /// CHECK-DAG: <<Const15:i\d+>> IntConstant 15
121 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
122 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const15>>]
123 /// CHECK-DAG: Return [<<And>>]
124
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100125 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100126 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
127 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
128 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
129 /// CHECK-DAG: Return [<<UShr>>]
130
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100131 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100132 /// CHECK-NOT: And
133
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100134 public static int $noinline$UShr28And15(int arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100135 return (arg >>> 28) & 15;
136 }
137
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100138 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100139 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
140 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
141 /// CHECK-DAG: <<Const15:j\d+>> LongConstant 15
142 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
143 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const15>>]
144 /// CHECK-DAG: Return [<<And>>]
145
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100146 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100147 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
148 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
149 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
150 /// CHECK-DAG: Return [<<UShr>>]
151
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100152 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100153 /// CHECK-NOT: And
154
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100155 public static long $noinline$UShr60And15(long arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100156 return (arg >>> 60) & 15;
157 }
158
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100159 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100160 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
161 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
162 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
163 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
164 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
165 /// CHECK-DAG: Return [<<And>>]
166
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100167 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100168 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
169 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
170 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
171 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
172 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
173 /// CHECK-DAG: Return [<<And>>]
174
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100175 public static int $noinline$UShr28And7(int arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100176 return (arg >>> 28) & 7;
177 }
178
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100179 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100180 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
181 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
182 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
183 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
184 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
185 /// CHECK-DAG: Return [<<And>>]
186
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100187 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100188 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
189 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
190 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
191 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
192 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
193 /// CHECK-DAG: Return [<<And>>]
194
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100195 public static long $noinline$UShr60And7(long arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100196 return (arg >>> 60) & 7;
197 }
198
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100199 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100200 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
201 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
202 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
203 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
204 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const255>>]
205 /// CHECK-DAG: Return [<<And>>]
206
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100207 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100208 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
209 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
210 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const24>>]
211 /// CHECK-DAG: Return [<<UShr>>]
212
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100213 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100214 /// CHECK-NOT: Shr
215 /// CHECK-NOT: And
216
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100217 public static int $noinline$Shr24And255(int arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100218 return (arg >> 24) & 255;
219 }
220
Vladimir Marko61b92282017-10-11 13:23:17 +0100221 /// CHECK-START: int Main.$noinline$Shr25And127(int) instruction_simplifier (before)
222 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
223 /// CHECK-DAG: <<Const25:i\d+>> IntConstant 25
224 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
225 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const25>>]
226 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
227 /// CHECK-DAG: Return [<<And>>]
228
229 /// CHECK-START: int Main.$noinline$Shr25And127(int) instruction_simplifier (after)
230 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
231 /// CHECK-DAG: <<Const25:i\d+>> IntConstant 25
232 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const25>>]
233 /// CHECK-DAG: Return [<<UShr>>]
234
235 /// CHECK-START: int Main.$noinline$Shr25And127(int) instruction_simplifier (after)
236 /// CHECK-NOT: Shr
237 /// CHECK-NOT: And
238
239 public static int $noinline$Shr25And127(int arg) {
240 return (arg >> 25) & 127;
241 }
242
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100243 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100244 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
245 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
246 /// CHECK-DAG: <<Const255:j\d+>> LongConstant 255
247 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
248 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const255>>]
249 /// CHECK-DAG: Return [<<And>>]
250
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100251 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100252 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
253 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
254 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const56>>]
255 /// CHECK-DAG: Return [<<UShr>>]
256
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100257 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100258 /// CHECK-NOT: Shr
259 /// CHECK-NOT: And
260
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100261 public static long $noinline$Shr56And255(long arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100262 return (arg >> 56) & 255;
263 }
264
Vladimir Marko61b92282017-10-11 13:23:17 +0100265 /// CHECK-START: long Main.$noinline$Shr57And127(long) instruction_simplifier (before)
266 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
267 /// CHECK-DAG: <<Const57:i\d+>> IntConstant 57
268 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
269 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const57>>]
270 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
271 /// CHECK-DAG: Return [<<And>>]
272
273 /// CHECK-START: long Main.$noinline$Shr57And127(long) instruction_simplifier (after)
274 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
275 /// CHECK-DAG: <<Const57:i\d+>> IntConstant 57
276 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const57>>]
277 /// CHECK-DAG: Return [<<UShr>>]
278
279 /// CHECK-START: long Main.$noinline$Shr57And127(long) instruction_simplifier (after)
280 /// CHECK-NOT: Shr
281 /// CHECK-NOT: And
282
283 public static long $noinline$Shr57And127(long arg) {
284 return (arg >> 57) & 127;
285 }
286
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100287 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100288 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
289 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
290 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
291 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
292 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
293 /// CHECK-DAG: Return [<<And>>]
294
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100295 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100296 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
297 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
298 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
299 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
300 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
301 /// CHECK-DAG: Return [<<And>>]
302
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100303 public static int $noinline$Shr24And127(int arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100304 return (arg >> 24) & 127;
305 }
306
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100307 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100308 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
309 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
310 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
311 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
312 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
313 /// CHECK-DAG: Return [<<And>>]
314
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100315 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100316 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
317 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
318 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
319 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
320 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
321 /// CHECK-DAG: Return [<<And>>]
322
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100323 public static long $noinline$Shr56And127(long arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100324 return (arg >> 56) & 127;
325 }
326
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100327 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100328 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
329 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
330 /// CHECK-DAG: <<Div:j\d+>> Div [<<Arg>>,<<Const1>>]
331 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000332
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100333 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100334 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
335 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000336
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100337 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100338 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100339
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100340 public static long $noinline$Div1(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000341 return arg / 1;
342 }
343
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100344 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100345 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
346 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
347 /// CHECK-DAG: <<Div:i\d+>> Div [<<Arg>>,<<ConstN1>>]
348 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000349
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100350 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100351 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
352 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
353 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000354
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100355 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100356 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100357
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100358 public static int $noinline$DivN1(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000359 return arg / -1;
360 }
361
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100362 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100363 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
364 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
David Brazdil57e863c2016-01-11 10:27:13 +0000365 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const1>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100366 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000367
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100368 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100369 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
370 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000371
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100372 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100373 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100374
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100375 public static long $noinline$Mul1(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000376 return arg * 1;
377 }
378
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100379 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100380 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
381 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
382 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Arg>>,<<ConstN1>>]
383 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000384
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100385 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100386 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
387 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
388 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000389
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100390 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100391 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100392
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100393 public static int $noinline$MulN1(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000394 return arg * -1;
395 }
396
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100397 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100398 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
399 /// CHECK-DAG: <<Const128:j\d+>> LongConstant 128
David Brazdil57e863c2016-01-11 10:27:13 +0000400 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const128>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100401 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000402
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100403 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100404 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
405 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
406 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Arg>>,<<Const7>>]
407 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000408
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100409 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100410 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100411
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100412 public static long $noinline$MulPowerOfTwo128(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000413 return arg * 128;
414 }
415
Anton Kirilove14dc862016-05-13 17:56:15 +0100416 /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (before)
417 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
418 /// CHECK-DAG: <<Const10:j\d+>> LongConstant 10
419 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11
420 /// CHECK-DAG: <<Const12:j\d+>> LongConstant 12
421 /// CHECK-DAG: <<Mul1:j\d+>> Mul [<<Const10>>,<<ArgValue>>]
422 /// CHECK-DAG: <<Mul2:j\d+>> Mul [<<Mul1>>,<<Const11>>]
423 /// CHECK-DAG: <<Mul3:j\d+>> Mul [<<Mul2>>,<<Const12>>]
424 /// CHECK-DAG: Return [<<Mul3>>]
425
426 /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (after)
427 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
428 /// CHECK-DAG: <<Const1320:j\d+>> LongConstant 1320
429 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<ArgValue>>,<<Const1320>>]
430 /// CHECK-DAG: Return [<<Mul>>]
431
432 public static long $noinline$MulMulMulConst(long arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +0100433 return 10 * arg * 11 * 12;
434 }
435
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100436 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100437 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
438 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
439 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<Const0>>]
440 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000441
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100442 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100443 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
444 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000445
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100446 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100447 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100448
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100449 public static int $noinline$Or0(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000450 return arg | 0;
451 }
452
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100453 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100454 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
455 /// CHECK-DAG: <<Or:j\d+>> Or [<<Arg>>,<<Arg>>]
456 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000457
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100458 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100459 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
460 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000461
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100462 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100463 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100464
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100465 public static long $noinline$OrSame(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000466 return arg | arg;
467 }
468
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100469 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100470 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
471 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
472 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Arg>>,<<Const0>>]
473 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000474
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100475 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100476 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
477 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000478
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100479 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100480 /// CHECK-NOT: Shl
Alexandre Rames74417692015-04-09 15:21:41 +0100481
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100482 public static int $noinline$Shl0(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000483 return arg << 0;
484 }
485
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100486 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100487 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
488 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
489 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const0>>]
490 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000491
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100492 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100493 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
494 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000495
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100496 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100497 /// CHECK-NOT: Shr
Alexandre Rames74417692015-04-09 15:21:41 +0100498
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100499 public static long $noinline$Shr0(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000500 return arg >> 0;
501 }
502
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100503 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (before)
Vladimir Marko164306e2016-03-15 14:57:32 +0000504 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
505 /// CHECK-DAG: <<Const64:i\d+>> IntConstant 64
506 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const64>>]
507 /// CHECK-DAG: Return [<<Shr>>]
508
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100509 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
Vladimir Marko164306e2016-03-15 14:57:32 +0000510 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
511 /// CHECK-DAG: Return [<<Arg>>]
512
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100513 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
Vladimir Marko164306e2016-03-15 14:57:32 +0000514 /// CHECK-NOT: Shr
515
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100516 public static long $noinline$Shr64(long arg) {
Vladimir Marko164306e2016-03-15 14:57:32 +0000517 return arg >> 64;
518 }
519
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100520 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100521 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
522 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
523 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Const0>>]
524 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000525
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100526 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100527 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
528 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000529
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100530 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100531 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100532
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100533 public static long $noinline$Sub0(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000534 return arg - 0;
535 }
536
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100537 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100538 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
539 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
540 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const0>>,<<Arg>>]
541 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000542
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100543 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100544 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
545 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
546 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000547
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100548 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100549 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100550
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100551 public static int $noinline$SubAliasNeg(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000552 return 0 - arg;
553 }
554
Anton Kirilove14dc862016-05-13 17:56:15 +0100555 /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (before)
556 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
557 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
558 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
559 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<ArgValue>>]
560 /// CHECK-DAG: <<Add:i\d+>> Add [<<Sub>>,<<Const6>>]
561 /// CHECK-DAG: Return [<<Add>>]
562
563 /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (after)
564 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
565 /// CHECK-DAG: <<Const11:i\d+>> IntConstant 11
566 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const11>>,<<ArgValue>>]
567 /// CHECK-DAG: Return [<<Sub>>]
568
569 public static int $noinline$SubAddConst1(int arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +0100570 return 5 - arg + 6;
571 }
572
573 /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (before)
574 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
575 /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14
576 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
577 /// CHECK-DAG: <<Add:i\d+>> Add [<<ArgValue>>,<<Const13>>]
578 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const14>>,<<Add>>]
579 /// CHECK-DAG: Return [<<Sub>>]
580
581 /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (after)
582 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
583 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
584 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const1>>,<<ArgValue>>]
585 /// CHECK-DAG: Return [<<Sub>>]
586
587 public static int $noinline$SubAddConst2(int arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +0100588 return 14 - (arg + 13);
589 }
590
591 /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (before)
592 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
593 /// CHECK-DAG: <<Const17:j\d+>> LongConstant 17
594 /// CHECK-DAG: <<Const18:j\d+>> LongConstant 18
595 /// CHECK-DAG: <<Sub1:j\d+>> Sub [<<Const18>>,<<ArgValue>>]
596 /// CHECK-DAG: <<Sub2:j\d+>> Sub [<<Const17>>,<<Sub1>>]
597 /// CHECK-DAG: Return [<<Sub2>>]
598
599 /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (after)
600 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
601 /// CHECK-DAG: <<ConstM1:j\d+>> LongConstant -1
602 /// CHECK-DAG: <<Add:j\d+>> Add [<<ArgValue>>,<<ConstM1>>]
603 /// CHECK-DAG: Return [<<Add>>]
604
605 public static long $noinline$SubSubConst(long arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +0100606 return 17 - (18 - arg);
607 }
608
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100609 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100610 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
611 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
612 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const0>>]
613 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000614
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100615 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100616 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
617 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000618
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100619 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100620 /// CHECK-NOT: UShr
Alexandre Rames74417692015-04-09 15:21:41 +0100621
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100622 public static long $noinline$UShr0(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000623 return arg >>> 0;
624 }
625
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100626 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100627 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
628 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
629 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Const0>>]
630 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000631
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100632 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100633 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
634 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000635
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100636 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100637 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100638
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100639 public static int $noinline$Xor0(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000640 return arg ^ 0;
641 }
642
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100643 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100644 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
645 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
646 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<ConstF>>]
647 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000648
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100649 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100650 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
651 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
652 /// CHECK-DAG: Return [<<Not>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000653
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100654 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100655 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100656
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100657 public static int $noinline$XorAllOnes(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000658 return arg ^ -1;
659 }
660
Alexandre Rames188d4312015-04-09 18:30:21 +0100661 /**
662 * Test that addition or subtraction operation with both inputs negated are
663 * optimized to use a single negation after the operation.
664 * The transformation tested is implemented in
665 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
666 */
667
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100668 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100669 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
670 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
671 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
672 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
673 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
674 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100675
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100676 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100677 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
678 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
679 /// CHECK-NOT: Neg
680 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
681 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
682 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100683
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100684 public static int $noinline$AddNegs1(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100685 return -arg1 + -arg2;
686 }
687
688 /**
689 * This is similar to the test-case AddNegs1, but the negations have
690 * multiple uses.
691 * The transformation tested is implemented in
692 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
693 * The current code won't perform the previous optimization. The
694 * transformations do not look at other uses of their inputs. As they don't
695 * know what will happen with other uses, they do not take the risk of
696 * increasing the register pressure by creating or extending live ranges.
697 */
698
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100699 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100700 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
701 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
702 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
703 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
704 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
705 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
706 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
707 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100708
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100709 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100710 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
711 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
712 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
713 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
714 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
715 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
716 /// CHECK-NOT: Neg
717 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
718 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100719
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100720 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) GVN (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100721 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
722 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
723 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
724 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
725 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
726 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add>>,<<Add>>]
727 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100728
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100729 public static int $noinline$AddNegs2(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100730 int temp1 = -arg1;
731 int temp2 = -arg2;
732 return (temp1 + temp2) | (temp1 + temp2);
733 }
734
735 /**
736 * This follows test-cases AddNegs1 and AddNegs2.
737 * The transformation tested is implemented in
738 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
739 * The optimization should not happen if it moves an additional instruction in
740 * the loop.
741 */
742
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100743 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100744 // -------------- Arguments and initial negation operations.
745 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
746 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
747 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
748 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
749 /// CHECK: Goto
750 // -------------- Loop
751 /// CHECK: SuspendCheck
752 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
753 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100754
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100755 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100756 // -------------- Arguments and initial negation operations.
757 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
758 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
759 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
760 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
761 /// CHECK: Goto
762 // -------------- Loop
763 /// CHECK: SuspendCheck
764 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
765 /// CHECK-NOT: Neg
766 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100767
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100768 public static long $noinline$AddNegs3(long arg1, long arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100769 long res = 0;
770 long n_arg1 = -arg1;
771 long n_arg2 = -arg2;
772 for (long i = 0; i < 1; i++) {
773 res += n_arg1 + n_arg2 + i;
774 }
775 return res;
776 }
777
778 /**
779 * Test the simplification of an addition with a negated argument into a
780 * subtraction.
781 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
782 */
783
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100784 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100785 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
786 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
787 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
788 /// CHECK-DAG: <<Add:j\d+>> Add [<<Neg>>,<<Arg2>>]
789 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100790
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100791 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100792 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
793 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
794 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg2>>,<<Arg1>>]
795 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100796
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100797 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100798 /// CHECK-NOT: Neg
799 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100800
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100801 public static long $noinline$AddNeg1(long arg1, long arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100802 return -arg1 + arg2;
803 }
804
805 /**
806 * This is similar to the test-case AddNeg1, but the negation has two uses.
807 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
808 * The current code won't perform the previous optimization. The
809 * transformations do not look at other uses of their inputs. As they don't
810 * know what will happen with other uses, they do not take the risk of
811 * increasing the register pressure by creating or extending live ranges.
812 */
813
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100814 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100815 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
816 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
817 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
818 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
819 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
820 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
821 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100822
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100823 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100824 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
825 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
826 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
827 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
828 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
829 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
830 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100831
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100832 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100833 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100834
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100835 public static long $noinline$AddNeg2(long arg1, long arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100836 long temp = -arg2;
837 return (arg1 + temp) | (arg1 + temp);
838 }
839
840 /**
841 * Test simplification of the `-(-var)` pattern.
842 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
843 */
844
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100845 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100846 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
847 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg>>]
848 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Neg1>>]
849 /// CHECK-DAG: Return [<<Neg2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100850
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100851 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100852 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
853 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100854
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100855 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100856 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100857
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100858 public static long $noinline$NegNeg1(long arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100859 return -(-arg);
860 }
861
862 /**
863 * Test 'multi-step' simplification, where a first transformation yields a
864 * new simplification possibility for the current instruction.
865 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
866 * and in `InstructionSimplifierVisitor::VisitAdd`.
867 */
868
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100869 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100870 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
871 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg>>]
872 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Neg1>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000873 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg2>>,<<Neg1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100874 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100875
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100876 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100877 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
878 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg>>,<<Arg>>]
879 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100880
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100881 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100882 /// CHECK-NOT: Neg
883 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100884
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700885 /// CHECK-START: int Main.$noinline$NegNeg2(int) constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100886 /// CHECK: <<Const0:i\d+>> IntConstant 0
887 /// CHECK-NOT: Neg
888 /// CHECK-NOT: Add
889 /// CHECK: Return [<<Const0>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100890
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100891 public static int $noinline$NegNeg2(int arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100892 int temp = -arg;
893 return temp + -temp;
894 }
895
896 /**
897 * Test another 'multi-step' simplification, where a first transformation
898 * yields a new simplification possibility for the current instruction.
899 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
900 * and in `InstructionSimplifierVisitor::VisitSub`.
901 */
902
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100903 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100904 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
905 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
906 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg>>]
907 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const0>>,<<Neg>>]
908 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100909
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100910 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100911 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
912 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100913
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100914 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100915 /// CHECK-NOT: Neg
916 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100917
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100918 public static long $noinline$NegNeg3(long arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100919 return 0 - -arg;
920 }
921
922 /**
923 * Test that a negated subtraction is simplified to a subtraction with its
924 * arguments reversed.
925 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
926 */
927
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100928 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100929 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
930 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
931 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
932 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Sub>>]
933 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100934
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100935 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100936 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
937 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
938 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg2>>,<<Arg1>>]
939 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100940
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100941 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100942 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100943
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100944 public static int $noinline$NegSub1(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100945 return -(arg1 - arg2);
946 }
947
948 /**
949 * This is similar to the test-case NegSub1, but the subtraction has
950 * multiple uses.
951 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
952 * The current code won't perform the previous optimization. The
953 * transformations do not look at other uses of their inputs. As they don't
954 * know what will happen with other uses, they do not take the risk of
955 * increasing the register pressure by creating or extending live ranges.
956 */
957
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100958 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100959 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
960 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
961 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
962 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
963 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
964 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
965 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100966
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100967 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100968 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
969 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
970 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
971 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
972 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
973 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
974 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100975
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100976 public static int $noinline$NegSub2(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100977 int temp = arg1 - arg2;
978 return -temp | -temp;
979 }
980
981 /**
982 * Test simplification of the `~~var` pattern.
983 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`.
984 */
985
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100986 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (before)
Igor Murashkin42691732017-06-26 15:57:31 -0700987 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
988 /// CHECK-DAG: <<ConstNeg1:j\d+>> LongConstant -1
989 /// CHECK-DAG: <<Not1:j\d+>> Xor [<<Arg>>,<<ConstNeg1>>]
990 /// CHECK-DAG: <<Not2:j\d+>> Xor [<<Not1>>,<<ConstNeg1>>]
991 /// CHECK-DAG: Return [<<Not2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100992
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100993 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100994 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
995 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100996
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100997 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
Igor Murashkin42691732017-06-26 15:57:31 -0700998 /// CHECK-NOT: Xor
Alexandre Rames188d4312015-04-09 18:30:21 +0100999
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001000 public static long $noinline$NotNot1(long arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +01001001 return ~~arg;
1002 }
1003
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001004 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (before)
Igor Murashkin42691732017-06-26 15:57:31 -07001005 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1006 /// CHECK-DAG: <<ConstNeg1:i\d+>> IntConstant -1
1007 /// CHECK-DAG: <<Not1:i\d+>> Xor [<<Arg>>,<<ConstNeg1>>]
1008 /// CHECK-DAG: <<Not2:i\d+>> Xor [<<Not1>>,<<ConstNeg1>>]
1009 /// CHECK-DAG: <<Add:i\d+>> Add [<<Not2>>,<<Not1>>]
1010 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001011
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001012 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001013 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1014 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
David Brazdil57e863c2016-01-11 10:27:13 +00001015 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg>>,<<Not>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001016 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001017
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001018 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +00001019 /// CHECK: Not
1020 /// CHECK-NOT: Not
Alexandre Rames188d4312015-04-09 18:30:21 +01001021
Igor Murashkin42691732017-06-26 15:57:31 -07001022 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
1023 /// CHECK-NOT: Xor
1024
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001025 public static int $noinline$NotNot2(int arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +01001026 int temp = ~arg;
1027 return temp + ~temp;
1028 }
1029
1030 /**
1031 * Test the simplification of a subtraction with a negated argument.
1032 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1033 */
1034
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001035 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001036 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1037 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1038 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1039 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1040 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001041
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001042 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001043 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1044 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1045 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
1046 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
1047 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001048
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001049 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001050 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +01001051
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001052 public static int $noinline$SubNeg1(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +01001053 return -arg1 - arg2;
1054 }
1055
1056 /**
1057 * This is similar to the test-case SubNeg1, but the negation has
1058 * multiple uses.
1059 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1060 * The current code won't perform the previous optimization. The
1061 * transformations do not look at other uses of their inputs. As they don't
1062 * know what will happen with other uses, they do not take the risk of
1063 * increasing the register pressure by creating or extending live ranges.
1064 */
1065
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001066 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001067 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1068 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1069 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1070 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1071 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1072 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
1073 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001074
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001075 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001076 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1077 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1078 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1079 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1080 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1081 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
1082 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001083
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001084 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001085 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +01001086
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001087 public static int $noinline$SubNeg2(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +01001088 int temp = -arg1;
1089 return (temp - arg2) | (temp - arg2);
1090 }
1091
1092 /**
1093 * This follows test-cases SubNeg1 and SubNeg2.
1094 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1095 * The optimization should not happen if it moves an additional instruction in
1096 * the loop.
1097 */
1098
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001099 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001100 // -------------- Arguments and initial negation operation.
1101 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
1102 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
1103 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1104 /// CHECK: Goto
1105 // -------------- Loop
1106 /// CHECK: SuspendCheck
1107 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1108 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001109
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001110 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001111 // -------------- Arguments and initial negation operation.
1112 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
1113 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
1114 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1115 /// CHECK-DAG: Goto
1116 // -------------- Loop
1117 /// CHECK: SuspendCheck
1118 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1119 /// CHECK-NOT: Neg
1120 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001121
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001122 public static long $noinline$SubNeg3(long arg1, long arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +01001123 long res = 0;
1124 long temp = -arg1;
1125 for (long i = 0; i < 1; i++) {
1126 res += temp - arg2 - i;
1127 }
1128 return res;
1129 }
1130
Aart Bik639cc8c2016-10-18 13:03:31 -07001131 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001132 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001133 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1134 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001135 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001136 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1137 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<NotArg>>,<<Const2>>]
1138 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1139 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001140
Aart Bik639cc8c2016-10-18 13:03:31 -07001141 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001142 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
1143 /// CHECK-DAG: Return [<<True>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001144
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001145 public static boolean $noinline$EqualBoolVsIntConst(boolean arg) {
Nicolas Geoffraydac9b192016-07-15 10:46:17 +01001146 // Make calls that will be inlined to make sure the instruction simplifier
1147 // sees the simplification (dead code elimination will also try to simplify it).
1148 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) != 2;
1149 }
1150
1151 public static int $inline$ReturnArg(int arg) {
1152 return arg;
David Brazdil1e9ec052015-06-22 10:26:45 +01001153 }
1154
Aart Bik639cc8c2016-10-18 13:03:31 -07001155 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001156 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001157 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1158 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001159 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001160 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1161 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<NotArg>>,<<Const2>>]
1162 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1163 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001164
Aart Bik639cc8c2016-10-18 13:03:31 -07001165 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001166 /// CHECK-DAG: <<False:i\d+>> IntConstant 0
1167 /// CHECK-DAG: Return [<<False>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001168
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001169 public static boolean $noinline$NotEqualBoolVsIntConst(boolean arg) {
Nicolas Geoffraydac9b192016-07-15 10:46:17 +01001170 // Make calls that will be inlined to make sure the instruction simplifier
1171 // sees the simplification (dead code elimination will also try to simplify it).
1172 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) == 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001173 }
1174
David Brazdil0d13fee2015-04-17 14:52:19 +01001175 /*
1176 * Test simplification of double Boolean negation. Note that sometimes
1177 * both negations can be removed but we only expect the simplifier to
1178 * remove the second.
1179 */
1180
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001181 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (before)
1182 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001183 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 0
1184 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect method_name:Main.NegateValue
1185 /// CHECK-DAG: <<NotResult:z\d+>> NotEqual [<<Result>>,<<Const1>>]
1186 /// CHECK-DAG: If [<<NotResult>>]
1187
1188 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after)
1189 /// CHECK-NOT: NotEqual
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001190
1191 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after)
1192 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001193 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect method_name:Main.NegateValue
1194 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1195 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1196 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>]
1197 /// CHECK-DAG: Return [<<Phi>>]
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001198
Aart Bik639cc8c2016-10-18 13:03:31 -07001199 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001200 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001201 /// CHECK-NOT: BooleanNot [<<Arg>>]
1202 /// CHECK-NOT: Phi
1203
1204 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before)
1205 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1206 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1207 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1208 /// CHECK-DAG: <<Sel:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1209 /// CHECK-DAG: <<Sel2:i\d+>> Select [<<Const1>>,<<Const0>>,<<Sel>>]
1210 /// CHECK-DAG: Return [<<Sel2>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001211
Aart Bik639cc8c2016-10-18 13:03:31 -07001212 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001213 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001214 /// CHECK: BooleanNot [<<Arg>>]
1215 /// CHECK-NEXT: Goto
1216
1217 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after)
1218 /// CHECK-NOT: Select
David Brazdil0d13fee2015-04-17 14:52:19 +01001219
Sebastien Hertz55418e12016-09-23 16:51:42 +02001220 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) dead_code_elimination$final (after)
1221 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001222 /// CHECK-NOT: BooleanNot [<<Arg>>]
Sebastien Hertz55418e12016-09-23 16:51:42 +02001223 /// CHECK-DAG: Return [<<Arg>>]
1224
David Brazdil769c9e52015-04-27 13:54:09 +01001225 public static boolean NegateValue(boolean arg) {
1226 return !arg;
1227 }
1228
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001229 public static boolean $noinline$NotNotBool(boolean arg) {
David Brazdil769c9e52015-04-27 13:54:09 +01001230 return !(NegateValue(arg));
David Brazdil0d13fee2015-04-17 14:52:19 +01001231 }
1232
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001233 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001234 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1235 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
1236 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>]
1237 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001238
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001239 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001240 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1241 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5
1242 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>]
1243 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001244
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001245 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001246 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001247
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001248 public static float $noinline$Div2(float arg) {
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001249 return arg / 2.0f;
1250 }
1251
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001252 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001253 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1254 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
1255 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>]
1256 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001257
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001258 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001259 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1260 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5
1261 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>]
1262 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001263
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001264 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001265 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001266 public static double $noinline$Div2(double arg) {
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001267 return arg / 2.0;
1268 }
1269
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001270 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001271 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1272 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25
1273 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>]
1274 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001275
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001276 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001277 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1278 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4
1279 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>]
1280 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001281
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001282 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001283 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001284
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001285 public static float $noinline$DivMP25(float arg) {
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001286 return arg / -0.25f;
1287 }
1288
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001289 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001290 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1291 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25
1292 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>]
1293 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001294
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001295 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001296 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1297 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4
1298 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>]
1299 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001300
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001301 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001302 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001303 public static double $noinline$DivMP25(double arg) {
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001304 return arg / -0.25f;
1305 }
1306
Alexandre Rames38db7852015-11-20 15:02:45 +00001307 /**
1308 * Test strength reduction of factors of the form (2^n + 1).
1309 */
1310
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001311 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001312 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1313 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
1314 /// CHECK: Mul [<<Arg>>,<<Const9>>]
1315
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001316 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001317 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1318 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1319 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>]
1320 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>]
1321
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001322 public static int $noinline$mulPow2Plus1(int arg) {
Alexandre Rames38db7852015-11-20 15:02:45 +00001323 return arg * 9;
1324 }
1325
Alexandre Rames38db7852015-11-20 15:02:45 +00001326 /**
1327 * Test strength reduction of factors of the form (2^n - 1).
1328 */
1329
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001330 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001331 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1332 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31
David Brazdil57e863c2016-01-11 10:27:13 +00001333 /// CHECK: Mul [<<Const31>>,<<Arg>>]
Alexandre Rames38db7852015-11-20 15:02:45 +00001334
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001335 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001336 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1337 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1338 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>]
1339 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>]
1340
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001341 public static long $noinline$mulPow2Minus1(long arg) {
Alexandre Rames38db7852015-11-20 15:02:45 +00001342 return arg * 31;
1343 }
1344
Aart Bik639cc8c2016-10-18 13:03:31 -07001345 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001346 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdilf02c3cf2016-02-29 09:14:51 +00001347 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1348 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Mark Mendellf6529172015-11-17 11:16:56 -05001349 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1350 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +00001351 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1352 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001353
Aart Bik639cc8c2016-10-18 13:03:31 -07001354 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001355 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1356 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1357 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1358 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1359 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001360
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001361 public static int $noinline$booleanFieldNotEqualOne() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001362 return (booleanField == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001363 }
1364
Aart Bik639cc8c2016-10-18 13:03:31 -07001365 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001366 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdilf02c3cf2016-02-29 09:14:51 +00001367 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1368 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Mark Mendellf6529172015-11-17 11:16:56 -05001369 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdilf02c3cf2016-02-29 09:14:51 +00001370 /// CHECK-DAG: <<NE:z\d+>> Equal [<<Field>>,<<Const0>>]
1371 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1372 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001373
Aart Bik639cc8c2016-10-18 13:03:31 -07001374 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001375 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1376 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1377 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1378 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1379 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001380
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001381 public static int $noinline$booleanFieldEqualZero() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001382 return (booleanField != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001383 }
1384
Aart Bik639cc8c2016-10-18 13:03:31 -07001385 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001386 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001387 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
Mark Mendellf6529172015-11-17 11:16:56 -05001388 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +00001389 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001390 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001391 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1392 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1393 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001394 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001395 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1396 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001397
Aart Bik639cc8c2016-10-18 13:03:31 -07001398 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001399 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001400 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001401 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001402 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1403 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001404 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001405 /// CHECK-DAG: Return [<<Result>>]
1406 // Note that we match `LE` from Select because there are two identical
1407 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001408
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001409 public static int $noinline$intConditionNotEqualOne(int i) {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001410 return ((i > 42) == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001411 }
1412
Aart Bik639cc8c2016-10-18 13:03:31 -07001413 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001414 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1415 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001416 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1417 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001418 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001419 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1420 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1421 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
1422 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>]
1423 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1424 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001425
Aart Bik639cc8c2016-10-18 13:03:31 -07001426 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001427 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001428 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001429 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001430 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1431 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001432 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001433 /// CHECK-DAG: Return [<<Result>>]
1434 // Note that we match `LE` from Select because there are two identical
1435 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001436
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001437 public static int $noinline$intConditionEqualZero(int i) {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001438 return ((i > 42) != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001439 }
1440
1441 // Test that conditions on float/double are not flipped.
1442
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001443 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001444 /// CHECK: LessThanOrEqual
1445
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001446 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001447 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1448 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1449 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1450 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
1451 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1452 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1453 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001454
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001455 public static int $noinline$floatConditionNotEqualOne(float f) {
Mark Mendellf6529172015-11-17 11:16:56 -05001456 return ((f > 42.0f) == true) ? 13 : 54;
1457 }
1458
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001459 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001460 /// CHECK: LessThanOrEqual
1461
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001462 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001463 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1464 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1465 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1466 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1467 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1468 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1469 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001470
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001471 public static int $noinline$doubleConditionEqualZero(double d) {
Mark Mendellf6529172015-11-17 11:16:56 -05001472 return ((d > 42.0) != false) ? 13 : 54;
1473 }
Alexandre Rames38db7852015-11-20 15:02:45 +00001474
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001475 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001476 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1477 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1478 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1479 /// CHECK-DAG: Return [<<Int>>]
1480
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001481 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001482 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1483 /// CHECK-DAG: Return [<<Arg>>]
1484
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001485 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001486 /// CHECK-NOT: TypeConversion
1487
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001488 public static int $noinline$intToDoubleToInt(int value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001489 // Lossless conversion followed by a conversion back.
1490 return (int) (double) value;
1491 }
1492
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001493 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001494 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1495 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1496 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1497
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001498 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001499 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1500 /// CHECK-DAG: {{d\d+}} TypeConversion [<<Arg>>]
1501
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001502 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001503 /// CHECK-DAG: TypeConversion
1504 /// CHECK-NOT: TypeConversion
1505
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001506 public static String $noinline$intToDoubleToIntPrint(int value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001507 // Lossless conversion followed by a conversion back
1508 // with another use of the intermediate result.
1509 double d = (double) value;
1510 int i = (int) d;
1511 return "d=" + d + ", i=" + i;
1512 }
1513
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001514 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001515 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1516 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1517 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1518 /// CHECK-DAG: Return [<<Int>>]
1519
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001520 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001521 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1522 /// CHECK-DAG: Return [<<Arg>>]
1523
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001524 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001525 /// CHECK-NOT: TypeConversion
1526
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001527 public static int $noinline$byteToDoubleToInt(byte value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001528 // Lossless conversion followed by another conversion, use implicit conversion.
1529 return (int) (double) value;
1530 }
1531
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001532 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001533 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1534 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1535 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1536 /// CHECK-DAG: Return [<<Int>>]
1537
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001538 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001539 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1540 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1541 /// CHECK-DAG: Return [<<Int>>]
1542
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001543 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001544 /// CHECK-DAG: TypeConversion
1545 /// CHECK-NOT: TypeConversion
1546
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001547 public static int $noinline$floatToDoubleToInt(float value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001548 // Lossless conversion followed by another conversion.
1549 return (int) (double) value;
1550 }
1551
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001552 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001553 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1554 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1555 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1556
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001557 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001558 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1559 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1560 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1561
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001562 public static String $noinline$floatToDoubleToIntPrint(float value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001563 // Lossless conversion followed by another conversion with
1564 // an extra use of the intermediate result.
1565 double d = (double) value;
1566 int i = (int) d;
1567 return "d=" + d + ", i=" + i;
1568 }
1569
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001570 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001571 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1572 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1573 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1574 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1575 /// CHECK-DAG: Return [<<Short>>]
1576
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001577 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001578 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1579 /// CHECK-DAG: Return [<<Arg>>]
1580
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001581 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001582 /// CHECK-NOT: TypeConversion
1583
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001584 public static short $noinline$byteToDoubleToShort(byte value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001585 // Originally, this is byte->double->int->short. The first conversion is lossless,
1586 // so we merge this with the second one to byte->int which we omit as it's an implicit
1587 // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1588 return (short) (double) value;
1589 }
1590
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001591 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001592 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1593 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1594 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1595 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1596 /// CHECK-DAG: Return [<<Short>>]
1597
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001598 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001599 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1600 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Arg>>]
1601 /// CHECK-DAG: Return [<<Short>>]
1602
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001603 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001604 /// CHECK-DAG: TypeConversion
1605 /// CHECK-NOT: TypeConversion
1606
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001607 public static short $noinline$charToDoubleToShort(char value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001608 // Originally, this is char->double->int->short. The first conversion is lossless,
1609 // so we merge this with the second one to char->int which we omit as it's an implicit
1610 // conversion. Then we are left with the resulting char->short conversion.
1611 return (short) (double) value;
1612 }
1613
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001614 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001615 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1616 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1617 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1618 /// CHECK-DAG: Return [<<Short>>]
1619
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001620 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001621 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1622 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1623 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1624 /// CHECK-DAG: Return [<<Short>>]
1625
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001626 public static short $noinline$floatToIntToShort(float value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001627 // Lossy FP to integral conversion followed by another conversion: no simplification.
1628 return (short) value;
1629 }
1630
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001631 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001632 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1633 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1634 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1635 /// CHECK-DAG: Return [<<Int>>]
1636
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001637 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001638 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1639 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1640 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1641 /// CHECK-DAG: Return [<<Int>>]
1642
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001643 public static int $noinline$intToFloatToInt(int value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001644 // Lossy integral to FP conversion followed another conversion: no simplification.
1645 return (int) (float) value;
1646 }
1647
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001648 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001649 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1650 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1651 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1652 /// CHECK-DAG: Return [<<Double>>]
1653
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001654 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001655 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1656 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1657 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1658 /// CHECK-DAG: Return [<<Double>>]
1659
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001660 public static double $noinline$longToIntToDouble(long value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001661 // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1662 return (double) (int) value;
1663 }
1664
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001665 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001666 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1667 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1668 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1669 /// CHECK-DAG: Return [<<Long>>]
1670
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001671 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001672 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1673 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1674 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1675 /// CHECK-DAG: Return [<<Long>>]
1676
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001677 public static long $noinline$longToIntToLong(long value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001678 // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1679 return (long) (int) value;
1680 }
1681
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001682 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001683 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1684 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1685 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Char>>]
1686 /// CHECK-DAG: Return [<<Short>>]
1687
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001688 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001689 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1690 /// CHECK-DAG: Return [<<Arg>>]
1691
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001692 public static short $noinline$shortToCharToShort(short value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001693 // Integral conversion followed by non-widening integral conversion to original type.
1694 return (short) (char) value;
1695 }
1696
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001697 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001698 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1699 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1700 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Long>>]
1701 /// CHECK-DAG: Return [<<Int>>]
1702
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001703 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001704 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1705 /// CHECK-DAG: Return [<<Arg>>]
1706
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001707 public static int $noinline$shortToLongToInt(short value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001708 // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1709 return (int) (long) value;
1710 }
1711
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001712 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001713 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1714 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1715 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Char>>]
1716 /// CHECK-DAG: Return [<<Byte>>]
1717
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001718 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001719 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1720 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1721 /// CHECK-DAG: Return [<<Byte>>]
1722
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001723 public static byte $noinline$shortToCharToByte(short value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001724 // Integral conversion followed by non-widening integral conversion losing bits
1725 // from the original type. Simplify to use only one conversion.
1726 return (byte) (char) value;
1727 }
1728
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001729 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001730 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1731 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1732 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1733
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001734 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001735 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1736 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1737 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1738
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001739 public static String $noinline$shortToCharToBytePrint(short value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001740 // Integral conversion followed by non-widening integral conversion losing bits
1741 // from the original type with an extra use of the intermediate result.
1742 char c = (char) value;
1743 byte b = (byte) c;
1744 return "c=" + ((int) c) + ", b=" + ((int) b); // implicit conversions.
1745 }
1746
Vladimir Markoc8fb2112017-10-03 11:37:52 +01001747 /// CHECK-START: long Main.$noinline$intAndSmallLongConstant(int) instruction_simplifier (before)
1748 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1749 /// CHECK-DAG: <<Mask:j\d+>> LongConstant -12345678
1750 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1751 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>]
1752 /// CHECK-DAG: Return [<<And>>]
1753
1754 /// CHECK-START: long Main.$noinline$intAndSmallLongConstant(int) instruction_simplifier (after)
1755 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1756 /// CHECK-DAG: <<Mask:i\d+>> IntConstant -12345678
1757 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Mask>>]
1758 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<And>>]
1759 /// CHECK-DAG: Return [<<Long>>]
1760
1761 public static long $noinline$intAndSmallLongConstant(int value) {
1762 return value & -12345678L; // Shall be simplified (constant is 32-bit).
1763 }
1764
1765 /// CHECK-START: long Main.$noinline$intAndLargeLongConstant(int) instruction_simplifier (before)
1766 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1767 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 9876543210
1768 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1769 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>]
1770 /// CHECK-DAG: Return [<<And>>]
1771
1772 /// CHECK-START: long Main.$noinline$intAndLargeLongConstant(int) instruction_simplifier (after)
1773 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1774 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 9876543210
1775 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1776 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>]
1777 /// CHECK-DAG: Return [<<And>>]
1778
1779 public static long $noinline$intAndLargeLongConstant(int value) {
1780 return value & 9876543210L; // Shall not be simplified (constant is not 32-bit).
1781 }
1782
1783 /// CHECK-START: long Main.$noinline$intShr28And15L(int) instruction_simplifier (before)
1784 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1785 /// CHECK-DAG: <<Shift:i\d+>> IntConstant 28
1786 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 15
1787 /// CHECK-DAG: <<Shifted:i\d+>> Shr [<<Arg>>,<<Shift>>]
1788 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Shifted>>]
1789 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>]
1790 /// CHECK-DAG: Return [<<And>>]
1791
1792 /// CHECK-START: long Main.$noinline$intShr28And15L(int) instruction_simplifier (after)
1793 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1794 /// CHECK-DAG: <<Shift:i\d+>> IntConstant 28
1795 /// CHECK-DAG: <<Shifted:i\d+>> UShr [<<Arg>>,<<Shift>>]
1796 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Shifted>>]
1797 /// CHECK-DAG: Return [<<Long>>]
1798
1799 public static long $noinline$intShr28And15L(int value) {
1800 return (value >> 28) & 15L;
1801 }
1802
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001803 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001804 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1805 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 255
1806 /// CHECK-DAG: <<And:j\d+>> And [<<Mask>>,<<Arg>>]
1807 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<And>>]
1808 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Int>>]
1809 /// CHECK-DAG: Return [<<Byte>>]
1810
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001811 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001812 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1813 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1814 /// CHECK-DAG: Return [<<Byte>>]
1815
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001816 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001817 /// CHECK-NOT: And
1818
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001819 public static byte $noinline$longAnd0xffToByte(long value) {
Vladimir Marko8428bd32016-02-12 16:53:57 +00001820 return (byte) (value & 0xff);
1821 }
1822
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001823 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001824 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1825 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 131071
1826 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1827 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<And>>]
1828 /// CHECK-DAG: Return [<<Char>>]
1829
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001830 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001831 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1832 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1833 /// CHECK-DAG: Return [<<Char>>]
1834
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001835 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001836 /// CHECK-NOT: And
1837
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001838 public static char $noinline$intAnd0x1ffffToChar(int value) {
Vladimir Marko8428bd32016-02-12 16:53:57 +00001839 // Keeping all significant bits and one more.
1840 return (char) (value & 0x1ffff);
1841 }
1842
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001843 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001844 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1845 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1846 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1847 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1848 /// CHECK-DAG: Return [<<Short>>]
1849
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001850 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001851 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1852 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1853 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1854 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1855 /// CHECK-DAG: Return [<<Short>>]
1856
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001857 public static short $noinline$intAnd0x17fffToShort(int value) {
Vladimir Marko8428bd32016-02-12 16:53:57 +00001858 // No simplification: clearing a significant bit.
1859 return (short) (value & 0x17fff);
1860 }
1861
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001862 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (before)
Vladimir Marko625090f2016-03-14 18:00:05 +00001863 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1864 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 65535
1865 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1866 /// CHECK-DAG: <<Same:s\d+>> TypeConversion [<<And>>]
1867 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Same>>]
1868 /// CHECK-DAG: Return [<<Double>>]
1869
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001870 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (after)
Vladimir Marko625090f2016-03-14 18:00:05 +00001871 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1872 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1873 /// CHECK-DAG: Return [<<Double>>]
1874
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001875 public static double $noinline$shortAnd0xffffToShortToDouble(short value) {
Vladimir Marko625090f2016-03-14 18:00:05 +00001876 short same = (short) (value & 0xffff);
1877 return (double) same;
1878 }
1879
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001880 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001881 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1882 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1883 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Const42>>,<<Arg>>]
1884
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001885 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001886 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1887 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1888 /// CHECK-DAG: <<GE:z\d+>> GreaterThanOrEqual [<<Arg>>,<<Const42>>]
1889
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001890 public static int $noinline$intReverseCondition(int i) {
Anton Shaminbdd79352016-02-15 12:48:36 +06001891 return (42 > i) ? 13 : 54;
1892 }
1893
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001894 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001895 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1896 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1897 /// CHECK-DAG: <<CMP:i\d+>> Compare [<<Const42>>,<<Result>>]
1898
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001899 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001900 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1901 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1902 /// CHECK-DAG: <<EQ:z\d+>> Equal [<<Result>>,<<Const42>>]
1903
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001904 public static int $noinline$intReverseConditionNaN(int i) {
Anton Shaminbdd79352016-02-15 12:48:36 +06001905 return (42 != Math.sqrt(i)) ? 13 : 54;
1906 }
1907
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001908 public static int $noinline$runSmaliTest(String name, boolean input) {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001909 try {
1910 Class<?> c = Class.forName("SmaliTests");
Andreas Gampe166aaee2016-07-18 08:27:23 -07001911 Method m = c.getMethod(name, boolean.class);
David Brazdilf02c3cf2016-02-29 09:14:51 +00001912 return (Integer) m.invoke(null, input);
1913 } catch (Exception ex) {
1914 throw new Error(ex);
1915 }
1916 }
1917
Igor Murashkin42691732017-06-26 15:57:31 -07001918 public static boolean $noinline$runSmaliTestBoolean(String name, boolean input) {
Igor Murashkin42691732017-06-26 15:57:31 -07001919 try {
1920 Class<?> c = Class.forName("SmaliTests");
1921 Method m = c.getMethod(name, boolean.class);
1922 return (Boolean) m.invoke(null, input);
1923 } catch (Exception ex) {
1924 throw new Error(ex);
1925 }
1926 }
1927
1928 public static int $noinline$runSmaliTestInt(String name, int arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +01001929 try {
1930 Class<?> c = Class.forName("SmaliTests");
1931 Method m = c.getMethod(name, int.class);
1932 return (Integer) m.invoke(null, arg);
1933 } catch (Exception ex) {
1934 throw new Error(ex);
1935 }
1936 }
1937
Igor Murashkin42691732017-06-26 15:57:31 -07001938 public static long $noinline$runSmaliTestLong(String name, long arg) {
Igor Murashkin42691732017-06-26 15:57:31 -07001939 try {
1940 Class<?> c = Class.forName("SmaliTests");
1941 Method m = c.getMethod(name, long.class);
1942 return (Long) m.invoke(null, arg);
1943 } catch (Exception ex) {
1944 throw new Error(ex);
1945 }
1946 }
1947
Alexandre Rames50518442016-06-27 11:39:19 +01001948 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1949 /// CHECK: <<Value:i\d+>> ParameterValue
1950 /// CHECK: <<Shift:i\d+>> ParameterValue
1951 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1952 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1953 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<And>>]
1954 /// CHECK-DAG: Return [<<Shl>>]
1955
1956 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1957 /// CHECK: <<Value:i\d+>> ParameterValue
1958 /// CHECK: <<Shift:i\d+>> ParameterValue
1959 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<Shift>>]
1960 /// CHECK-DAG: Return [<<Shl>>]
1961
1962 public static int $noinline$intUnnecessaryShiftMasking(int value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01001963 return value << (shift & 31);
1964 }
1965
1966 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (before)
1967 /// CHECK: <<Value:j\d+>> ParameterValue
1968 /// CHECK: <<Shift:i\d+>> ParameterValue
1969 /// CHECK-DAG: <<Const63:i\d+>> IntConstant 63
1970 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const63>>]
1971 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<And>>]
1972 /// CHECK-DAG: Return [<<Shr>>]
1973
1974 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (after)
1975 /// CHECK: <<Value:j\d+>> ParameterValue
1976 /// CHECK: <<Shift:i\d+>> ParameterValue
1977 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<Shift>>]
1978 /// CHECK-DAG: Return [<<Shr>>]
1979
1980 public static long $noinline$longUnnecessaryShiftMasking(long value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01001981 return value >> (shift & 63);
1982 }
1983
1984 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (before)
1985 /// CHECK: <<Value:i\d+>> ParameterValue
1986 /// CHECK: <<Shift:i\d+>> ParameterValue
1987 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
1988 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const255>>]
1989 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<And>>]
1990 /// CHECK-DAG: Return [<<UShr>>]
1991
1992 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (after)
1993 /// CHECK: <<Value:i\d+>> ParameterValue
1994 /// CHECK: <<Shift:i\d+>> ParameterValue
1995 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<Shift>>]
1996 /// CHECK-DAG: Return [<<UShr>>]
1997
1998 public static int $noinline$intUnnecessaryWiderShiftMasking(int value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01001999 return value >>> (shift & 0xff);
2000 }
2001
2002 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (before)
2003 /// CHECK: <<Value:j\d+>> ParameterValue
2004 /// CHECK: <<Shift:i\d+>> ParameterValue
2005 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
2006 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
2007 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
2008 /// CHECK-DAG: Return [<<Shl>>]
2009
2010 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (after)
2011 /// CHECK: <<Value:j\d+>> ParameterValue
2012 /// CHECK: <<Shift:i\d+>> ParameterValue
2013 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
2014 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
2015 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
2016 /// CHECK-DAG: Return [<<Shl>>]
2017
2018 public static long $noinline$longSmallerShiftMasking(long value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01002019 return value << (shift & 3);
2020 }
2021
2022 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
2023 /// CHECK: <<Value:i\d+>> ParameterValue
2024 /// CHECK: <<Shift:i\d+>> ParameterValue
2025 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
2026 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
2027 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<And>>]
2028 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
2029 /// CHECK-DAG: Return [<<Add>>]
2030
2031 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
2032 /// CHECK: <<Value:i\d+>> ParameterValue
2033 /// CHECK: <<Shift:i\d+>> ParameterValue
2034 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
2035 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
2036 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<Shift>>]
2037 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
2038 /// CHECK-DAG: Return [<<Add>>]
2039
2040 public static int $noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01002041 int temp = shift & 31;
2042 return (value >> temp) + temp;
2043 }
2044
Vladimir Marko7033d492017-09-28 16:32:24 +01002045 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (before)
2046 /// CHECK: <<Value:i\d+>> ParameterValue
2047 /// CHECK: <<Shift:i\d+>> ParameterValue
2048 /// CHECK-DAG: <<Const32:i\d+>> IntConstant 32
2049 /// CHECK-DAG: <<Const64:i\d+>> IntConstant 64
2050 /// CHECK-DAG: <<Const96:i\d+>> IntConstant 96
2051 /// CHECK-DAG: <<Const128:i\d+>> IntConstant 128
2052 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const32>>]
2053 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const64>>]
2054 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const96>>]
2055 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const128>>]
2056 /// CHECK-DAG: <<Conv:b\d+>> TypeConversion [<<Shift>>]
2057 /// CHECK-DAG: Shl [<<Value>>,<<Or>>]
2058 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>]
2059 /// CHECK-DAG: UShr [<<Value>>,<<Add>>]
2060 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>]
2061 /// CHECK-DAG: Shr [<<Value>>,<<Conv>>]
2062
2063 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (after)
2064 /// CHECK: <<Value:i\d+>> ParameterValue
2065 /// CHECK: <<Shift:i\d+>> ParameterValue
2066 /// CHECK-DAG: Shl [<<Value>>,<<Shift>>]
2067 /// CHECK-DAG: Shr [<<Value>>,<<Shift>>]
2068 /// CHECK-DAG: UShr [<<Value>>,<<Shift>>]
2069 /// CHECK-DAG: Shl [<<Value>>,<<Shift>>]
2070 /// CHECK-DAG: Shr [<<Value>>,<<Shift>>]
2071
2072 public static int $noinline$intUnnecessaryShiftModifications(int value, int shift) {
Vladimir Marko7033d492017-09-28 16:32:24 +01002073 int c128 = 128;
2074 return (value << (shift | 32)) +
2075 (value >> (shift ^ 64)) +
2076 (value >>> (shift + 96)) +
2077 (value << (shift - c128)) + // Needs a named constant to generate Sub.
2078 (value >> ((byte) shift));
2079 }
2080
2081 /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (before)
2082 /// CHECK: <<Value:i\d+>> ParameterValue
2083 /// CHECK: <<Shift:i\d+>> ParameterValue
2084 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
2085 /// CHECK-DAG: <<Const65:i\d+>> IntConstant 65
2086 /// CHECK-DAG: <<Const97:i\d+>> IntConstant 97
2087 /// CHECK-DAG: <<Const129:i\d+>> IntConstant 129
2088 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const33>>]
2089 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const65>>]
2090 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const97>>]
2091 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const129>>]
2092 /// CHECK-DAG: Shl [<<Value>>,<<Or>>]
2093 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>]
2094 /// CHECK-DAG: UShr [<<Value>>,<<Add>>]
2095 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>]
2096
2097 /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (after)
2098 /// CHECK: <<Value:i\d+>> ParameterValue
2099 /// CHECK: <<Shift:i\d+>> ParameterValue
2100 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
2101 /// CHECK-DAG: <<Const65:i\d+>> IntConstant 65
2102 /// CHECK-DAG: <<Const97:i\d+>> IntConstant 97
2103 /// CHECK-DAG: <<Const129:i\d+>> IntConstant 129
2104 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const33>>]
2105 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const65>>]
2106 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const97>>]
2107 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const129>>]
2108 /// CHECK-DAG: Shl [<<Value>>,<<Or>>]
2109 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>]
2110 /// CHECK-DAG: UShr [<<Value>>,<<Add>>]
2111 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>]
2112
2113 public static int $noinline$intNecessaryShiftModifications(int value, int shift) {
Vladimir Marko7033d492017-09-28 16:32:24 +01002114 int c129 = 129;
2115 return (value << (shift | 33)) +
2116 (value >> (shift ^ 65)) +
2117 (value >>> (shift + 97)) +
2118 (value << (shift - c129)); // Needs a named constant to generate Sub.
2119 }
2120
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002121 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (before)
2122 /// CHECK: <<X:i\d+>> ParameterValue
2123 /// CHECK: <<Y:i\d+>> ParameterValue
2124 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2125 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<X>>]
2126 /// CHECK-DAG: Return [<<Res>>]
2127
2128 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (after)
2129 /// CHECK: <<X:i\d+>> ParameterValue
2130 /// CHECK: <<Y:i\d+>> ParameterValue
2131 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2132 /// CHECK-DAG: Return [<<Y>>]
2133
2134 public static int $noinline$intAddSubSimplifyArg1(int x, int y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002135 int sum = x + y;
2136 return sum - x;
2137 }
2138
2139 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (before)
2140 /// CHECK: <<X:i\d+>> ParameterValue
2141 /// CHECK: <<Y:i\d+>> ParameterValue
2142 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2143 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<Y>>]
2144 /// CHECK-DAG: Return [<<Res>>]
2145
2146 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (after)
2147 /// CHECK: <<X:i\d+>> ParameterValue
2148 /// CHECK: <<Y:i\d+>> ParameterValue
2149 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2150 /// CHECK-DAG: Return [<<X>>]
2151
2152 public static int $noinline$intAddSubSimplifyArg2(int x, int y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002153 int sum = x + y;
2154 return sum - y;
2155 }
2156
2157 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (before)
2158 /// CHECK: <<X:i\d+>> ParameterValue
2159 /// CHECK: <<Y:i\d+>> ParameterValue
2160 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2161 /// CHECK-DAG: <<Res:i\d+>> Add [<<Sub>>,<<Y>>]
2162 /// CHECK-DAG: Return [<<Res>>]
2163
2164 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (after)
2165 /// CHECK: <<X:i\d+>> ParameterValue
2166 /// CHECK: <<Y:i\d+>> ParameterValue
2167 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2168 /// CHECK-DAG: Return [<<X>>]
2169
2170 public static int $noinline$intSubAddSimplifyLeft(int x, int y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002171 int sub = x - y;
2172 return sub + y;
2173 }
2174
2175 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (before)
2176 /// CHECK: <<X:i\d+>> ParameterValue
2177 /// CHECK: <<Y:i\d+>> ParameterValue
2178 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2179 /// CHECK-DAG: <<Res:i\d+>> Add [<<Y>>,<<Sub>>]
2180 /// CHECK-DAG: Return [<<Res>>]
2181
2182 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (after)
2183 /// CHECK: <<X:i\d+>> ParameterValue
2184 /// CHECK: <<Y:i\d+>> ParameterValue
2185 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2186 /// CHECK-DAG: Return [<<X>>]
2187
2188 public static int $noinline$intSubAddSimplifyRight(int x, int y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002189 int sub = x - y;
2190 return y + sub;
2191 }
2192
2193 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (before)
2194 /// CHECK: <<X:f\d+>> ParameterValue
2195 /// CHECK: <<Y:f\d+>> ParameterValue
2196 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2197 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2198 /// CHECK-DAG: Return [<<Res>>]
2199
2200 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (after)
2201 /// CHECK: <<X:f\d+>> ParameterValue
2202 /// CHECK: <<Y:f\d+>> ParameterValue
2203 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2204 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2205 /// CHECK-DAG: Return [<<Res>>]
2206
2207 public static float $noinline$floatAddSubSimplifyArg1(float x, float y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002208 float sum = x + y;
2209 return sum - x;
2210 }
2211
2212 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (before)
2213 /// CHECK: <<X:f\d+>> ParameterValue
2214 /// CHECK: <<Y:f\d+>> ParameterValue
2215 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2216 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2217 /// CHECK-DAG: Return [<<Res>>]
2218
2219 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (after)
2220 /// CHECK: <<X:f\d+>> ParameterValue
2221 /// CHECK: <<Y:f\d+>> ParameterValue
2222 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2223 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2224 /// CHECK-DAG: Return [<<Res>>]
2225
2226 public static float $noinline$floatAddSubSimplifyArg2(float x, float y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002227 float sum = x + y;
2228 return sum - y;
2229 }
2230
2231 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (before)
2232 /// CHECK: <<X:f\d+>> ParameterValue
2233 /// CHECK: <<Y:f\d+>> ParameterValue
2234 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2235 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2236 /// CHECK-DAG: Return [<<Res>>]
2237
2238 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (after)
2239 /// CHECK: <<X:f\d+>> ParameterValue
2240 /// CHECK: <<Y:f\d+>> ParameterValue
2241 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2242 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2243 /// CHECK-DAG: Return [<<Res>>]
2244
2245 public static float $noinline$floatSubAddSimplifyLeft(float x, float y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002246 float sub = x - y;
2247 return sub + y;
2248 }
2249
2250 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (before)
2251 /// CHECK: <<X:f\d+>> ParameterValue
2252 /// CHECK: <<Y:f\d+>> ParameterValue
2253 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2254 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2255 /// CHECK-DAG: Return [<<Res>>]
2256
2257 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (after)
2258 /// CHECK: <<X:f\d+>> ParameterValue
2259 /// CHECK: <<Y:f\d+>> ParameterValue
2260 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2261 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2262 /// CHECK-DAG: Return [<<Res>>]
2263
2264 public static float $noinline$floatSubAddSimplifyRight(float x, float y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002265 float sub = x - y;
2266 return y + sub;
2267 }
2268
Vladimir Marko61b92282017-10-11 13:23:17 +01002269 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteField(Main) instruction_simplifier (before)
2270 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
2271 /// CHECK-DAG: <<Get:b\d+>> InstanceFieldGet
2272 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>]
2273 /// CHECK-DAG: Return [<<And>>]
2274
2275 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteField(Main) instruction_simplifier (after)
2276 /// CHECK-DAG: <<Get:a\d+>> InstanceFieldGet
2277 /// CHECK-DAG: Return [<<Get>>]
2278
2279 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteField(Main) instruction_simplifier (after)
2280 /// CHECK-NOT: And
2281 /// CHECK-NOT: TypeConversion
2282 public static int $noinline$getUint8FromInstanceByteField(Main m) {
2283 return m.instanceByteField & 0xff;
2284 }
2285
2286 /// CHECK-START: int Main.$noinline$getUint8FromStaticByteField() instruction_simplifier (before)
2287 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
2288 /// CHECK-DAG: <<Get:b\d+>> StaticFieldGet
2289 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>]
2290 /// CHECK-DAG: Return [<<And>>]
2291
2292 /// CHECK-START: int Main.$noinline$getUint8FromStaticByteField() instruction_simplifier (after)
2293 /// CHECK-DAG: <<Get:a\d+>> StaticFieldGet
2294 /// CHECK-DAG: Return [<<Get>>]
2295
2296 /// CHECK-START: int Main.$noinline$getUint8FromStaticByteField() instruction_simplifier (after)
2297 /// CHECK-NOT: And
2298 /// CHECK-NOT: TypeConversion
2299 public static int $noinline$getUint8FromStaticByteField() {
2300 return staticByteField & 0xff;
2301 }
2302
2303 /// CHECK-START: int Main.$noinline$getUint8FromByteArray(byte[]) instruction_simplifier (before)
2304 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
2305 /// CHECK-DAG: <<Get:b\d+>> ArrayGet
2306 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>]
2307 /// CHECK-DAG: Return [<<And>>]
2308
2309 /// CHECK-START: int Main.$noinline$getUint8FromByteArray(byte[]) instruction_simplifier (after)
2310 /// CHECK-DAG: <<Get:a\d+>> ArrayGet
2311 /// CHECK-DAG: Return [<<Get>>]
2312
2313 /// CHECK-START: int Main.$noinline$getUint8FromByteArray(byte[]) instruction_simplifier (after)
2314 /// CHECK-NOT: And
2315 /// CHECK-NOT: TypeConversion
2316 public static int $noinline$getUint8FromByteArray(byte[] a) {
2317 return a[0] & 0xff;
2318 }
2319
2320 /// CHECK-START: int Main.$noinline$getUint16FromInstanceShortField(Main) instruction_simplifier (before)
2321 /// CHECK-DAG: <<Cst65535:i\d+>> IntConstant 65535
2322 /// CHECK-DAG: <<Get:s\d+>> InstanceFieldGet
2323 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Cst65535>>]
2324 /// CHECK-DAG: Return [<<And>>]
2325
2326 /// CHECK-START: int Main.$noinline$getUint16FromInstanceShortField(Main) instruction_simplifier (after)
2327 /// CHECK-DAG: <<Get:c\d+>> InstanceFieldGet
2328 /// CHECK-DAG: Return [<<Get>>]
2329
2330 /// CHECK-START: int Main.$noinline$getUint16FromInstanceShortField(Main) instruction_simplifier (after)
2331 /// CHECK-NOT: And
2332 /// CHECK-NOT: TypeConversion
2333 public static int $noinline$getUint16FromInstanceShortField(Main m) {
2334 return m.instanceShortField & 0xffff;
2335 }
2336
2337 /// CHECK-START: int Main.$noinline$getUint16FromStaticShortField() instruction_simplifier (before)
2338 /// CHECK-DAG: <<Cst65535:i\d+>> IntConstant 65535
2339 /// CHECK-DAG: <<Get:s\d+>> StaticFieldGet
2340 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Cst65535>>]
2341 /// CHECK-DAG: Return [<<And>>]
2342
2343 /// CHECK-START: int Main.$noinline$getUint16FromStaticShortField() instruction_simplifier (after)
2344 /// CHECK-DAG: <<Get:c\d+>> StaticFieldGet
2345 /// CHECK-DAG: Return [<<Get>>]
2346
2347 /// CHECK-START: int Main.$noinline$getUint16FromStaticShortField() instruction_simplifier (after)
2348 /// CHECK-NOT: And
2349 /// CHECK-NOT: TypeConversion
2350 public static int $noinline$getUint16FromStaticShortField() {
2351 return staticShortField & 0xffff;
2352 }
2353
2354 /// CHECK-START: int Main.$noinline$getUint16FromShortArray(short[]) instruction_simplifier (before)
2355 /// CHECK-DAG: <<Cst65535:i\d+>> IntConstant 65535
2356 /// CHECK-DAG: <<Get:s\d+>> ArrayGet
2357 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Cst65535>>]
2358 /// CHECK-DAG: Return [<<And>>]
2359
2360 /// CHECK-START: int Main.$noinline$getUint16FromShortArray(short[]) instruction_simplifier (after)
2361 /// CHECK-DAG: <<Get:c\d+>> ArrayGet
2362 /// CHECK-DAG: Return [<<Get>>]
2363
2364 /// CHECK-START: int Main.$noinline$getUint16FromShortArray(short[]) instruction_simplifier (after)
2365 /// CHECK-NOT: And
2366 /// CHECK-NOT: TypeConversion
2367 public static int $noinline$getUint16FromShortArray(short[] a) {
2368 return a[0] & 0xffff;
2369 }
2370
2371 /// CHECK-START: int Main.$noinline$getInt16FromInstanceCharField(Main) instruction_simplifier (before)
2372 /// CHECK-DAG: <<Get:c\d+>> InstanceFieldGet
2373 /// CHECK-DAG: <<Conv:s\d+>> TypeConversion [<<Get>>]
2374 /// CHECK-DAG: Return [<<Conv>>]
2375
2376 /// CHECK-START: int Main.$noinline$getInt16FromInstanceCharField(Main) instruction_simplifier (after)
2377 /// CHECK-DAG: <<Get:s\d+>> InstanceFieldGet
2378 /// CHECK-DAG: Return [<<Get>>]
2379
2380 /// CHECK-START: int Main.$noinline$getInt16FromInstanceCharField(Main) instruction_simplifier (after)
2381 /// CHECK-NOT: And
2382 /// CHECK-NOT: TypeConversion
2383 public static int $noinline$getInt16FromInstanceCharField(Main m) {
2384 return (short) m.instanceCharField;
2385 }
2386
2387 /// CHECK-START: int Main.$noinline$getInt16FromStaticCharField() instruction_simplifier (before)
2388 /// CHECK-DAG: <<Get:c\d+>> StaticFieldGet
2389 /// CHECK-DAG: <<Conv:s\d+>> TypeConversion [<<Get>>]
2390 /// CHECK-DAG: Return [<<Conv>>]
2391
2392 /// CHECK-START: int Main.$noinline$getInt16FromStaticCharField() instruction_simplifier (after)
2393 /// CHECK-DAG: <<Get:s\d+>> StaticFieldGet
2394 /// CHECK-DAG: Return [<<Get>>]
2395
2396 /// CHECK-START: int Main.$noinline$getInt16FromStaticCharField() instruction_simplifier (after)
2397 /// CHECK-NOT: And
2398 /// CHECK-NOT: TypeConversion
2399 public static int $noinline$getInt16FromStaticCharField() {
2400 return (short) staticCharField;
2401 }
2402
2403 /// CHECK-START: int Main.$noinline$getInt16FromCharArray(char[]) instruction_simplifier (before)
2404 /// CHECK-DAG: <<Get:c\d+>> ArrayGet
2405 /// CHECK-DAG: <<Conv:s\d+>> TypeConversion [<<Get>>]
2406 /// CHECK-DAG: Return [<<Conv>>]
2407
2408 /// CHECK-START: int Main.$noinline$getInt16FromCharArray(char[]) instruction_simplifier (after)
2409 /// CHECK-DAG: <<Get:s\d+>> ArrayGet
2410 /// CHECK-DAG: Return [<<Get>>]
2411
2412 /// CHECK-START: int Main.$noinline$getInt16FromCharArray(char[]) instruction_simplifier (after)
2413 /// CHECK-NOT: And
2414 /// CHECK-NOT: TypeConversion
2415 public static int $noinline$getInt16FromCharArray(char[] a) {
2416 return (short) a[0];
2417 }
2418
2419 /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier (before)
2420 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
2421 /// CHECK-DAG: <<Get:b\d+>> StaticFieldGet
2422 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>]
2423 /// CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect [<<And>>{{(,[ij]\d+)?}}]
2424 /// CHECK-DAG: Return [<<Invoke>>]
2425
2426 /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier (after)
2427 /// CHECK-DAG: <<Get:a\d+>> StaticFieldGet
2428 /// CHECK-DAG: <<Invoke:i\d+>> InvokeStaticOrDirect [<<Get>>{{(,[ij]\d+)?}}]
2429 /// CHECK-DAG: Return [<<Invoke>>]
2430
2431 /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier$after_inlining (before)
2432 /// CHECK-DAG: <<Get:a\d+>> StaticFieldGet
2433 /// CHECK-DAG: <<Conv:b\d+>> TypeConversion [<<Get>>]
2434 /// CHECK-DAG: Return [<<Conv>>]
2435
2436 /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier$after_inlining (after)
2437 /// CHECK-DAG: <<Get:b\d+>> StaticFieldGet
2438 /// CHECK-DAG: Return [<<Get>>]
2439 public static int $noinline$byteToUint8AndBack() {
2440 return $inline$toByte(staticByteField & 0xff);
2441 }
2442
2443 public static int $inline$toByte(int value) {
2444 return (byte) value;
2445 }
2446
2447 /// CHECK-START: int Main.$noinline$getStaticCharFieldAnd0xff() instruction_simplifier (before)
2448 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
2449 /// CHECK-DAG: <<Get:c\d+>> StaticFieldGet
2450 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>]
2451 /// CHECK-DAG: Return [<<And>>]
2452
2453 /// CHECK-START: int Main.$noinline$getStaticCharFieldAnd0xff() instruction_simplifier (after)
2454 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
2455 /// CHECK-DAG: <<Get:c\d+>> StaticFieldGet
2456 /// CHECK-DAG: <<Cnv:a\d+>> TypeConversion [<<Get>>]
2457 /// CHECK-DAG: Return [<<Cnv>>]
2458
2459 /// CHECK-START: int Main.$noinline$getStaticCharFieldAnd0xff() instruction_simplifier (after)
2460 /// CHECK-NOT: {{a\d+}} StaticFieldGet
2461 public static int $noinline$getStaticCharFieldAnd0xff() {
2462 return staticCharField & 0xff;
2463 }
2464
2465 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main) instruction_simplifier (before)
2466 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
2467 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
2468 /// CHECK-DAG: <<Get:b\d+>> InstanceFieldGet
2469 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Const255>>]
2470 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Get>>,<<Const8>>]
2471 /// CHECK-DAG: <<Add:i\d+>> Add [<<And>>,<<Shl>>]
2472 /// CHECK-DAG: Return [<<Add>>]
2473
2474 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main) instruction_simplifier (after)
2475 /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8
2476 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
2477 /// CHECK-DAG: <<Get:b\d+>> InstanceFieldGet
2478 /// CHECK-DAG: <<Cnv:a\d+>> TypeConversion [<<Get>>]
2479 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Get>>,<<Const8>>]
2480 /// CHECK-DAG: <<Add:i\d+>> Add [<<Cnv>>,<<Shl>>]
2481 /// CHECK-DAG: Return [<<Add>>]
2482
2483 /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main) instruction_simplifier (after)
2484 /// CHECK-NOT: {{a\d+}} InstanceFieldGet
2485 public static int $noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main m) {
2486 byte b = m.instanceByteField;
2487 int v1 = b & 0xff;
2488 int v2 = (b << 8);
2489 return v1 + v2;
2490 }
2491
2492 /// CHECK-START: int Main.$noinline$intAnd0xffToChar(int) instruction_simplifier (before)
2493 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
2494 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
2495 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const255>>]
2496 /// CHECK-DAG: <<Conv:c\d+>> TypeConversion [<<And>>]
2497 /// CHECK-DAG: Return [<<Conv>>]
2498
2499 /// CHECK-START: int Main.$noinline$intAnd0xffToChar(int) instruction_simplifier (after)
2500 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
2501 /// CHECK-DAG: <<Conv:a\d+>> TypeConversion [<<Arg>>]
2502 /// CHECK-DAG: Return [<<Conv>>]
2503 public static int $noinline$intAnd0xffToChar(int value) {
2504 return (char) (value & 0xff);
2505 }
2506
2507 /// CHECK-START: int Main.$noinline$intAnd0x1ffToChar(int) instruction_simplifier (before)
2508 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
2509 /// CHECK-DAG: <<Const511:i\d+>> IntConstant 511
2510 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const511>>]
2511 /// CHECK-DAG: <<Conv:c\d+>> TypeConversion [<<And>>]
2512 /// CHECK-DAG: Return [<<Conv>>]
2513
2514 // TODO: Simplify this. Unlike the $noinline$intAnd0xffToChar(), the TypeConversion
2515 // to `char` is not eliminated despite the result of the And being within the `char` range.
2516
2517 // CHECK-START: int Main.$noinline$intAnd0x1ffToChar(int) instruction_simplifier (after)
2518 // CHECK-DAG: <<Arg:i\d+>> ParameterValue
2519 // CHECK-DAG: <<Const511:i\d+>> IntConstant 511
2520 // CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const511>>]
2521 // CHECK-DAG: Return [<<And>>]
2522 public static int $noinline$intAnd0x1ffToChar(int value) {
2523 return (char) (value & 0x1ff);
2524 }
2525
2526 /// CHECK-START: int Main.$noinline$getInstanceCharFieldAnd0x1ffff(Main) instruction_simplifier (before)
2527 /// CHECK-DAG: <<Cst1ffff:i\d+>> IntConstant 131071
2528 /// CHECK-DAG: <<Get:c\d+>> InstanceFieldGet
2529 /// CHECK-DAG: <<And:i\d+>> And [<<Get>>,<<Cst1ffff>>]
2530 /// CHECK-DAG: Return [<<And>>]
2531
2532 // TODO: Simplify this. The And is useless.
2533
2534 // CHECK-START: int Main.$noinline$getInstanceCharFieldAnd0x1ffff(Main) instruction_simplifier (after)
2535 // CHECK-DAG: <<Get:c\d+>> InstanceFieldGet
2536 // CHECK-DAG: Return [<<Get>>]
2537 public static int $noinline$getInstanceCharFieldAnd0x1ffff(Main m) {
2538 return m.instanceCharField & 0x1ffff;
2539 }
2540
2541 public static void main(String[] args) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002542 int arg = 123456;
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002543 float floatArg = 123456.125f;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002544
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002545 assertLongEquals(arg, $noinline$Add0(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002546 assertIntEquals(5, $noinline$AddAddSubAddConst(1));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002547 assertIntEquals(arg, $noinline$AndAllOnes(arg));
2548 assertLongEquals(arg, $noinline$Div1(arg));
2549 assertIntEquals(-arg, $noinline$DivN1(arg));
2550 assertLongEquals(arg, $noinline$Mul1(arg));
2551 assertIntEquals(-arg, $noinline$MulN1(arg));
2552 assertLongEquals((128 * arg), $noinline$MulPowerOfTwo128(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002553 assertLongEquals(2640, $noinline$MulMulMulConst(2));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002554 assertIntEquals(arg, $noinline$Or0(arg));
2555 assertLongEquals(arg, $noinline$OrSame(arg));
2556 assertIntEquals(arg, $noinline$Shl0(arg));
2557 assertLongEquals(arg, $noinline$Shr0(arg));
2558 assertLongEquals(arg, $noinline$Shr64(arg));
2559 assertLongEquals(arg, $noinline$Sub0(arg));
2560 assertIntEquals(-arg, $noinline$SubAliasNeg(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002561 assertIntEquals(9, $noinline$SubAddConst1(2));
2562 assertIntEquals(-2, $noinline$SubAddConst2(3));
2563 assertLongEquals(3, $noinline$SubSubConst(4));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002564 assertLongEquals(arg, $noinline$UShr0(arg));
2565 assertIntEquals(arg, $noinline$Xor0(arg));
2566 assertIntEquals(~arg, $noinline$XorAllOnes(arg));
2567 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs1(arg, arg + 1));
2568 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs2(arg, arg + 1));
2569 assertLongEquals(-(2 * arg + 1), $noinline$AddNegs3(arg, arg + 1));
2570 assertLongEquals(1, $noinline$AddNeg1(arg, arg + 1));
2571 assertLongEquals(-1, $noinline$AddNeg2(arg, arg + 1));
2572 assertLongEquals(arg, $noinline$NegNeg1(arg));
2573 assertIntEquals(0, $noinline$NegNeg2(arg));
2574 assertLongEquals(arg, $noinline$NegNeg3(arg));
2575 assertIntEquals(1, $noinline$NegSub1(arg, arg + 1));
2576 assertIntEquals(1, $noinline$NegSub2(arg, arg + 1));
2577 assertLongEquals(arg, $noinline$NotNot1(arg));
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002578 assertLongEquals(arg, $noinline$runSmaliTestLong("$noinline$NotNot1", arg));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002579 assertIntEquals(-1, $noinline$NotNot2(arg));
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002580 assertIntEquals(-1, $noinline$runSmaliTestInt("$noinline$NotNot2", arg));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002581 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg1(arg, arg + 1));
2582 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg2(arg, arg + 1));
2583 assertLongEquals(-(2 * arg + 1), $noinline$SubNeg3(arg, arg + 1));
2584 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2585 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2586 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2587 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2588 assertBooleanEquals(true, $noinline$NotNotBool(true));
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002589 assertBooleanEquals(true, $noinline$runSmaliTestBoolean("$noinline$NotNotBool", true));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002590 assertBooleanEquals(false, $noinline$NotNotBool(false));
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002591 assertBooleanEquals(false, $noinline$runSmaliTestBoolean("$noinline$NotNotBool", false));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002592 assertFloatEquals(50.0f, $noinline$Div2(100.0f));
2593 assertDoubleEquals(75.0, $noinline$Div2(150.0));
2594 assertFloatEquals(-400.0f, $noinline$DivMP25(100.0f));
2595 assertDoubleEquals(-600.0, $noinline$DivMP25(150.0));
2596 assertIntEquals(0xc, $noinline$UShr28And15(0xc1234567));
2597 assertLongEquals(0xcL, $noinline$UShr60And15(0xc123456787654321L));
2598 assertIntEquals(0x4, $noinline$UShr28And7(0xc1234567));
2599 assertLongEquals(0x4L, $noinline$UShr60And7(0xc123456787654321L));
2600 assertIntEquals(0xc1, $noinline$Shr24And255(0xc1234567));
Vladimir Marko61b92282017-10-11 13:23:17 +01002601 assertIntEquals(0x60, $noinline$Shr25And127(0xc1234567));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002602 assertLongEquals(0xc1L, $noinline$Shr56And255(0xc123456787654321L));
Vladimir Marko61b92282017-10-11 13:23:17 +01002603 assertLongEquals(0x60L, $noinline$Shr57And127(0xc123456787654321L));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002604 assertIntEquals(0x41, $noinline$Shr24And127(0xc1234567));
2605 assertLongEquals(0x41L, $noinline$Shr56And127(0xc123456787654321L));
2606 assertIntEquals(0, $noinline$mulPow2Plus1(0));
2607 assertIntEquals(9, $noinline$mulPow2Plus1(1));
2608 assertIntEquals(18, $noinline$mulPow2Plus1(2));
2609 assertIntEquals(900, $noinline$mulPow2Plus1(100));
2610 assertIntEquals(111105, $noinline$mulPow2Plus1(12345));
2611 assertLongEquals(0, $noinline$mulPow2Minus1(0));
2612 assertLongEquals(31, $noinline$mulPow2Minus1(1));
2613 assertLongEquals(62, $noinline$mulPow2Minus1(2));
2614 assertLongEquals(3100, $noinline$mulPow2Minus1(100));
2615 assertLongEquals(382695, $noinline$mulPow2Minus1(12345));
Mark Mendellf6529172015-11-17 11:16:56 -05002616
2617 booleanField = false;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002618 assertIntEquals($noinline$booleanFieldNotEqualOne(), 54);
2619 assertIntEquals($noinline$booleanFieldEqualZero(), 54);
Mark Mendellf6529172015-11-17 11:16:56 -05002620 booleanField = true;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002621 assertIntEquals(13, $noinline$booleanFieldNotEqualOne());
2622 assertIntEquals(13, $noinline$booleanFieldEqualZero());
2623 assertIntEquals(54, $noinline$intConditionNotEqualOne(6));
2624 assertIntEquals(13, $noinline$intConditionNotEqualOne(43));
2625 assertIntEquals(54, $noinline$intConditionEqualZero(6));
2626 assertIntEquals(13, $noinline$intConditionEqualZero(43));
2627 assertIntEquals(54, $noinline$floatConditionNotEqualOne(6.0f));
2628 assertIntEquals(13, $noinline$floatConditionNotEqualOne(43.0f));
2629 assertIntEquals(54, $noinline$doubleConditionEqualZero(6.0));
2630 assertIntEquals(13, $noinline$doubleConditionEqualZero(43.0));
Vladimir Markob52bbde2016-02-12 12:06:05 +00002631
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002632 assertIntEquals(1234567, $noinline$intToDoubleToInt(1234567));
2633 assertIntEquals(Integer.MIN_VALUE, $noinline$intToDoubleToInt(Integer.MIN_VALUE));
2634 assertIntEquals(Integer.MAX_VALUE, $noinline$intToDoubleToInt(Integer.MAX_VALUE));
2635 assertStringEquals("d=7654321.0, i=7654321", $noinline$intToDoubleToIntPrint(7654321));
2636 assertIntEquals(12, $noinline$byteToDoubleToInt((byte) 12));
2637 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToInt(Byte.MIN_VALUE));
2638 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToInt(Byte.MAX_VALUE));
2639 assertIntEquals(11, $noinline$floatToDoubleToInt(11.3f));
2640 assertStringEquals("d=12.25, i=12", $noinline$floatToDoubleToIntPrint(12.25f));
2641 assertIntEquals(123, $noinline$byteToDoubleToShort((byte) 123));
2642 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToShort(Byte.MIN_VALUE));
2643 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToShort(Byte.MAX_VALUE));
2644 assertIntEquals(1234, $noinline$charToDoubleToShort((char) 1234));
2645 assertIntEquals(Character.MIN_VALUE, $noinline$charToDoubleToShort(Character.MIN_VALUE));
2646 assertIntEquals(/* sign-extended */ -1, $noinline$charToDoubleToShort(Character.MAX_VALUE));
2647 assertIntEquals(12345, $noinline$floatToIntToShort(12345.75f));
2648 assertIntEquals(Short.MAX_VALUE, $noinline$floatToIntToShort((float)(Short.MIN_VALUE - 1)));
2649 assertIntEquals(Short.MIN_VALUE, $noinline$floatToIntToShort((float)(Short.MAX_VALUE + 1)));
2650 assertIntEquals(-54321, $noinline$intToFloatToInt(-54321));
2651 assertDoubleEquals((double) 0x12345678, $noinline$longToIntToDouble(0x1234567812345678L));
2652 assertDoubleEquals(0.0, $noinline$longToIntToDouble(Long.MIN_VALUE));
2653 assertDoubleEquals(-1.0, $noinline$longToIntToDouble(Long.MAX_VALUE));
2654 assertLongEquals(0x0000000012345678L, $noinline$longToIntToLong(0x1234567812345678L));
2655 assertLongEquals(0xffffffff87654321L, $noinline$longToIntToLong(0x1234567887654321L));
2656 assertLongEquals(0L, $noinline$longToIntToLong(Long.MIN_VALUE));
2657 assertLongEquals(-1L, $noinline$longToIntToLong(Long.MAX_VALUE));
2658 assertIntEquals((short) -5678, $noinline$shortToCharToShort((short) -5678));
2659 assertIntEquals(Short.MIN_VALUE, $noinline$shortToCharToShort(Short.MIN_VALUE));
2660 assertIntEquals(Short.MAX_VALUE, $noinline$shortToCharToShort(Short.MAX_VALUE));
2661 assertIntEquals(5678, $noinline$shortToLongToInt((short) 5678));
2662 assertIntEquals(Short.MIN_VALUE, $noinline$shortToLongToInt(Short.MIN_VALUE));
2663 assertIntEquals(Short.MAX_VALUE, $noinline$shortToLongToInt(Short.MAX_VALUE));
2664 assertIntEquals(0x34, $noinline$shortToCharToByte((short) 0x1234));
2665 assertIntEquals(-0x10, $noinline$shortToCharToByte((short) 0x12f0));
2666 assertIntEquals(0, $noinline$shortToCharToByte(Short.MIN_VALUE));
2667 assertIntEquals(-1, $noinline$shortToCharToByte(Short.MAX_VALUE));
2668 assertStringEquals("c=1025, b=1", $noinline$shortToCharToBytePrint((short) 1025));
2669 assertStringEquals("c=1023, b=-1", $noinline$shortToCharToBytePrint((short) 1023));
2670 assertStringEquals("c=65535, b=-1", $noinline$shortToCharToBytePrint((short) -1));
Vladimir Marko8428bd32016-02-12 16:53:57 +00002671
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002672 assertLongEquals(0x55411410L, $noinline$intAndSmallLongConstant(0x55555555));
2673 assertLongEquals(0xffffffffaa028aa2L, $noinline$intAndSmallLongConstant(0xaaaaaaaa));
2674 assertLongEquals(0x44101440L, $noinline$intAndLargeLongConstant(0x55555555));
2675 assertLongEquals(0x208a002aaL, $noinline$intAndLargeLongConstant(0xaaaaaaaa));
2676 assertLongEquals(7L, $noinline$intShr28And15L(0x76543210));
2677
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002678 assertIntEquals(0x21, $noinline$longAnd0xffToByte(0x1234432112344321L));
2679 assertIntEquals(0, $noinline$longAnd0xffToByte(Long.MIN_VALUE));
2680 assertIntEquals(-1, $noinline$longAnd0xffToByte(Long.MAX_VALUE));
2681 assertIntEquals(0x1234, $noinline$intAnd0x1ffffToChar(0x43211234));
2682 assertIntEquals(0, $noinline$intAnd0x1ffffToChar(Integer.MIN_VALUE));
2683 assertIntEquals(Character.MAX_VALUE, $noinline$intAnd0x1ffffToChar(Integer.MAX_VALUE));
2684 assertIntEquals(0x4321, $noinline$intAnd0x17fffToShort(0x87654321));
2685 assertIntEquals(0x0888, $noinline$intAnd0x17fffToShort(0x88888888));
2686 assertIntEquals(0, $noinline$intAnd0x17fffToShort(Integer.MIN_VALUE));
2687 assertIntEquals(Short.MAX_VALUE, $noinline$intAnd0x17fffToShort(Integer.MAX_VALUE));
Vladimir Marko625090f2016-03-14 18:00:05 +00002688
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002689 assertDoubleEquals(0.0, $noinline$shortAnd0xffffToShortToDouble((short) 0));
2690 assertDoubleEquals(1.0, $noinline$shortAnd0xffffToShortToDouble((short) 1));
2691 assertDoubleEquals(-2.0, $noinline$shortAnd0xffffToShortToDouble((short) -2));
2692 assertDoubleEquals(12345.0, $noinline$shortAnd0xffffToShortToDouble((short) 12345));
2693 assertDoubleEquals((double)Short.MAX_VALUE,
2694 $noinline$shortAnd0xffffToShortToDouble(Short.MAX_VALUE));
2695 assertDoubleEquals((double)Short.MIN_VALUE,
2696 $noinline$shortAnd0xffffToShortToDouble(Short.MIN_VALUE));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002697
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002698 assertIntEquals(13, $noinline$intReverseCondition(41));
2699 assertIntEquals(13, $noinline$intReverseConditionNaN(-5));
Anton Shaminbdd79352016-02-15 12:48:36 +06002700
David Brazdilf02c3cf2016-02-29 09:14:51 +00002701 for (String condition : new String[] { "Equal", "NotEqual" }) {
2702 for (String constant : new String[] { "True", "False" }) {
2703 for (String side : new String[] { "Rhs", "Lhs" }) {
2704 String name = condition + constant + side;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002705 assertIntEquals(5, $noinline$runSmaliTest(name, true));
2706 assertIntEquals(3, $noinline$runSmaliTest(name, false));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002707 }
2708 }
2709 }
Alexandre Rames50518442016-06-27 11:39:19 +01002710
Igor Murashkin42691732017-06-26 15:57:31 -07002711 assertIntEquals(0, $noinline$runSmaliTestInt("AddSubConst", 1));
2712 assertIntEquals(3, $noinline$runSmaliTestInt("SubAddConst", 2));
2713 assertIntEquals(-16, $noinline$runSmaliTestInt("SubSubConst1", 3));
2714 assertIntEquals(-5, $noinline$runSmaliTestInt("SubSubConst2", 4));
2715 assertIntEquals(26, $noinline$runSmaliTestInt("SubSubConst3", 5));
Alexandre Rames50518442016-06-27 11:39:19 +01002716 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3));
2717 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3 + 32));
Vladimir Marko7033d492017-09-28 16:32:24 +01002718 assertLongEquals(0xffffffffffffeaf3L,
2719 $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50));
2720 assertLongEquals(0xffffffffffffeaf3L,
2721 $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50 + 64));
Alexandre Rames50518442016-06-27 11:39:19 +01002722 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10));
2723 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10 + 128));
Vladimir Marko7033d492017-09-28 16:32:24 +01002724 assertLongEquals(0xaf37bc048d159e24L,
2725 $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2));
2726 assertLongEquals(0xaf37bc048d159e24L,
2727 $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2 + 256));
Alexandre Rames50518442016-06-27 11:39:19 +01002728 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13));
2729 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13 + 512));
Vladimir Marko7033d492017-09-28 16:32:24 +01002730 assertIntEquals(0x5f49eb48, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 2));
2731 assertIntEquals(0xbd4c29b0, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 3));
2732 assertIntEquals(0xc0fed1ca, $noinline$intNecessaryShiftModifications(0xabcdef01, 2));
2733 assertIntEquals(0x03578ebc, $noinline$intNecessaryShiftModifications(0xabcdef01, 3));
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002734
2735 assertIntEquals(654321, $noinline$intAddSubSimplifyArg1(arg, 654321));
2736 assertIntEquals(arg, $noinline$intAddSubSimplifyArg2(arg, 654321));
2737 assertIntEquals(arg, $noinline$intSubAddSimplifyLeft(arg, 654321));
2738 assertIntEquals(arg, $noinline$intSubAddSimplifyRight(arg, 654321));
2739 assertFloatEquals(654321.125f, $noinline$floatAddSubSimplifyArg1(floatArg, 654321.125f));
2740 assertFloatEquals(floatArg, $noinline$floatAddSubSimplifyArg2(floatArg, 654321.125f));
2741 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyLeft(floatArg, 654321.125f));
2742 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyRight(floatArg, 654321.125f));
Vladimir Marko61b92282017-10-11 13:23:17 +01002743
2744 Main m = new Main();
2745 m.instanceByteField = -1;
2746 assertIntEquals(0xff, $noinline$getUint8FromInstanceByteField(m));
2747 staticByteField = -2;
2748 assertIntEquals(0xfe, $noinline$getUint8FromStaticByteField());
2749 assertIntEquals(0xfd, $noinline$getUint8FromByteArray(new byte[] { -3 }));
2750 m.instanceShortField = -4;
2751 assertIntEquals(0xfffc, $noinline$getUint16FromInstanceShortField(m));
2752 staticShortField = -5;
2753 assertIntEquals(0xfffb, $noinline$getUint16FromStaticShortField());
2754 assertIntEquals(0xfffa, $noinline$getUint16FromShortArray(new short[] { -6 }));
2755 m.instanceCharField = 0xfff9;
2756 assertIntEquals(-7, $noinline$getInt16FromInstanceCharField(m));
2757 staticCharField = 0xfff8;
2758 assertIntEquals(-8, $noinline$getInt16FromStaticCharField());
2759 assertIntEquals(-9, $noinline$getInt16FromCharArray(new char[] { 0xfff7 }));
2760
2761 staticCharField = 0xfff6;
2762 assertIntEquals(0xf6, $noinline$getStaticCharFieldAnd0xff());
2763
2764 staticByteField = -11;
2765 assertIntEquals(-11, $noinline$byteToUint8AndBack());
2766
2767 m.instanceByteField = -12;
2768 assertIntEquals(0xfffff4f4, $noinline$getUint8FromInstanceByteFieldWithAnotherUse(m));
2769
2770 assertIntEquals(0x21, $noinline$intAnd0xffToChar(0x87654321));
2771 assertIntEquals(0x121, $noinline$intAnd0x1ffToChar(0x87654321));
2772
2773 m.instanceCharField = 'x';
2774 assertIntEquals('x', $noinline$getInstanceCharFieldAnd0x1ffff(m));
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002775 }
Mark Mendellf6529172015-11-17 11:16:56 -05002776
David Brazdilf02c3cf2016-02-29 09:14:51 +00002777 private static boolean $inline$true() { return true; }
2778 private static boolean $inline$false() { return false; }
2779
Mark Mendellf6529172015-11-17 11:16:56 -05002780 public static boolean booleanField;
Vladimir Marko61b92282017-10-11 13:23:17 +01002781
2782 public static byte staticByteField;
2783 public static char staticCharField;
2784 public static short staticShortField;
2785
2786 public byte instanceByteField;
2787 public char instanceCharField;
2788 public short instanceShortField;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002789}