blob: f36c261a4eb89d569e50cbe3a3cc6544d34ca606 [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
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010021 static boolean doThrow = false;
22
David Brazdil0d13fee2015-04-17 14:52:19 +010023 public static void assertBooleanEquals(boolean expected, boolean result) {
24 if (expected != result) {
25 throw new Error("Expected: " + expected + ", found: " + result);
26 }
27 }
28
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000029 public static void assertIntEquals(int expected, int result) {
30 if (expected != result) {
31 throw new Error("Expected: " + expected + ", found: " + result);
32 }
33 }
34
35 public static void assertLongEquals(long expected, long result) {
36 if (expected != result) {
37 throw new Error("Expected: " + expected + ", found: " + result);
38 }
39 }
40
Nicolas Geoffray0d221842015-04-27 08:53:46 +000041 public static void assertFloatEquals(float expected, float result) {
42 if (expected != result) {
43 throw new Error("Expected: " + expected + ", found: " + result);
44 }
45 }
46
47 public static void assertDoubleEquals(double expected, double result) {
48 if (expected != result) {
49 throw new Error("Expected: " + expected + ", found: " + result);
50 }
51 }
52
Vladimir Markob52bbde2016-02-12 12:06:05 +000053 public static void assertStringEquals(String expected, String result) {
54 if (expected == null ? result != null : !expected.equals(result)) {
55 throw new Error("Expected: " + expected + ", found: " + result);
56 }
57 }
58
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000059 /**
60 * Tiny programs exercising optimizations of arithmetic identities.
61 */
62
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010063 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +010064 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
65 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
66 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const0>>,<<Arg>>]
67 /// CHECK-DAG: Return [<<Add>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000068
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010069 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +010070 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
71 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +010072
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010073 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +010074 /// CHECK-NOT: Add
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000075
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010076 public static long $noinline$Add0(long arg) {
77 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000078 return 0 + arg;
79 }
80
Anton Kirilove14dc862016-05-13 17:56:15 +010081 /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (before)
82 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
83 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
84 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
85 /// CHECK-DAG: <<ConstM3:i\d+>> IntConstant -3
86 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
87 /// CHECK-DAG: <<Add1:i\d+>> Add [<<ArgValue>>,<<Const1>>]
88 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Add1>>,<<Const2>>]
89 /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add2>>,<<ConstM3>>]
90 /// CHECK-DAG: <<Add4:i\d+>> Add [<<Add3>>,<<Const4>>]
91 /// CHECK-DAG: Return [<<Add4>>]
92
93 /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (after)
94 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
95 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
96 /// CHECK-DAG: <<Add:i\d+>> Add [<<ArgValue>>,<<Const4>>]
97 /// CHECK-DAG: Return [<<Add>>]
98
99 public static int $noinline$AddAddSubAddConst(int arg) {
100 if (doThrow) { throw new Error(); }
101 return arg + 1 + 2 - 3 + 4;
102 }
103
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100104 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100105 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
106 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
107 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<ConstF>>]
108 /// CHECK-DAG: Return [<<And>>]
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-DAG: <<Arg:i\d+>> ParameterValue
112 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000113
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100114 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100115 /// CHECK-NOT: And
Alexandre Rames74417692015-04-09 15:21:41 +0100116
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100117 public static int $noinline$AndAllOnes(int arg) {
118 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000119 return arg & -1;
120 }
121
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100122 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100123 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
124 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
125 /// CHECK-DAG: <<Const15:i\d+>> IntConstant 15
126 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
127 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const15>>]
128 /// CHECK-DAG: Return [<<And>>]
129
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100130 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100131 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
132 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
133 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
134 /// CHECK-DAG: Return [<<UShr>>]
135
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100136 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100137 /// CHECK-NOT: And
138
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100139 public static int $noinline$UShr28And15(int arg) {
140 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100141 return (arg >>> 28) & 15;
142 }
143
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100144 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100145 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
146 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
147 /// CHECK-DAG: <<Const15:j\d+>> LongConstant 15
148 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
149 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const15>>]
150 /// CHECK-DAG: Return [<<And>>]
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-DAG: <<Arg:j\d+>> ParameterValue
154 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
155 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
156 /// CHECK-DAG: Return [<<UShr>>]
157
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100158 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100159 /// CHECK-NOT: And
160
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100161 public static long $noinline$UShr60And15(long arg) {
162 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100163 return (arg >>> 60) & 15;
164 }
165
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100166 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100167 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
168 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
169 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
170 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
171 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
172 /// CHECK-DAG: Return [<<And>>]
173
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100174 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100175 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
176 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
177 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
178 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
179 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
180 /// CHECK-DAG: Return [<<And>>]
181
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100182 public static int $noinline$UShr28And7(int arg) {
183 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100184 return (arg >>> 28) & 7;
185 }
186
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100187 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (before)
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 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100196 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
197 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
198 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
199 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
200 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
201 /// CHECK-DAG: Return [<<And>>]
202
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100203 public static long $noinline$UShr60And7(long arg) {
204 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100205 return (arg >>> 60) & 7;
206 }
207
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100208 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100209 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
210 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
211 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
212 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
213 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const255>>]
214 /// CHECK-DAG: Return [<<And>>]
215
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100216 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100217 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
218 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
219 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const24>>]
220 /// CHECK-DAG: Return [<<UShr>>]
221
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100222 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100223 /// CHECK-NOT: Shr
224 /// CHECK-NOT: And
225
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100226 public static int $noinline$Shr24And255(int arg) {
227 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100228 return (arg >> 24) & 255;
229 }
230
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100231 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100232 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
233 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
234 /// CHECK-DAG: <<Const255:j\d+>> LongConstant 255
235 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
236 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const255>>]
237 /// CHECK-DAG: Return [<<And>>]
238
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100239 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100240 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
241 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
242 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const56>>]
243 /// CHECK-DAG: Return [<<UShr>>]
244
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100245 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100246 /// CHECK-NOT: Shr
247 /// CHECK-NOT: And
248
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100249 public static long $noinline$Shr56And255(long arg) {
250 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100251 return (arg >> 56) & 255;
252 }
253
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100254 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100255 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
256 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
257 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
258 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
259 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
260 /// CHECK-DAG: Return [<<And>>]
261
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100262 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100263 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
264 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
265 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
266 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
267 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
268 /// CHECK-DAG: Return [<<And>>]
269
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100270 public static int $noinline$Shr24And127(int arg) {
271 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100272 return (arg >> 24) & 127;
273 }
274
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100275 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100276 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
277 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
278 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
279 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
280 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
281 /// CHECK-DAG: Return [<<And>>]
282
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100283 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100284 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
285 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
286 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
287 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
288 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
289 /// CHECK-DAG: Return [<<And>>]
290
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100291 public static long $noinline$Shr56And127(long arg) {
292 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100293 return (arg >> 56) & 127;
294 }
295
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100296 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100297 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
298 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
299 /// CHECK-DAG: <<Div:j\d+>> Div [<<Arg>>,<<Const1>>]
300 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000301
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100302 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100303 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
304 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000305
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100306 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100307 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100308
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100309 public static long $noinline$Div1(long arg) {
310 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000311 return arg / 1;
312 }
313
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100314 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100315 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
316 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
317 /// CHECK-DAG: <<Div:i\d+>> Div [<<Arg>>,<<ConstN1>>]
318 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000319
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100320 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100321 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
322 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
323 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000324
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100325 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100326 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100327
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100328 public static int $noinline$DivN1(int arg) {
329 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000330 return arg / -1;
331 }
332
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100333 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100334 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
335 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
David Brazdil57e863c2016-01-11 10:27:13 +0000336 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const1>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100337 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000338
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100339 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100340 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
341 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000342
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100343 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100344 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100345
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100346 public static long $noinline$Mul1(long arg) {
347 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000348 return arg * 1;
349 }
350
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100351 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100352 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
353 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
354 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Arg>>,<<ConstN1>>]
355 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000356
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100357 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100358 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
359 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
360 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000361
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100362 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100363 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100364
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100365 public static int $noinline$MulN1(int arg) {
366 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000367 return arg * -1;
368 }
369
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100370 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100371 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
372 /// CHECK-DAG: <<Const128:j\d+>> LongConstant 128
David Brazdil57e863c2016-01-11 10:27:13 +0000373 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const128>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100374 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000375
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100376 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100377 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
378 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
379 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Arg>>,<<Const7>>]
380 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000381
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100382 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100383 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100384
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100385 public static long $noinline$MulPowerOfTwo128(long arg) {
386 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000387 return arg * 128;
388 }
389
Anton Kirilove14dc862016-05-13 17:56:15 +0100390 /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (before)
391 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
392 /// CHECK-DAG: <<Const10:j\d+>> LongConstant 10
393 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11
394 /// CHECK-DAG: <<Const12:j\d+>> LongConstant 12
395 /// CHECK-DAG: <<Mul1:j\d+>> Mul [<<Const10>>,<<ArgValue>>]
396 /// CHECK-DAG: <<Mul2:j\d+>> Mul [<<Mul1>>,<<Const11>>]
397 /// CHECK-DAG: <<Mul3:j\d+>> Mul [<<Mul2>>,<<Const12>>]
398 /// CHECK-DAG: Return [<<Mul3>>]
399
400 /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (after)
401 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
402 /// CHECK-DAG: <<Const1320:j\d+>> LongConstant 1320
403 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<ArgValue>>,<<Const1320>>]
404 /// CHECK-DAG: Return [<<Mul>>]
405
406 public static long $noinline$MulMulMulConst(long arg) {
407 if (doThrow) { throw new Error(); }
408 return 10 * arg * 11 * 12;
409 }
410
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100411 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100412 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
413 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
414 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<Const0>>]
415 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000416
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100417 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100418 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
419 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000420
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100421 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100422 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100423
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100424 public static int $noinline$Or0(int arg) {
425 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000426 return arg | 0;
427 }
428
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100429 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100430 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
431 /// CHECK-DAG: <<Or:j\d+>> Or [<<Arg>>,<<Arg>>]
432 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000433
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100434 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100435 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
436 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000437
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100438 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100439 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100440
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100441 public static long $noinline$OrSame(long arg) {
442 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000443 return arg | arg;
444 }
445
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100446 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100447 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
448 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
449 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Arg>>,<<Const0>>]
450 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000451
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100452 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100453 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
454 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000455
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100456 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100457 /// CHECK-NOT: Shl
Alexandre Rames74417692015-04-09 15:21:41 +0100458
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100459 public static int $noinline$Shl0(int arg) {
460 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000461 return arg << 0;
462 }
463
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100464 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100465 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
466 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
467 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const0>>]
468 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000469
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100470 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100471 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
472 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000473
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100474 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100475 /// CHECK-NOT: Shr
Alexandre Rames74417692015-04-09 15:21:41 +0100476
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100477 public static long $noinline$Shr0(long arg) {
478 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000479 return arg >> 0;
480 }
481
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100482 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (before)
Vladimir Marko164306e2016-03-15 14:57:32 +0000483 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
484 /// CHECK-DAG: <<Const64:i\d+>> IntConstant 64
485 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const64>>]
486 /// CHECK-DAG: Return [<<Shr>>]
487
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100488 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
Vladimir Marko164306e2016-03-15 14:57:32 +0000489 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
490 /// CHECK-DAG: Return [<<Arg>>]
491
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100492 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
Vladimir Marko164306e2016-03-15 14:57:32 +0000493 /// CHECK-NOT: Shr
494
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100495 public static long $noinline$Shr64(long arg) {
496 if (doThrow) { throw new Error(); }
Vladimir Marko164306e2016-03-15 14:57:32 +0000497 return arg >> 64;
498 }
499
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100500 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100501 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
502 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
503 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Const0>>]
504 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000505
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100506 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100507 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
508 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000509
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100510 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100511 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100512
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100513 public static long $noinline$Sub0(long arg) {
514 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000515 return arg - 0;
516 }
517
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100518 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100519 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
520 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
521 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const0>>,<<Arg>>]
522 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000523
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100524 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100525 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
526 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
527 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000528
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100529 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100530 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100531
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100532 public static int $noinline$SubAliasNeg(int arg) {
533 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000534 return 0 - arg;
535 }
536
Anton Kirilove14dc862016-05-13 17:56:15 +0100537 /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (before)
538 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
539 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
540 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
541 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<ArgValue>>]
542 /// CHECK-DAG: <<Add:i\d+>> Add [<<Sub>>,<<Const6>>]
543 /// CHECK-DAG: Return [<<Add>>]
544
545 /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (after)
546 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
547 /// CHECK-DAG: <<Const11:i\d+>> IntConstant 11
548 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const11>>,<<ArgValue>>]
549 /// CHECK-DAG: Return [<<Sub>>]
550
551 public static int $noinline$SubAddConst1(int arg) {
552 if (doThrow) { throw new Error(); }
553 return 5 - arg + 6;
554 }
555
556 /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (before)
557 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
558 /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14
559 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
560 /// CHECK-DAG: <<Add:i\d+>> Add [<<ArgValue>>,<<Const13>>]
561 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const14>>,<<Add>>]
562 /// CHECK-DAG: Return [<<Sub>>]
563
564 /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (after)
565 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
566 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
567 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const1>>,<<ArgValue>>]
568 /// CHECK-DAG: Return [<<Sub>>]
569
570 public static int $noinline$SubAddConst2(int arg) {
571 if (doThrow) { throw new Error(); }
572 return 14 - (arg + 13);
573 }
574
575 /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (before)
576 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
577 /// CHECK-DAG: <<Const17:j\d+>> LongConstant 17
578 /// CHECK-DAG: <<Const18:j\d+>> LongConstant 18
579 /// CHECK-DAG: <<Sub1:j\d+>> Sub [<<Const18>>,<<ArgValue>>]
580 /// CHECK-DAG: <<Sub2:j\d+>> Sub [<<Const17>>,<<Sub1>>]
581 /// CHECK-DAG: Return [<<Sub2>>]
582
583 /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (after)
584 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
585 /// CHECK-DAG: <<ConstM1:j\d+>> LongConstant -1
586 /// CHECK-DAG: <<Add:j\d+>> Add [<<ArgValue>>,<<ConstM1>>]
587 /// CHECK-DAG: Return [<<Add>>]
588
589 public static long $noinline$SubSubConst(long arg) {
590 if (doThrow) { throw new Error(); }
591 return 17 - (18 - arg);
592 }
593
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100594 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100595 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
596 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
597 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const0>>]
598 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000599
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100600 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100601 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
602 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000603
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100604 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100605 /// CHECK-NOT: UShr
Alexandre Rames74417692015-04-09 15:21:41 +0100606
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100607 public static long $noinline$UShr0(long arg) {
608 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000609 return arg >>> 0;
610 }
611
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100612 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100613 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
614 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
615 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Const0>>]
616 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000617
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100618 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100619 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
620 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000621
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100622 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100623 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100624
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100625 public static int $noinline$Xor0(int arg) {
626 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000627 return arg ^ 0;
628 }
629
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100630 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100631 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
632 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
633 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<ConstF>>]
634 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000635
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100636 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100637 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
638 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
639 /// CHECK-DAG: Return [<<Not>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000640
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100641 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100642 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100643
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100644 public static int $noinline$XorAllOnes(int arg) {
645 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000646 return arg ^ -1;
647 }
648
Alexandre Rames188d4312015-04-09 18:30:21 +0100649 /**
650 * Test that addition or subtraction operation with both inputs negated are
651 * optimized to use a single negation after the operation.
652 * The transformation tested is implemented in
653 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
654 */
655
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100656 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100657 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
658 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
659 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
660 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
661 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
662 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100663
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100664 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100665 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
666 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
667 /// CHECK-NOT: Neg
668 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
669 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
670 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100671
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100672 public static int $noinline$AddNegs1(int arg1, int arg2) {
673 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100674 return -arg1 + -arg2;
675 }
676
677 /**
678 * This is similar to the test-case AddNegs1, but the negations have
679 * multiple uses.
680 * The transformation tested is implemented in
681 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
682 * The current code won't perform the previous optimization. The
683 * transformations do not look at other uses of their inputs. As they don't
684 * know what will happen with other uses, they do not take the risk of
685 * increasing the register pressure by creating or extending live ranges.
686 */
687
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100688 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100689 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
690 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
691 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
692 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
693 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
694 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
695 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
696 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100697
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100698 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100699 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
700 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
701 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
702 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
703 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
704 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
705 /// CHECK-NOT: Neg
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) GVN (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: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
715 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add>>,<<Add>>]
716 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100717
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100718 public static int $noinline$AddNegs2(int arg1, int arg2) {
719 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100720 int temp1 = -arg1;
721 int temp2 = -arg2;
722 return (temp1 + temp2) | (temp1 + temp2);
723 }
724
725 /**
726 * This follows test-cases AddNegs1 and AddNegs2.
727 * The transformation tested is implemented in
728 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
729 * The optimization should not happen if it moves an additional instruction in
730 * the loop.
731 */
732
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100733 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100734 // -------------- Arguments and initial negation operations.
735 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
736 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
737 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
738 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
739 /// CHECK: Goto
740 // -------------- Loop
741 /// CHECK: SuspendCheck
742 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
743 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100744
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100745 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100746 // -------------- Arguments and initial negation operations.
747 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
748 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
749 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
750 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
751 /// CHECK: Goto
752 // -------------- Loop
753 /// CHECK: SuspendCheck
754 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
755 /// CHECK-NOT: Neg
756 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100757
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100758 public static long $noinline$AddNegs3(long arg1, long arg2) {
759 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100760 long res = 0;
761 long n_arg1 = -arg1;
762 long n_arg2 = -arg2;
763 for (long i = 0; i < 1; i++) {
764 res += n_arg1 + n_arg2 + i;
765 }
766 return res;
767 }
768
769 /**
770 * Test the simplification of an addition with a negated argument into a
771 * subtraction.
772 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
773 */
774
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100775 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100776 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
777 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
778 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
779 /// CHECK-DAG: <<Add:j\d+>> Add [<<Neg>>,<<Arg2>>]
780 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100781
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100782 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100783 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
784 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
785 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg2>>,<<Arg1>>]
786 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100787
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100788 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100789 /// CHECK-NOT: Neg
790 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100791
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100792 public static long $noinline$AddNeg1(long arg1, long arg2) {
793 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100794 return -arg1 + arg2;
795 }
796
797 /**
798 * This is similar to the test-case AddNeg1, but the negation has two uses.
799 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
800 * The current code won't perform the previous optimization. The
801 * transformations do not look at other uses of their inputs. As they don't
802 * know what will happen with other uses, they do not take the risk of
803 * increasing the register pressure by creating or extending live ranges.
804 */
805
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100806 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100807 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
808 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
809 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
810 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
811 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
812 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
813 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100814
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100815 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100816 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
817 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
818 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
819 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
820 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
821 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
822 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100823
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100824 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100825 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100826
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100827 public static long $noinline$AddNeg2(long arg1, long arg2) {
828 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100829 long temp = -arg2;
830 return (arg1 + temp) | (arg1 + temp);
831 }
832
833 /**
834 * Test simplification of the `-(-var)` pattern.
835 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
836 */
837
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100838 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100839 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
840 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg>>]
841 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Neg1>>]
842 /// CHECK-DAG: Return [<<Neg2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100843
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100844 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100845 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
846 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100847
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100848 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100849 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100850
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100851 public static long $noinline$NegNeg1(long arg) {
852 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100853 return -(-arg);
854 }
855
856 /**
857 * Test 'multi-step' simplification, where a first transformation yields a
858 * new simplification possibility for the current instruction.
859 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
860 * and in `InstructionSimplifierVisitor::VisitAdd`.
861 */
862
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100863 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100864 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
865 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg>>]
866 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Neg1>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000867 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg2>>,<<Neg1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100868 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100869
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100870 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100871 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
872 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg>>,<<Arg>>]
873 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100874
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100875 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100876 /// CHECK-NOT: Neg
877 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100878
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700879 /// CHECK-START: int Main.$noinline$NegNeg2(int) constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100880 /// CHECK: <<Const0:i\d+>> IntConstant 0
881 /// CHECK-NOT: Neg
882 /// CHECK-NOT: Add
883 /// CHECK: Return [<<Const0>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100884
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100885 public static int $noinline$NegNeg2(int arg) {
886 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100887 int temp = -arg;
888 return temp + -temp;
889 }
890
891 /**
892 * Test another 'multi-step' simplification, where a first transformation
893 * yields a new simplification possibility for the current instruction.
894 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
895 * and in `InstructionSimplifierVisitor::VisitSub`.
896 */
897
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100898 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100899 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
900 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
901 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg>>]
902 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const0>>,<<Neg>>]
903 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100904
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100905 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100906 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
907 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100908
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100909 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100910 /// CHECK-NOT: Neg
911 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100912
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100913 public static long $noinline$NegNeg3(long arg) {
914 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100915 return 0 - -arg;
916 }
917
918 /**
919 * Test that a negated subtraction is simplified to a subtraction with its
920 * arguments reversed.
921 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
922 */
923
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100924 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100925 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
926 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
927 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
928 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Sub>>]
929 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100930
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100931 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100932 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
933 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
934 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg2>>,<<Arg1>>]
935 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100936
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100937 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100938 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100939
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100940 public static int $noinline$NegSub1(int arg1, int arg2) {
941 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100942 return -(arg1 - arg2);
943 }
944
945 /**
946 * This is similar to the test-case NegSub1, but the subtraction has
947 * multiple uses.
948 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
949 * The current code won't perform the previous optimization. The
950 * transformations do not look at other uses of their inputs. As they don't
951 * know what will happen with other uses, they do not take the risk of
952 * increasing the register pressure by creating or extending live ranges.
953 */
954
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100955 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100956 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
957 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
958 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
959 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
960 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
961 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
962 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100963
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100964 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100965 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
966 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
967 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
968 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
969 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
970 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
971 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100972
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100973 public static int $noinline$NegSub2(int arg1, int arg2) {
974 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100975 int temp = arg1 - arg2;
976 return -temp | -temp;
977 }
978
979 /**
980 * Test simplification of the `~~var` pattern.
981 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`.
982 */
983
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100984 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (before)
Igor Murashkin42691732017-06-26 15:57:31 -0700985 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
986 /// CHECK-DAG: <<ConstNeg1:j\d+>> LongConstant -1
987 /// CHECK-DAG: <<Not1:j\d+>> Xor [<<Arg>>,<<ConstNeg1>>]
988 /// CHECK-DAG: <<Not2:j\d+>> Xor [<<Not1>>,<<ConstNeg1>>]
989 /// CHECK-DAG: Return [<<Not2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100990
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100991 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100992 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
993 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100994
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100995 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
Igor Murashkin42691732017-06-26 15:57:31 -0700996 /// CHECK-NOT: Xor
Alexandre Rames188d4312015-04-09 18:30:21 +0100997
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100998 public static long $noinline$NotNot1(long arg) {
999 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +01001000 return ~~arg;
1001 }
1002
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001003 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (before)
Igor Murashkin42691732017-06-26 15:57:31 -07001004 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1005 /// CHECK-DAG: <<ConstNeg1:i\d+>> IntConstant -1
1006 /// CHECK-DAG: <<Not1:i\d+>> Xor [<<Arg>>,<<ConstNeg1>>]
1007 /// CHECK-DAG: <<Not2:i\d+>> Xor [<<Not1>>,<<ConstNeg1>>]
1008 /// CHECK-DAG: <<Add:i\d+>> Add [<<Not2>>,<<Not1>>]
1009 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001010
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001011 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001012 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1013 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
David Brazdil57e863c2016-01-11 10:27:13 +00001014 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg>>,<<Not>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001015 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001016
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001017 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +00001018 /// CHECK: Not
1019 /// CHECK-NOT: Not
Alexandre Rames188d4312015-04-09 18:30:21 +01001020
Igor Murashkin42691732017-06-26 15:57:31 -07001021 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
1022 /// CHECK-NOT: Xor
1023
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001024 public static int $noinline$NotNot2(int arg) {
1025 if (doThrow) { throw new Error(); }
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) {
1053 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +01001054 return -arg1 - arg2;
1055 }
1056
1057 /**
1058 * This is similar to the test-case SubNeg1, but the negation has
1059 * multiple uses.
1060 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1061 * The current code won't perform the previous optimization. The
1062 * transformations do not look at other uses of their inputs. As they don't
1063 * know what will happen with other uses, they do not take the risk of
1064 * increasing the register pressure by creating or extending live ranges.
1065 */
1066
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001067 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001068 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1069 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1070 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1071 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1072 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1073 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
1074 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001075
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001076 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001077 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1078 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1079 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1080 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1081 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1082 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
1083 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001084
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001085 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001086 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +01001087
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001088 public static int $noinline$SubNeg2(int arg1, int arg2) {
1089 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +01001090 int temp = -arg1;
1091 return (temp - arg2) | (temp - arg2);
1092 }
1093
1094 /**
1095 * This follows test-cases SubNeg1 and SubNeg2.
1096 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1097 * The optimization should not happen if it moves an additional instruction in
1098 * the loop.
1099 */
1100
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001101 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001102 // -------------- Arguments and initial negation operation.
1103 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
1104 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
1105 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1106 /// CHECK: Goto
1107 // -------------- Loop
1108 /// CHECK: SuspendCheck
1109 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1110 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001111
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001112 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001113 // -------------- Arguments and initial negation operation.
1114 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
1115 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
1116 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1117 /// CHECK-DAG: Goto
1118 // -------------- Loop
1119 /// CHECK: SuspendCheck
1120 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1121 /// CHECK-NOT: Neg
1122 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001123
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001124 public static long $noinline$SubNeg3(long arg1, long arg2) {
1125 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +01001126 long res = 0;
1127 long temp = -arg1;
1128 for (long i = 0; i < 1; i++) {
1129 res += temp - arg2 - i;
1130 }
1131 return res;
1132 }
1133
Aart Bik639cc8c2016-10-18 13:03:31 -07001134 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001135 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001136 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1137 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001138 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001139 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1140 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<NotArg>>,<<Const2>>]
1141 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1142 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001143
Aart Bik639cc8c2016-10-18 13:03:31 -07001144 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001145 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
1146 /// CHECK-DAG: Return [<<True>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001147
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001148 public static boolean $noinline$EqualBoolVsIntConst(boolean arg) {
1149 if (doThrow) { throw new Error(); }
Nicolas Geoffraydac9b192016-07-15 10:46:17 +01001150 // Make calls that will be inlined to make sure the instruction simplifier
1151 // sees the simplification (dead code elimination will also try to simplify it).
1152 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) != 2;
1153 }
1154
1155 public static int $inline$ReturnArg(int arg) {
1156 return arg;
David Brazdil1e9ec052015-06-22 10:26:45 +01001157 }
1158
Aart Bik639cc8c2016-10-18 13:03:31 -07001159 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001160 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001161 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1162 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001163 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001164 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1165 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<NotArg>>,<<Const2>>]
1166 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1167 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001168
Aart Bik639cc8c2016-10-18 13:03:31 -07001169 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001170 /// CHECK-DAG: <<False:i\d+>> IntConstant 0
1171 /// CHECK-DAG: Return [<<False>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001172
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001173 public static boolean $noinline$NotEqualBoolVsIntConst(boolean arg) {
1174 if (doThrow) { throw new Error(); }
Nicolas Geoffraydac9b192016-07-15 10:46:17 +01001175 // Make calls that will be inlined to make sure the instruction simplifier
1176 // sees the simplification (dead code elimination will also try to simplify it).
1177 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) == 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001178 }
1179
David Brazdil0d13fee2015-04-17 14:52:19 +01001180 /*
1181 * Test simplification of double Boolean negation. Note that sometimes
1182 * both negations can be removed but we only expect the simplifier to
1183 * remove the second.
1184 */
1185
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001186 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (before)
1187 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001188 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 0
1189 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect method_name:Main.NegateValue
1190 /// CHECK-DAG: <<NotResult:z\d+>> NotEqual [<<Result>>,<<Const1>>]
1191 /// CHECK-DAG: If [<<NotResult>>]
1192
1193 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after)
1194 /// CHECK-NOT: NotEqual
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001195
1196 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after)
1197 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001198 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect method_name:Main.NegateValue
1199 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1200 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1201 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>]
1202 /// CHECK-DAG: Return [<<Phi>>]
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001203
Aart Bik639cc8c2016-10-18 13:03:31 -07001204 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001205 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001206 /// CHECK-NOT: BooleanNot [<<Arg>>]
1207 /// CHECK-NOT: Phi
1208
1209 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before)
1210 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1211 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1212 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1213 /// CHECK-DAG: <<Sel:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1214 /// CHECK-DAG: <<Sel2:i\d+>> Select [<<Const1>>,<<Const0>>,<<Sel>>]
1215 /// CHECK-DAG: Return [<<Sel2>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001216
Aart Bik639cc8c2016-10-18 13:03:31 -07001217 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001218 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001219 /// CHECK: BooleanNot [<<Arg>>]
1220 /// CHECK-NEXT: Goto
1221
1222 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after)
1223 /// CHECK-NOT: Select
David Brazdil0d13fee2015-04-17 14:52:19 +01001224
Sebastien Hertz55418e12016-09-23 16:51:42 +02001225 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) dead_code_elimination$final (after)
1226 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001227 /// CHECK-NOT: BooleanNot [<<Arg>>]
Sebastien Hertz55418e12016-09-23 16:51:42 +02001228 /// CHECK-DAG: Return [<<Arg>>]
1229
David Brazdil769c9e52015-04-27 13:54:09 +01001230 public static boolean NegateValue(boolean arg) {
1231 return !arg;
1232 }
1233
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001234 public static boolean $noinline$NotNotBool(boolean arg) {
1235 if (doThrow) { throw new Error(); }
David Brazdil769c9e52015-04-27 13:54:09 +01001236 return !(NegateValue(arg));
David Brazdil0d13fee2015-04-17 14:52:19 +01001237 }
1238
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001239 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001240 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1241 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
1242 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>]
1243 /// CHECK-DAG: Return [<<Div>>]
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-DAG: <<Arg:f\d+>> ParameterValue
1247 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5
1248 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>]
1249 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001250
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001251 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001252 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001253
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001254 public static float $noinline$Div2(float arg) {
1255 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001256 return arg / 2.0f;
1257 }
1258
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001259 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001260 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1261 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
1262 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>]
1263 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001264
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001265 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001266 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1267 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5
1268 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>]
1269 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001270
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001271 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001272 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001273 public static double $noinline$Div2(double arg) {
1274 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001275 return arg / 2.0;
1276 }
1277
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001278 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001279 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1280 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25
1281 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>]
1282 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001283
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001284 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001285 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1286 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4
1287 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>]
1288 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001289
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001290 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001291 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001292
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001293 public static float $noinline$DivMP25(float arg) {
1294 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001295 return arg / -0.25f;
1296 }
1297
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001298 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001299 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1300 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25
1301 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>]
1302 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001303
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001304 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001305 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1306 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4
1307 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>]
1308 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001309
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001310 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001311 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001312 public static double $noinline$DivMP25(double arg) {
1313 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001314 return arg / -0.25f;
1315 }
1316
Alexandre Rames38db7852015-11-20 15:02:45 +00001317 /**
1318 * Test strength reduction of factors of the form (2^n + 1).
1319 */
1320
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001321 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001322 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1323 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
1324 /// CHECK: Mul [<<Arg>>,<<Const9>>]
1325
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001326 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001327 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1328 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1329 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>]
1330 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>]
1331
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001332 public static int $noinline$mulPow2Plus1(int arg) {
1333 if (doThrow) { throw new Error(); }
Alexandre Rames38db7852015-11-20 15:02:45 +00001334 return arg * 9;
1335 }
1336
Alexandre Rames38db7852015-11-20 15:02:45 +00001337 /**
1338 * Test strength reduction of factors of the form (2^n - 1).
1339 */
1340
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001341 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001342 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1343 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31
David Brazdil57e863c2016-01-11 10:27:13 +00001344 /// CHECK: Mul [<<Const31>>,<<Arg>>]
Alexandre Rames38db7852015-11-20 15:02:45 +00001345
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001346 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001347 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1348 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1349 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>]
1350 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>]
1351
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001352 public static long $noinline$mulPow2Minus1(long arg) {
1353 if (doThrow) { throw new Error(); }
Alexandre Rames38db7852015-11-20 15:02:45 +00001354 return arg * 31;
1355 }
1356
Aart Bik639cc8c2016-10-18 13:03:31 -07001357 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001358 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdilf02c3cf2016-02-29 09:14:51 +00001359 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1360 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001361 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
Mark Mendellf6529172015-11-17 11:16:56 -05001362 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1363 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +00001364 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1365 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001366
Aart Bik639cc8c2016-10-18 13:03:31 -07001367 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (after)
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001368 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001369 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1370 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1371 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1372 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1373 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001374
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001375 public static int $noinline$booleanFieldNotEqualOne() {
1376 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001377 return (booleanField == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001378 }
1379
Aart Bik639cc8c2016-10-18 13:03:31 -07001380 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001381 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdilf02c3cf2016-02-29 09:14:51 +00001382 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1383 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001384 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
Mark Mendellf6529172015-11-17 11:16:56 -05001385 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdilf02c3cf2016-02-29 09:14:51 +00001386 /// CHECK-DAG: <<NE:z\d+>> Equal [<<Field>>,<<Const0>>]
1387 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1388 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001389
Aart Bik639cc8c2016-10-18 13:03:31 -07001390 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (after)
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001391 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001392 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1393 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1394 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1395 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1396 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001397
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001398 public static int $noinline$booleanFieldEqualZero() {
1399 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001400 return (booleanField != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001401 }
1402
Aart Bik639cc8c2016-10-18 13:03:31 -07001403 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001404 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001405 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
Mark Mendellf6529172015-11-17 11:16:56 -05001406 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +00001407 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001408 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001409 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1410 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1411 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001412 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001413 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1414 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001415
Aart Bik639cc8c2016-10-18 13:03:31 -07001416 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001417 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001418 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001419 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001420 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1421 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001422 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001423 /// CHECK-DAG: Return [<<Result>>]
1424 // Note that we match `LE` from Select because there are two identical
1425 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001426
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001427 public static int $noinline$intConditionNotEqualOne(int i) {
1428 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001429 return ((i > 42) == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001430 }
1431
Aart Bik639cc8c2016-10-18 13:03:31 -07001432 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001433 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1434 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001435 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1436 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001437 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001438 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1439 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1440 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
1441 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>]
1442 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1443 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001444
Aart Bik639cc8c2016-10-18 13:03:31 -07001445 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001446 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001447 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001448 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001449 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1450 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001451 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001452 /// CHECK-DAG: Return [<<Result>>]
1453 // Note that we match `LE` from Select because there are two identical
1454 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001455
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001456 public static int $noinline$intConditionEqualZero(int i) {
1457 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001458 return ((i > 42) != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001459 }
1460
1461 // Test that conditions on float/double are not flipped.
1462
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001463 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001464 /// CHECK: LessThanOrEqual
1465
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001466 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001467 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1468 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1469 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1470 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
1471 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1472 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1473 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001474
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001475 public static int $noinline$floatConditionNotEqualOne(float f) {
1476 if (doThrow) { throw new Error(); }
Mark Mendellf6529172015-11-17 11:16:56 -05001477 return ((f > 42.0f) == true) ? 13 : 54;
1478 }
1479
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001480 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001481 /// CHECK: LessThanOrEqual
1482
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001483 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001484 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1485 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1486 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1487 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1488 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1489 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1490 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001491
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001492 public static int $noinline$doubleConditionEqualZero(double d) {
1493 if (doThrow) { throw new Error(); }
Mark Mendellf6529172015-11-17 11:16:56 -05001494 return ((d > 42.0) != false) ? 13 : 54;
1495 }
Alexandre Rames38db7852015-11-20 15:02:45 +00001496
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001497 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001498 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1499 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1500 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1501 /// CHECK-DAG: Return [<<Int>>]
1502
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001503 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001504 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1505 /// CHECK-DAG: Return [<<Arg>>]
1506
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001507 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001508 /// CHECK-NOT: TypeConversion
1509
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001510 public static int $noinline$intToDoubleToInt(int value) {
1511 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001512 // Lossless conversion followed by a conversion back.
1513 return (int) (double) value;
1514 }
1515
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001516 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001517 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1518 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1519 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1520
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001521 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001522 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1523 /// CHECK-DAG: {{d\d+}} TypeConversion [<<Arg>>]
1524
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001525 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001526 /// CHECK-DAG: TypeConversion
1527 /// CHECK-NOT: TypeConversion
1528
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001529 public static String $noinline$intToDoubleToIntPrint(int value) {
1530 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001531 // Lossless conversion followed by a conversion back
1532 // with another use of the intermediate result.
1533 double d = (double) value;
1534 int i = (int) d;
1535 return "d=" + d + ", i=" + i;
1536 }
1537
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001538 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001539 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1540 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1541 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1542 /// CHECK-DAG: Return [<<Int>>]
1543
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001544 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001545 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1546 /// CHECK-DAG: Return [<<Arg>>]
1547
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001548 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001549 /// CHECK-NOT: TypeConversion
1550
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001551 public static int $noinline$byteToDoubleToInt(byte value) {
1552 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001553 // Lossless conversion followed by another conversion, use implicit conversion.
1554 return (int) (double) value;
1555 }
1556
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001557 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (before)
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: <<Int:i\d+>> TypeConversion [<<Double>>]
1561 /// CHECK-DAG: Return [<<Int>>]
1562
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001563 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001564 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1565 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1566 /// CHECK-DAG: Return [<<Int>>]
1567
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001568 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001569 /// CHECK-DAG: TypeConversion
1570 /// CHECK-NOT: TypeConversion
1571
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001572 public static int $noinline$floatToDoubleToInt(float value) {
1573 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001574 // Lossless conversion followed by another conversion.
1575 return (int) (double) value;
1576 }
1577
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001578 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001579 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1580 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1581 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1582
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001583 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001584 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1585 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1586 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1587
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001588 public static String $noinline$floatToDoubleToIntPrint(float value) {
1589 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001590 // Lossless conversion followed by another conversion with
1591 // an extra use of the intermediate result.
1592 double d = (double) value;
1593 int i = (int) d;
1594 return "d=" + d + ", i=" + i;
1595 }
1596
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001597 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001598 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1599 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1600 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1601 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1602 /// CHECK-DAG: Return [<<Short>>]
1603
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001604 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001605 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1606 /// CHECK-DAG: Return [<<Arg>>]
1607
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001608 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001609 /// CHECK-NOT: TypeConversion
1610
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001611 public static short $noinline$byteToDoubleToShort(byte value) {
1612 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001613 // Originally, this is byte->double->int->short. The first conversion is lossless,
1614 // so we merge this with the second one to byte->int which we omit as it's an implicit
1615 // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1616 return (short) (double) value;
1617 }
1618
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001619 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001620 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1621 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1622 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1623 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1624 /// CHECK-DAG: Return [<<Short>>]
1625
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001626 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001627 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1628 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Arg>>]
1629 /// CHECK-DAG: Return [<<Short>>]
1630
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001631 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001632 /// CHECK-DAG: TypeConversion
1633 /// CHECK-NOT: TypeConversion
1634
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001635 public static short $noinline$charToDoubleToShort(char value) {
1636 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001637 // Originally, this is char->double->int->short. The first conversion is lossless,
1638 // so we merge this with the second one to char->int which we omit as it's an implicit
1639 // conversion. Then we are left with the resulting char->short conversion.
1640 return (short) (double) value;
1641 }
1642
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001643 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001644 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1645 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1646 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1647 /// CHECK-DAG: Return [<<Short>>]
1648
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001649 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001650 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1651 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1652 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1653 /// CHECK-DAG: Return [<<Short>>]
1654
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001655 public static short $noinline$floatToIntToShort(float value) {
1656 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001657 // Lossy FP to integral conversion followed by another conversion: no simplification.
1658 return (short) value;
1659 }
1660
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001661 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001662 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1663 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1664 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1665 /// CHECK-DAG: Return [<<Int>>]
1666
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001667 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001668 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1669 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1670 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1671 /// CHECK-DAG: Return [<<Int>>]
1672
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001673 public static int $noinline$intToFloatToInt(int value) {
1674 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001675 // Lossy integral to FP conversion followed another conversion: no simplification.
1676 return (int) (float) value;
1677 }
1678
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001679 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001680 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1681 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1682 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1683 /// CHECK-DAG: Return [<<Double>>]
1684
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001685 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001686 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1687 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1688 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1689 /// CHECK-DAG: Return [<<Double>>]
1690
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001691 public static double $noinline$longToIntToDouble(long value) {
1692 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001693 // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1694 return (double) (int) value;
1695 }
1696
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001697 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001698 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1699 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1700 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1701 /// CHECK-DAG: Return [<<Long>>]
1702
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001703 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001704 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1705 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1706 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1707 /// CHECK-DAG: Return [<<Long>>]
1708
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001709 public static long $noinline$longToIntToLong(long value) {
1710 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001711 // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1712 return (long) (int) value;
1713 }
1714
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001715 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001716 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1717 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1718 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Char>>]
1719 /// CHECK-DAG: Return [<<Short>>]
1720
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001721 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001722 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1723 /// CHECK-DAG: Return [<<Arg>>]
1724
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001725 public static short $noinline$shortToCharToShort(short value) {
1726 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001727 // Integral conversion followed by non-widening integral conversion to original type.
1728 return (short) (char) value;
1729 }
1730
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001731 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001732 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1733 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1734 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Long>>]
1735 /// CHECK-DAG: Return [<<Int>>]
1736
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001737 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001738 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1739 /// CHECK-DAG: Return [<<Arg>>]
1740
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001741 public static int $noinline$shortToLongToInt(short value) {
1742 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001743 // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1744 return (int) (long) value;
1745 }
1746
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001747 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001748 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1749 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1750 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Char>>]
1751 /// CHECK-DAG: Return [<<Byte>>]
1752
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001753 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001754 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1755 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1756 /// CHECK-DAG: Return [<<Byte>>]
1757
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001758 public static byte $noinline$shortToCharToByte(short value) {
1759 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001760 // Integral conversion followed by non-widening integral conversion losing bits
1761 // from the original type. Simplify to use only one conversion.
1762 return (byte) (char) value;
1763 }
1764
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001765 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001766 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1767 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1768 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1769
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001770 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001771 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1772 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1773 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1774
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001775 public static String $noinline$shortToCharToBytePrint(short value) {
1776 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001777 // Integral conversion followed by non-widening integral conversion losing bits
1778 // from the original type with an extra use of the intermediate result.
1779 char c = (char) value;
1780 byte b = (byte) c;
1781 return "c=" + ((int) c) + ", b=" + ((int) b); // implicit conversions.
1782 }
1783
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001784 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001785 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1786 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 255
1787 /// CHECK-DAG: <<And:j\d+>> And [<<Mask>>,<<Arg>>]
1788 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<And>>]
1789 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Int>>]
1790 /// CHECK-DAG: Return [<<Byte>>]
1791
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001792 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001793 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1794 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1795 /// CHECK-DAG: Return [<<Byte>>]
1796
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001797 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001798 /// CHECK-NOT: And
1799
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001800 public static byte $noinline$longAnd0xffToByte(long value) {
1801 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001802 return (byte) (value & 0xff);
1803 }
1804
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001805 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001806 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1807 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 131071
1808 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1809 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<And>>]
1810 /// CHECK-DAG: Return [<<Char>>]
1811
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001812 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001813 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1814 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1815 /// CHECK-DAG: Return [<<Char>>]
1816
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001817 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001818 /// CHECK-NOT: And
1819
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001820 public static char $noinline$intAnd0x1ffffToChar(int value) {
1821 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001822 // Keeping all significant bits and one more.
1823 return (char) (value & 0x1ffff);
1824 }
1825
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001826 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001827 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1828 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1829 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1830 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1831 /// CHECK-DAG: Return [<<Short>>]
1832
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001833 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001834 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1835 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1836 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1837 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1838 /// CHECK-DAG: Return [<<Short>>]
1839
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001840 public static short $noinline$intAnd0x17fffToShort(int value) {
1841 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001842 // No simplification: clearing a significant bit.
1843 return (short) (value & 0x17fff);
1844 }
1845
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001846 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (before)
Vladimir Marko625090f2016-03-14 18:00:05 +00001847 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1848 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 65535
1849 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1850 /// CHECK-DAG: <<Same:s\d+>> TypeConversion [<<And>>]
1851 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Same>>]
1852 /// CHECK-DAG: Return [<<Double>>]
1853
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001854 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (after)
Vladimir Marko625090f2016-03-14 18:00:05 +00001855 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1856 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1857 /// CHECK-DAG: Return [<<Double>>]
1858
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001859 public static double $noinline$shortAnd0xffffToShortToDouble(short value) {
1860 if (doThrow) { throw new Error(); }
Vladimir Marko625090f2016-03-14 18:00:05 +00001861 short same = (short) (value & 0xffff);
1862 return (double) same;
1863 }
1864
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001865 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001866 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1867 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1868 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Const42>>,<<Arg>>]
1869
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001870 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001871 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1872 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1873 /// CHECK-DAG: <<GE:z\d+>> GreaterThanOrEqual [<<Arg>>,<<Const42>>]
1874
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001875 public static int $noinline$intReverseCondition(int i) {
1876 if (doThrow) { throw new Error(); }
Anton Shaminbdd79352016-02-15 12:48:36 +06001877 return (42 > i) ? 13 : 54;
1878 }
1879
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001880 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001881 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1882 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1883 /// CHECK-DAG: <<CMP:i\d+>> Compare [<<Const42>>,<<Result>>]
1884
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001885 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001886 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1887 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1888 /// CHECK-DAG: <<EQ:z\d+>> Equal [<<Result>>,<<Const42>>]
1889
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001890 public static int $noinline$intReverseConditionNaN(int i) {
1891 if (doThrow) { throw new Error(); }
Anton Shaminbdd79352016-02-15 12:48:36 +06001892 return (42 != Math.sqrt(i)) ? 13 : 54;
1893 }
1894
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001895 public static int $noinline$runSmaliTest(String name, boolean input) {
1896 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001897 try {
1898 Class<?> c = Class.forName("SmaliTests");
Andreas Gampe166aaee2016-07-18 08:27:23 -07001899 Method m = c.getMethod(name, boolean.class);
David Brazdilf02c3cf2016-02-29 09:14:51 +00001900 return (Integer) m.invoke(null, input);
1901 } catch (Exception ex) {
1902 throw new Error(ex);
1903 }
1904 }
1905
Igor Murashkin42691732017-06-26 15:57:31 -07001906 public static boolean $noinline$runSmaliTestBoolean(String name, boolean input) {
1907 if (doThrow) { throw new Error(); }
1908 try {
1909 Class<?> c = Class.forName("SmaliTests");
1910 Method m = c.getMethod(name, boolean.class);
1911 return (Boolean) m.invoke(null, input);
1912 } catch (Exception ex) {
1913 throw new Error(ex);
1914 }
1915 }
1916
1917 public static int $noinline$runSmaliTestInt(String name, int arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +01001918 if (doThrow) { throw new Error(); }
1919 try {
1920 Class<?> c = Class.forName("SmaliTests");
1921 Method m = c.getMethod(name, int.class);
1922 return (Integer) m.invoke(null, arg);
1923 } catch (Exception ex) {
1924 throw new Error(ex);
1925 }
1926 }
1927
Igor Murashkin42691732017-06-26 15:57:31 -07001928 public static long $noinline$runSmaliTestLong(String name, long arg) {
1929 if (doThrow) { throw new Error(); }
1930 try {
1931 Class<?> c = Class.forName("SmaliTests");
1932 Method m = c.getMethod(name, long.class);
1933 return (Long) m.invoke(null, arg);
1934 } catch (Exception ex) {
1935 throw new Error(ex);
1936 }
1937 }
1938
Alexandre Rames50518442016-06-27 11:39:19 +01001939 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1940 /// CHECK: <<Value:i\d+>> ParameterValue
1941 /// CHECK: <<Shift:i\d+>> ParameterValue
1942 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1943 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1944 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<And>>]
1945 /// CHECK-DAG: Return [<<Shl>>]
1946
1947 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1948 /// CHECK: <<Value:i\d+>> ParameterValue
1949 /// CHECK: <<Shift:i\d+>> ParameterValue
1950 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<Shift>>]
1951 /// CHECK-DAG: Return [<<Shl>>]
1952
1953 public static int $noinline$intUnnecessaryShiftMasking(int value, int shift) {
1954 if (doThrow) { throw new Error(); }
1955 return value << (shift & 31);
1956 }
1957
1958 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (before)
1959 /// CHECK: <<Value:j\d+>> ParameterValue
1960 /// CHECK: <<Shift:i\d+>> ParameterValue
1961 /// CHECK-DAG: <<Const63:i\d+>> IntConstant 63
1962 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const63>>]
1963 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<And>>]
1964 /// CHECK-DAG: Return [<<Shr>>]
1965
1966 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (after)
1967 /// CHECK: <<Value:j\d+>> ParameterValue
1968 /// CHECK: <<Shift:i\d+>> ParameterValue
1969 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<Shift>>]
1970 /// CHECK-DAG: Return [<<Shr>>]
1971
1972 public static long $noinline$longUnnecessaryShiftMasking(long value, int shift) {
1973 if (doThrow) { throw new Error(); }
1974 return value >> (shift & 63);
1975 }
1976
1977 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (before)
1978 /// CHECK: <<Value:i\d+>> ParameterValue
1979 /// CHECK: <<Shift:i\d+>> ParameterValue
1980 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
1981 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const255>>]
1982 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<And>>]
1983 /// CHECK-DAG: Return [<<UShr>>]
1984
1985 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (after)
1986 /// CHECK: <<Value:i\d+>> ParameterValue
1987 /// CHECK: <<Shift:i\d+>> ParameterValue
1988 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<Shift>>]
1989 /// CHECK-DAG: Return [<<UShr>>]
1990
1991 public static int $noinline$intUnnecessaryWiderShiftMasking(int value, int shift) {
1992 if (doThrow) { throw new Error(); }
1993 return value >>> (shift & 0xff);
1994 }
1995
1996 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (before)
1997 /// CHECK: <<Value:j\d+>> ParameterValue
1998 /// CHECK: <<Shift:i\d+>> ParameterValue
1999 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
2000 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
2001 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
2002 /// CHECK-DAG: Return [<<Shl>>]
2003
2004 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (after)
2005 /// CHECK: <<Value:j\d+>> ParameterValue
2006 /// CHECK: <<Shift:i\d+>> ParameterValue
2007 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
2008 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
2009 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
2010 /// CHECK-DAG: Return [<<Shl>>]
2011
2012 public static long $noinline$longSmallerShiftMasking(long value, int shift) {
2013 if (doThrow) { throw new Error(); }
2014 return value << (shift & 3);
2015 }
2016
2017 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
2018 /// CHECK: <<Value:i\d+>> ParameterValue
2019 /// CHECK: <<Shift:i\d+>> ParameterValue
2020 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
2021 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
2022 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<And>>]
2023 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
2024 /// CHECK-DAG: Return [<<Add>>]
2025
2026 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
2027 /// CHECK: <<Value:i\d+>> ParameterValue
2028 /// CHECK: <<Shift:i\d+>> ParameterValue
2029 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
2030 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
2031 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<Shift>>]
2032 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
2033 /// CHECK-DAG: Return [<<Add>>]
2034
2035 public static int $noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift) {
2036 if (doThrow) { throw new Error(); }
2037 int temp = shift & 31;
2038 return (value >> temp) + temp;
2039 }
2040
Vladimir Marko7033d492017-09-28 16:32:24 +01002041 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (before)
2042 /// CHECK: <<Value:i\d+>> ParameterValue
2043 /// CHECK: <<Shift:i\d+>> ParameterValue
2044 /// CHECK-DAG: <<Const32:i\d+>> IntConstant 32
2045 /// CHECK-DAG: <<Const64:i\d+>> IntConstant 64
2046 /// CHECK-DAG: <<Const96:i\d+>> IntConstant 96
2047 /// CHECK-DAG: <<Const128:i\d+>> IntConstant 128
2048 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const32>>]
2049 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const64>>]
2050 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const96>>]
2051 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const128>>]
2052 /// CHECK-DAG: <<Conv:b\d+>> TypeConversion [<<Shift>>]
2053 /// CHECK-DAG: Shl [<<Value>>,<<Or>>]
2054 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>]
2055 /// CHECK-DAG: UShr [<<Value>>,<<Add>>]
2056 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>]
2057 /// CHECK-DAG: Shr [<<Value>>,<<Conv>>]
2058
2059 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (after)
2060 /// CHECK: <<Value:i\d+>> ParameterValue
2061 /// CHECK: <<Shift:i\d+>> ParameterValue
2062 /// CHECK-DAG: Shl [<<Value>>,<<Shift>>]
2063 /// CHECK-DAG: Shr [<<Value>>,<<Shift>>]
2064 /// CHECK-DAG: UShr [<<Value>>,<<Shift>>]
2065 /// CHECK-DAG: Shl [<<Value>>,<<Shift>>]
2066 /// CHECK-DAG: Shr [<<Value>>,<<Shift>>]
2067
2068 public static int $noinline$intUnnecessaryShiftModifications(int value, int shift) {
2069 if (doThrow) { throw new Error(); }
2070 int c128 = 128;
2071 return (value << (shift | 32)) +
2072 (value >> (shift ^ 64)) +
2073 (value >>> (shift + 96)) +
2074 (value << (shift - c128)) + // Needs a named constant to generate Sub.
2075 (value >> ((byte) shift));
2076 }
2077
2078 /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (before)
2079 /// CHECK: <<Value:i\d+>> ParameterValue
2080 /// CHECK: <<Shift:i\d+>> ParameterValue
2081 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
2082 /// CHECK-DAG: <<Const65:i\d+>> IntConstant 65
2083 /// CHECK-DAG: <<Const97:i\d+>> IntConstant 97
2084 /// CHECK-DAG: <<Const129:i\d+>> IntConstant 129
2085 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const33>>]
2086 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const65>>]
2087 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const97>>]
2088 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const129>>]
2089 /// CHECK-DAG: Shl [<<Value>>,<<Or>>]
2090 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>]
2091 /// CHECK-DAG: UShr [<<Value>>,<<Add>>]
2092 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>]
2093
2094 /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (after)
2095 /// CHECK: <<Value:i\d+>> ParameterValue
2096 /// CHECK: <<Shift:i\d+>> ParameterValue
2097 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
2098 /// CHECK-DAG: <<Const65:i\d+>> IntConstant 65
2099 /// CHECK-DAG: <<Const97:i\d+>> IntConstant 97
2100 /// CHECK-DAG: <<Const129:i\d+>> IntConstant 129
2101 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const33>>]
2102 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const65>>]
2103 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const97>>]
2104 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const129>>]
2105 /// CHECK-DAG: Shl [<<Value>>,<<Or>>]
2106 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>]
2107 /// CHECK-DAG: UShr [<<Value>>,<<Add>>]
2108 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>]
2109
2110 public static int $noinline$intNecessaryShiftModifications(int value, int shift) {
2111 if (doThrow) { throw new Error(); }
2112 int c129 = 129;
2113 return (value << (shift | 33)) +
2114 (value >> (shift ^ 65)) +
2115 (value >>> (shift + 97)) +
2116 (value << (shift - c129)); // Needs a named constant to generate Sub.
2117 }
2118
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002119 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (before)
2120 /// CHECK: <<X:i\d+>> ParameterValue
2121 /// CHECK: <<Y:i\d+>> ParameterValue
2122 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2123 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<X>>]
2124 /// CHECK-DAG: Return [<<Res>>]
2125
2126 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (after)
2127 /// CHECK: <<X:i\d+>> ParameterValue
2128 /// CHECK: <<Y:i\d+>> ParameterValue
2129 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2130 /// CHECK-DAG: Return [<<Y>>]
2131
2132 public static int $noinline$intAddSubSimplifyArg1(int x, int y) {
2133 if (doThrow) { throw new Error(); }
2134 int sum = x + y;
2135 return sum - x;
2136 }
2137
2138 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (before)
2139 /// CHECK: <<X:i\d+>> ParameterValue
2140 /// CHECK: <<Y:i\d+>> ParameterValue
2141 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2142 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<Y>>]
2143 /// CHECK-DAG: Return [<<Res>>]
2144
2145 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (after)
2146 /// CHECK: <<X:i\d+>> ParameterValue
2147 /// CHECK: <<Y:i\d+>> ParameterValue
2148 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2149 /// CHECK-DAG: Return [<<X>>]
2150
2151 public static int $noinline$intAddSubSimplifyArg2(int x, int y) {
2152 if (doThrow) { throw new Error(); }
2153 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) {
2171 if (doThrow) { throw new Error(); }
2172 int sub = x - y;
2173 return sub + y;
2174 }
2175
2176 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (before)
2177 /// CHECK: <<X:i\d+>> ParameterValue
2178 /// CHECK: <<Y:i\d+>> ParameterValue
2179 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2180 /// CHECK-DAG: <<Res:i\d+>> Add [<<Y>>,<<Sub>>]
2181 /// CHECK-DAG: Return [<<Res>>]
2182
2183 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (after)
2184 /// CHECK: <<X:i\d+>> ParameterValue
2185 /// CHECK: <<Y:i\d+>> ParameterValue
2186 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2187 /// CHECK-DAG: Return [<<X>>]
2188
2189 public static int $noinline$intSubAddSimplifyRight(int x, int y) {
2190 if (doThrow) { throw new Error(); }
2191 int sub = x - y;
2192 return y + sub;
2193 }
2194
2195 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (before)
2196 /// CHECK: <<X:f\d+>> ParameterValue
2197 /// CHECK: <<Y:f\d+>> ParameterValue
2198 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2199 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2200 /// CHECK-DAG: Return [<<Res>>]
2201
2202 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (after)
2203 /// CHECK: <<X:f\d+>> ParameterValue
2204 /// CHECK: <<Y:f\d+>> ParameterValue
2205 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2206 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2207 /// CHECK-DAG: Return [<<Res>>]
2208
2209 public static float $noinline$floatAddSubSimplifyArg1(float x, float y) {
2210 if (doThrow) { throw new Error(); }
2211 float sum = x + y;
2212 return sum - x;
2213 }
2214
2215 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (before)
2216 /// CHECK: <<X:f\d+>> ParameterValue
2217 /// CHECK: <<Y:f\d+>> ParameterValue
2218 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2219 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2220 /// CHECK-DAG: Return [<<Res>>]
2221
2222 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (after)
2223 /// CHECK: <<X:f\d+>> ParameterValue
2224 /// CHECK: <<Y:f\d+>> ParameterValue
2225 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2226 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2227 /// CHECK-DAG: Return [<<Res>>]
2228
2229 public static float $noinline$floatAddSubSimplifyArg2(float x, float y) {
2230 if (doThrow) { throw new Error(); }
2231 float sum = x + y;
2232 return sum - y;
2233 }
2234
2235 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (before)
2236 /// CHECK: <<X:f\d+>> ParameterValue
2237 /// CHECK: <<Y:f\d+>> ParameterValue
2238 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2239 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2240 /// CHECK-DAG: Return [<<Res>>]
2241
2242 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (after)
2243 /// CHECK: <<X:f\d+>> ParameterValue
2244 /// CHECK: <<Y:f\d+>> ParameterValue
2245 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2246 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2247 /// CHECK-DAG: Return [<<Res>>]
2248
2249 public static float $noinline$floatSubAddSimplifyLeft(float x, float y) {
2250 if (doThrow) { throw new Error(); }
2251 float sub = x - y;
2252 return sub + y;
2253 }
2254
2255 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (before)
2256 /// CHECK: <<X:f\d+>> ParameterValue
2257 /// CHECK: <<Y:f\d+>> ParameterValue
2258 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2259 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2260 /// CHECK-DAG: Return [<<Res>>]
2261
2262 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (after)
2263 /// CHECK: <<X:f\d+>> ParameterValue
2264 /// CHECK: <<Y:f\d+>> ParameterValue
2265 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2266 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2267 /// CHECK-DAG: Return [<<Res>>]
2268
2269 public static float $noinline$floatSubAddSimplifyRight(float x, float y) {
2270 if (doThrow) { throw new Error(); }
2271 float sub = x - y;
2272 return y + sub;
2273 }
2274
2275 public static void main(String[] args) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002276 int arg = 123456;
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002277 float floatArg = 123456.125f;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002278
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002279 assertLongEquals(arg, $noinline$Add0(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002280 assertIntEquals(5, $noinline$AddAddSubAddConst(1));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002281 assertIntEquals(arg, $noinline$AndAllOnes(arg));
2282 assertLongEquals(arg, $noinline$Div1(arg));
2283 assertIntEquals(-arg, $noinline$DivN1(arg));
2284 assertLongEquals(arg, $noinline$Mul1(arg));
2285 assertIntEquals(-arg, $noinline$MulN1(arg));
2286 assertLongEquals((128 * arg), $noinline$MulPowerOfTwo128(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002287 assertLongEquals(2640, $noinline$MulMulMulConst(2));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002288 assertIntEquals(arg, $noinline$Or0(arg));
2289 assertLongEquals(arg, $noinline$OrSame(arg));
2290 assertIntEquals(arg, $noinline$Shl0(arg));
2291 assertLongEquals(arg, $noinline$Shr0(arg));
2292 assertLongEquals(arg, $noinline$Shr64(arg));
2293 assertLongEquals(arg, $noinline$Sub0(arg));
2294 assertIntEquals(-arg, $noinline$SubAliasNeg(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002295 assertIntEquals(9, $noinline$SubAddConst1(2));
2296 assertIntEquals(-2, $noinline$SubAddConst2(3));
2297 assertLongEquals(3, $noinline$SubSubConst(4));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002298 assertLongEquals(arg, $noinline$UShr0(arg));
2299 assertIntEquals(arg, $noinline$Xor0(arg));
2300 assertIntEquals(~arg, $noinline$XorAllOnes(arg));
2301 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs1(arg, arg + 1));
2302 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs2(arg, arg + 1));
2303 assertLongEquals(-(2 * arg + 1), $noinline$AddNegs3(arg, arg + 1));
2304 assertLongEquals(1, $noinline$AddNeg1(arg, arg + 1));
2305 assertLongEquals(-1, $noinline$AddNeg2(arg, arg + 1));
2306 assertLongEquals(arg, $noinline$NegNeg1(arg));
2307 assertIntEquals(0, $noinline$NegNeg2(arg));
2308 assertLongEquals(arg, $noinline$NegNeg3(arg));
2309 assertIntEquals(1, $noinline$NegSub1(arg, arg + 1));
2310 assertIntEquals(1, $noinline$NegSub2(arg, arg + 1));
2311 assertLongEquals(arg, $noinline$NotNot1(arg));
Igor Murashkin42691732017-06-26 15:57:31 -07002312 assertLongEquals(arg, $noinline$runSmaliTestLong("NotNot1", arg));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002313 assertIntEquals(-1, $noinline$NotNot2(arg));
Igor Murashkin42691732017-06-26 15:57:31 -07002314 assertIntEquals(-1, $noinline$runSmaliTestInt("NotNot2", arg));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002315 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg1(arg, arg + 1));
2316 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg2(arg, arg + 1));
2317 assertLongEquals(-(2 * arg + 1), $noinline$SubNeg3(arg, arg + 1));
2318 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2319 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2320 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2321 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2322 assertBooleanEquals(true, $noinline$NotNotBool(true));
Igor Murashkin42691732017-06-26 15:57:31 -07002323 assertBooleanEquals(true, $noinline$runSmaliTestBoolean("NotNotBool", true));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002324 assertBooleanEquals(false, $noinline$NotNotBool(false));
Igor Murashkin42691732017-06-26 15:57:31 -07002325 assertBooleanEquals(false, $noinline$runSmaliTestBoolean("NotNotBool", false));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002326 assertFloatEquals(50.0f, $noinline$Div2(100.0f));
2327 assertDoubleEquals(75.0, $noinline$Div2(150.0));
2328 assertFloatEquals(-400.0f, $noinline$DivMP25(100.0f));
2329 assertDoubleEquals(-600.0, $noinline$DivMP25(150.0));
2330 assertIntEquals(0xc, $noinline$UShr28And15(0xc1234567));
2331 assertLongEquals(0xcL, $noinline$UShr60And15(0xc123456787654321L));
2332 assertIntEquals(0x4, $noinline$UShr28And7(0xc1234567));
2333 assertLongEquals(0x4L, $noinline$UShr60And7(0xc123456787654321L));
2334 assertIntEquals(0xc1, $noinline$Shr24And255(0xc1234567));
2335 assertLongEquals(0xc1L, $noinline$Shr56And255(0xc123456787654321L));
2336 assertIntEquals(0x41, $noinline$Shr24And127(0xc1234567));
2337 assertLongEquals(0x41L, $noinline$Shr56And127(0xc123456787654321L));
2338 assertIntEquals(0, $noinline$mulPow2Plus1(0));
2339 assertIntEquals(9, $noinline$mulPow2Plus1(1));
2340 assertIntEquals(18, $noinline$mulPow2Plus1(2));
2341 assertIntEquals(900, $noinline$mulPow2Plus1(100));
2342 assertIntEquals(111105, $noinline$mulPow2Plus1(12345));
2343 assertLongEquals(0, $noinline$mulPow2Minus1(0));
2344 assertLongEquals(31, $noinline$mulPow2Minus1(1));
2345 assertLongEquals(62, $noinline$mulPow2Minus1(2));
2346 assertLongEquals(3100, $noinline$mulPow2Minus1(100));
2347 assertLongEquals(382695, $noinline$mulPow2Minus1(12345));
Mark Mendellf6529172015-11-17 11:16:56 -05002348
2349 booleanField = false;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002350 assertIntEquals($noinline$booleanFieldNotEqualOne(), 54);
2351 assertIntEquals($noinline$booleanFieldEqualZero(), 54);
Mark Mendellf6529172015-11-17 11:16:56 -05002352 booleanField = true;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002353 assertIntEquals(13, $noinline$booleanFieldNotEqualOne());
2354 assertIntEquals(13, $noinline$booleanFieldEqualZero());
2355 assertIntEquals(54, $noinline$intConditionNotEqualOne(6));
2356 assertIntEquals(13, $noinline$intConditionNotEqualOne(43));
2357 assertIntEquals(54, $noinline$intConditionEqualZero(6));
2358 assertIntEquals(13, $noinline$intConditionEqualZero(43));
2359 assertIntEquals(54, $noinline$floatConditionNotEqualOne(6.0f));
2360 assertIntEquals(13, $noinline$floatConditionNotEqualOne(43.0f));
2361 assertIntEquals(54, $noinline$doubleConditionEqualZero(6.0));
2362 assertIntEquals(13, $noinline$doubleConditionEqualZero(43.0));
Vladimir Markob52bbde2016-02-12 12:06:05 +00002363
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002364 assertIntEquals(1234567, $noinline$intToDoubleToInt(1234567));
2365 assertIntEquals(Integer.MIN_VALUE, $noinline$intToDoubleToInt(Integer.MIN_VALUE));
2366 assertIntEquals(Integer.MAX_VALUE, $noinline$intToDoubleToInt(Integer.MAX_VALUE));
2367 assertStringEquals("d=7654321.0, i=7654321", $noinline$intToDoubleToIntPrint(7654321));
2368 assertIntEquals(12, $noinline$byteToDoubleToInt((byte) 12));
2369 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToInt(Byte.MIN_VALUE));
2370 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToInt(Byte.MAX_VALUE));
2371 assertIntEquals(11, $noinline$floatToDoubleToInt(11.3f));
2372 assertStringEquals("d=12.25, i=12", $noinline$floatToDoubleToIntPrint(12.25f));
2373 assertIntEquals(123, $noinline$byteToDoubleToShort((byte) 123));
2374 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToShort(Byte.MIN_VALUE));
2375 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToShort(Byte.MAX_VALUE));
2376 assertIntEquals(1234, $noinline$charToDoubleToShort((char) 1234));
2377 assertIntEquals(Character.MIN_VALUE, $noinline$charToDoubleToShort(Character.MIN_VALUE));
2378 assertIntEquals(/* sign-extended */ -1, $noinline$charToDoubleToShort(Character.MAX_VALUE));
2379 assertIntEquals(12345, $noinline$floatToIntToShort(12345.75f));
2380 assertIntEquals(Short.MAX_VALUE, $noinline$floatToIntToShort((float)(Short.MIN_VALUE - 1)));
2381 assertIntEquals(Short.MIN_VALUE, $noinline$floatToIntToShort((float)(Short.MAX_VALUE + 1)));
2382 assertIntEquals(-54321, $noinline$intToFloatToInt(-54321));
2383 assertDoubleEquals((double) 0x12345678, $noinline$longToIntToDouble(0x1234567812345678L));
2384 assertDoubleEquals(0.0, $noinline$longToIntToDouble(Long.MIN_VALUE));
2385 assertDoubleEquals(-1.0, $noinline$longToIntToDouble(Long.MAX_VALUE));
2386 assertLongEquals(0x0000000012345678L, $noinline$longToIntToLong(0x1234567812345678L));
2387 assertLongEquals(0xffffffff87654321L, $noinline$longToIntToLong(0x1234567887654321L));
2388 assertLongEquals(0L, $noinline$longToIntToLong(Long.MIN_VALUE));
2389 assertLongEquals(-1L, $noinline$longToIntToLong(Long.MAX_VALUE));
2390 assertIntEquals((short) -5678, $noinline$shortToCharToShort((short) -5678));
2391 assertIntEquals(Short.MIN_VALUE, $noinline$shortToCharToShort(Short.MIN_VALUE));
2392 assertIntEquals(Short.MAX_VALUE, $noinline$shortToCharToShort(Short.MAX_VALUE));
2393 assertIntEquals(5678, $noinline$shortToLongToInt((short) 5678));
2394 assertIntEquals(Short.MIN_VALUE, $noinline$shortToLongToInt(Short.MIN_VALUE));
2395 assertIntEquals(Short.MAX_VALUE, $noinline$shortToLongToInt(Short.MAX_VALUE));
2396 assertIntEquals(0x34, $noinline$shortToCharToByte((short) 0x1234));
2397 assertIntEquals(-0x10, $noinline$shortToCharToByte((short) 0x12f0));
2398 assertIntEquals(0, $noinline$shortToCharToByte(Short.MIN_VALUE));
2399 assertIntEquals(-1, $noinline$shortToCharToByte(Short.MAX_VALUE));
2400 assertStringEquals("c=1025, b=1", $noinline$shortToCharToBytePrint((short) 1025));
2401 assertStringEquals("c=1023, b=-1", $noinline$shortToCharToBytePrint((short) 1023));
2402 assertStringEquals("c=65535, b=-1", $noinline$shortToCharToBytePrint((short) -1));
Vladimir Marko8428bd32016-02-12 16:53:57 +00002403
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002404 assertIntEquals(0x21, $noinline$longAnd0xffToByte(0x1234432112344321L));
2405 assertIntEquals(0, $noinline$longAnd0xffToByte(Long.MIN_VALUE));
2406 assertIntEquals(-1, $noinline$longAnd0xffToByte(Long.MAX_VALUE));
2407 assertIntEquals(0x1234, $noinline$intAnd0x1ffffToChar(0x43211234));
2408 assertIntEquals(0, $noinline$intAnd0x1ffffToChar(Integer.MIN_VALUE));
2409 assertIntEquals(Character.MAX_VALUE, $noinline$intAnd0x1ffffToChar(Integer.MAX_VALUE));
2410 assertIntEquals(0x4321, $noinline$intAnd0x17fffToShort(0x87654321));
2411 assertIntEquals(0x0888, $noinline$intAnd0x17fffToShort(0x88888888));
2412 assertIntEquals(0, $noinline$intAnd0x17fffToShort(Integer.MIN_VALUE));
2413 assertIntEquals(Short.MAX_VALUE, $noinline$intAnd0x17fffToShort(Integer.MAX_VALUE));
Vladimir Marko625090f2016-03-14 18:00:05 +00002414
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002415 assertDoubleEquals(0.0, $noinline$shortAnd0xffffToShortToDouble((short) 0));
2416 assertDoubleEquals(1.0, $noinline$shortAnd0xffffToShortToDouble((short) 1));
2417 assertDoubleEquals(-2.0, $noinline$shortAnd0xffffToShortToDouble((short) -2));
2418 assertDoubleEquals(12345.0, $noinline$shortAnd0xffffToShortToDouble((short) 12345));
2419 assertDoubleEquals((double)Short.MAX_VALUE,
2420 $noinline$shortAnd0xffffToShortToDouble(Short.MAX_VALUE));
2421 assertDoubleEquals((double)Short.MIN_VALUE,
2422 $noinline$shortAnd0xffffToShortToDouble(Short.MIN_VALUE));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002423
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002424 assertIntEquals(13, $noinline$intReverseCondition(41));
2425 assertIntEquals(13, $noinline$intReverseConditionNaN(-5));
Anton Shaminbdd79352016-02-15 12:48:36 +06002426
David Brazdilf02c3cf2016-02-29 09:14:51 +00002427 for (String condition : new String[] { "Equal", "NotEqual" }) {
2428 for (String constant : new String[] { "True", "False" }) {
2429 for (String side : new String[] { "Rhs", "Lhs" }) {
2430 String name = condition + constant + side;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002431 assertIntEquals(5, $noinline$runSmaliTest(name, true));
2432 assertIntEquals(3, $noinline$runSmaliTest(name, false));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002433 }
2434 }
2435 }
Alexandre Rames50518442016-06-27 11:39:19 +01002436
Igor Murashkin42691732017-06-26 15:57:31 -07002437 assertIntEquals(0, $noinline$runSmaliTestInt("AddSubConst", 1));
2438 assertIntEquals(3, $noinline$runSmaliTestInt("SubAddConst", 2));
2439 assertIntEquals(-16, $noinline$runSmaliTestInt("SubSubConst1", 3));
2440 assertIntEquals(-5, $noinline$runSmaliTestInt("SubSubConst2", 4));
2441 assertIntEquals(26, $noinline$runSmaliTestInt("SubSubConst3", 5));
Alexandre Rames50518442016-06-27 11:39:19 +01002442 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3));
2443 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3 + 32));
Vladimir Marko7033d492017-09-28 16:32:24 +01002444 assertLongEquals(0xffffffffffffeaf3L,
2445 $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50));
2446 assertLongEquals(0xffffffffffffeaf3L,
2447 $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50 + 64));
Alexandre Rames50518442016-06-27 11:39:19 +01002448 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10));
2449 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10 + 128));
Vladimir Marko7033d492017-09-28 16:32:24 +01002450 assertLongEquals(0xaf37bc048d159e24L,
2451 $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2));
2452 assertLongEquals(0xaf37bc048d159e24L,
2453 $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2 + 256));
Alexandre Rames50518442016-06-27 11:39:19 +01002454 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13));
2455 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13 + 512));
Vladimir Marko7033d492017-09-28 16:32:24 +01002456 assertIntEquals(0x5f49eb48, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 2));
2457 assertIntEquals(0xbd4c29b0, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 3));
2458 assertIntEquals(0xc0fed1ca, $noinline$intNecessaryShiftModifications(0xabcdef01, 2));
2459 assertIntEquals(0x03578ebc, $noinline$intNecessaryShiftModifications(0xabcdef01, 3));
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002460
2461 assertIntEquals(654321, $noinline$intAddSubSimplifyArg1(arg, 654321));
2462 assertIntEquals(arg, $noinline$intAddSubSimplifyArg2(arg, 654321));
2463 assertIntEquals(arg, $noinline$intSubAddSimplifyLeft(arg, 654321));
2464 assertIntEquals(arg, $noinline$intSubAddSimplifyRight(arg, 654321));
2465 assertFloatEquals(654321.125f, $noinline$floatAddSubSimplifyArg1(floatArg, 654321.125f));
2466 assertFloatEquals(floatArg, $noinline$floatAddSubSimplifyArg2(floatArg, 654321.125f));
2467 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyLeft(floatArg, 654321.125f));
2468 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyRight(floatArg, 654321.125f));
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002469 }
Mark Mendellf6529172015-11-17 11:16:56 -05002470
David Brazdilf02c3cf2016-02-29 09:14:51 +00002471 private static boolean $inline$true() { return true; }
2472 private static boolean $inline$false() { return false; }
2473
Mark Mendellf6529172015-11-17 11:16:56 -05002474 public static boolean booleanField;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002475}