blob: e71a0e150b3ff1a1f89956ce63268cb8f0db1620 [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)
David Brazdila06d66a2015-05-28 11:14:54 +0100985 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
David Brazdilf02c3cf2016-02-29 09:14:51 +0000986 /// CHECK-DAG: <<Not1:j\d+>> Not [<<Arg>>]
987 /// CHECK-DAG: <<Not2:j\d+>> Not [<<Not1>>]
988 /// CHECK-DAG: Return [<<Not2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100989
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100990 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100991 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
992 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100993
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100994 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +0000995 /// CHECK-NOT: Not
Alexandre Rames188d4312015-04-09 18:30:21 +0100996
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100997 public static long $noinline$NotNot1(long arg) {
998 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100999 return ~~arg;
1000 }
1001
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001002 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001003 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdilf02c3cf2016-02-29 09:14:51 +00001004 /// CHECK-DAG: <<Not1:i\d+>> Not [<<Arg>>]
1005 /// CHECK-DAG: <<Not2:i\d+>> Not [<<Not1>>]
1006 /// CHECK-DAG: <<Add:i\d+>> Add [<<Not2>>,<<Not1>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001007 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001008
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001009 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001010 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1011 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
David Brazdil57e863c2016-01-11 10:27:13 +00001012 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg>>,<<Not>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001013 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001014
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001015 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +00001016 /// CHECK: Not
1017 /// CHECK-NOT: Not
Alexandre Rames188d4312015-04-09 18:30:21 +01001018
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001019 public static int $noinline$NotNot2(int arg) {
1020 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +01001021 int temp = ~arg;
1022 return temp + ~temp;
1023 }
1024
1025 /**
1026 * Test the simplification of a subtraction with a negated argument.
1027 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1028 */
1029
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001030 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001031 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1032 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1033 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1034 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1035 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001036
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001037 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001038 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1039 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1040 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
1041 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
1042 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001043
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001044 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001045 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +01001046
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001047 public static int $noinline$SubNeg1(int arg1, int arg2) {
1048 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +01001049 return -arg1 - arg2;
1050 }
1051
1052 /**
1053 * This is similar to the test-case SubNeg1, but the negation has
1054 * multiple uses.
1055 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1056 * The current code won't perform the previous optimization. The
1057 * transformations do not look at other uses of their inputs. As they don't
1058 * know what will happen with other uses, they do not take the risk of
1059 * increasing the register pressure by creating or extending live ranges.
1060 */
1061
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001062 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001063 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1064 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1065 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1066 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1067 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1068 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
1069 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001070
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001071 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001072 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1073 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1074 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1075 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1076 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1077 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
1078 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001079
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001080 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001081 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +01001082
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001083 public static int $noinline$SubNeg2(int arg1, int arg2) {
1084 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +01001085 int temp = -arg1;
1086 return (temp - arg2) | (temp - arg2);
1087 }
1088
1089 /**
1090 * This follows test-cases SubNeg1 and SubNeg2.
1091 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1092 * The optimization should not happen if it moves an additional instruction in
1093 * the loop.
1094 */
1095
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001096 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001097 // -------------- Arguments and initial negation operation.
1098 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
1099 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
1100 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1101 /// CHECK: Goto
1102 // -------------- Loop
1103 /// CHECK: SuspendCheck
1104 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1105 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001106
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001107 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001108 // -------------- Arguments and initial negation operation.
1109 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
1110 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
1111 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1112 /// CHECK-DAG: Goto
1113 // -------------- Loop
1114 /// CHECK: SuspendCheck
1115 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1116 /// CHECK-NOT: Neg
1117 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001118
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001119 public static long $noinline$SubNeg3(long arg1, long arg2) {
1120 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +01001121 long res = 0;
1122 long temp = -arg1;
1123 for (long i = 0; i < 1; i++) {
1124 res += temp - arg2 - i;
1125 }
1126 return res;
1127 }
1128
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001129 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_bce (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001130 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001131 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1132 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001133 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001134 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1135 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<NotArg>>,<<Const2>>]
1136 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1137 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001138
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001139 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001140 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
1141 /// CHECK-DAG: Return [<<True>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001142
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001143 public static boolean $noinline$EqualBoolVsIntConst(boolean arg) {
1144 if (doThrow) { throw new Error(); }
Nicolas Geoffraydac9b192016-07-15 10:46:17 +01001145 // Make calls that will be inlined to make sure the instruction simplifier
1146 // sees the simplification (dead code elimination will also try to simplify it).
1147 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) != 2;
1148 }
1149
1150 public static int $inline$ReturnArg(int arg) {
1151 return arg;
David Brazdil1e9ec052015-06-22 10:26:45 +01001152 }
1153
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001154 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_bce (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001155 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001156 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1157 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001158 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001159 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1160 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<NotArg>>,<<Const2>>]
1161 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1162 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001163
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001164 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001165 /// CHECK-DAG: <<False:i\d+>> IntConstant 0
1166 /// CHECK-DAG: Return [<<False>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001167
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001168 public static boolean $noinline$NotEqualBoolVsIntConst(boolean arg) {
1169 if (doThrow) { throw new Error(); }
Nicolas Geoffraydac9b192016-07-15 10:46:17 +01001170 // Make calls that will be inlined to make sure the instruction simplifier
1171 // sees the simplification (dead code elimination will also try to simplify it).
1172 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) == 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001173 }
1174
David Brazdil0d13fee2015-04-17 14:52:19 +01001175 /*
1176 * Test simplification of double Boolean negation. Note that sometimes
1177 * both negations can be removed but we only expect the simplifier to
1178 * remove the second.
1179 */
1180
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001181 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (before)
1182 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1183 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1184 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect
1185 /// CHECK-DAG: <<NotResult:i\d+>> Xor [<<Result>>,<<Const1>>]
1186 /// CHECK-DAG: Return [<<NotResult>>]
1187
1188 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after)
1189 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1190 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect
1191 /// CHECK-DAG: <<NotResult:z\d+>> BooleanNot [<<Result>>]
1192 /// CHECK-DAG: Return [<<NotResult>>]
1193
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001194 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_bce (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001195 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001196 /// CHECK-DAG: <<NotArg:z\d+>> BooleanNot [<<Arg>>]
1197 /// CHECK-DAG: <<NotNotArg:z\d+>> BooleanNot [<<NotArg>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001198 /// CHECK-DAG: Return [<<NotNotArg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001199
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001200 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_bce (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001201 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001202 /// CHECK-DAG: <<NotArg:z\d+>> BooleanNot [<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001203 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001204
David Brazdil769c9e52015-04-27 13:54:09 +01001205 public static boolean NegateValue(boolean arg) {
1206 return !arg;
1207 }
1208
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001209 public static boolean $noinline$NotNotBool(boolean arg) {
1210 if (doThrow) { throw new Error(); }
David Brazdil769c9e52015-04-27 13:54:09 +01001211 return !(NegateValue(arg));
David Brazdil0d13fee2015-04-17 14:52:19 +01001212 }
1213
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001214 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001215 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1216 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
1217 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>]
1218 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001219
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001220 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001221 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1222 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5
1223 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>]
1224 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001225
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001226 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001227 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001228
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001229 public static float $noinline$Div2(float arg) {
1230 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001231 return arg / 2.0f;
1232 }
1233
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001234 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001235 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1236 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
1237 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>]
1238 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001239
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001240 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001241 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1242 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5
1243 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>]
1244 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001245
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001246 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001247 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001248 public static double $noinline$Div2(double arg) {
1249 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001250 return arg / 2.0;
1251 }
1252
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001253 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001254 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1255 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25
1256 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>]
1257 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001258
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001259 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001260 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1261 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4
1262 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>]
1263 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001264
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001265 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001266 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001267
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001268 public static float $noinline$DivMP25(float arg) {
1269 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001270 return arg / -0.25f;
1271 }
1272
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001273 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001274 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1275 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25
1276 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>]
1277 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001278
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001279 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001280 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1281 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4
1282 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>]
1283 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001284
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001285 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001286 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001287 public static double $noinline$DivMP25(double arg) {
1288 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001289 return arg / -0.25f;
1290 }
1291
Alexandre Rames38db7852015-11-20 15:02:45 +00001292 /**
1293 * Test strength reduction of factors of the form (2^n + 1).
1294 */
1295
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001296 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001297 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1298 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
1299 /// CHECK: Mul [<<Arg>>,<<Const9>>]
1300
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001301 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001302 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1303 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1304 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>]
1305 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>]
1306
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001307 public static int $noinline$mulPow2Plus1(int arg) {
1308 if (doThrow) { throw new Error(); }
Alexandre Rames38db7852015-11-20 15:02:45 +00001309 return arg * 9;
1310 }
1311
Alexandre Rames38db7852015-11-20 15:02:45 +00001312 /**
1313 * Test strength reduction of factors of the form (2^n - 1).
1314 */
1315
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001316 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001317 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1318 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31
David Brazdil57e863c2016-01-11 10:27:13 +00001319 /// CHECK: Mul [<<Const31>>,<<Arg>>]
Alexandre Rames38db7852015-11-20 15:02:45 +00001320
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001321 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001322 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1323 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1324 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>]
1325 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>]
1326
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001327 public static long $noinline$mulPow2Minus1(long arg) {
1328 if (doThrow) { throw new Error(); }
Alexandre Rames38db7852015-11-20 15:02:45 +00001329 return arg * 31;
1330 }
1331
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001332 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001333 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdilf02c3cf2016-02-29 09:14:51 +00001334 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1335 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001336 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
Mark Mendellf6529172015-11-17 11:16:56 -05001337 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1338 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +00001339 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1340 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001341
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001342 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_bce (after)
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001343 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001344 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1345 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1346 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1347 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1348 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001349
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001350 public static int $noinline$booleanFieldNotEqualOne() {
1351 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001352 return (booleanField == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001353 }
1354
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001355 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001356 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdilf02c3cf2016-02-29 09:14:51 +00001357 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1358 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001359 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
Mark Mendellf6529172015-11-17 11:16:56 -05001360 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdilf02c3cf2016-02-29 09:14:51 +00001361 /// CHECK-DAG: <<NE:z\d+>> Equal [<<Field>>,<<Const0>>]
1362 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1363 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001364
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001365 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_bce (after)
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001366 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001367 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1368 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1369 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1370 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1371 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001372
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001373 public static int $noinline$booleanFieldEqualZero() {
1374 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001375 return (booleanField != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001376 }
1377
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001378 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001379 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001380 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
Mark Mendellf6529172015-11-17 11:16:56 -05001381 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +00001382 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001383 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001384 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1385 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1386 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001387 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001388 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1389 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001390
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001391 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_bce (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001392 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001393 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001394 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001395 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1396 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001397 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001398 /// CHECK-DAG: Return [<<Result>>]
1399 // Note that we match `LE` from Select because there are two identical
1400 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001401
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001402 public static int $noinline$intConditionNotEqualOne(int i) {
1403 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001404 return ((i > 42) == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001405 }
1406
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001407 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001408 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1409 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001410 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1411 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001412 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001413 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1414 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1415 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
1416 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>]
1417 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1418 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001419
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001420 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_bce (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001421 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001422 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001423 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001424 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1425 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001426 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001427 /// CHECK-DAG: Return [<<Result>>]
1428 // Note that we match `LE` from Select because there are two identical
1429 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001430
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001431 public static int $noinline$intConditionEqualZero(int i) {
1432 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001433 return ((i > 42) != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001434 }
1435
1436 // Test that conditions on float/double are not flipped.
1437
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001438 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001439 /// CHECK: LessThanOrEqual
1440
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001441 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001442 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1443 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1444 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1445 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
1446 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1447 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1448 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001449
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001450 public static int $noinline$floatConditionNotEqualOne(float f) {
1451 if (doThrow) { throw new Error(); }
Mark Mendellf6529172015-11-17 11:16:56 -05001452 return ((f > 42.0f) == true) ? 13 : 54;
1453 }
1454
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001455 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001456 /// CHECK: LessThanOrEqual
1457
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001458 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001459 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1460 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1461 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1462 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1463 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1464 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1465 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001466
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001467 public static int $noinline$doubleConditionEqualZero(double d) {
1468 if (doThrow) { throw new Error(); }
Mark Mendellf6529172015-11-17 11:16:56 -05001469 return ((d > 42.0) != false) ? 13 : 54;
1470 }
Alexandre Rames38db7852015-11-20 15:02:45 +00001471
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001472 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001473 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1474 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1475 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1476 /// CHECK-DAG: Return [<<Int>>]
1477
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001478 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001479 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1480 /// CHECK-DAG: Return [<<Arg>>]
1481
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001482 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001483 /// CHECK-NOT: TypeConversion
1484
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001485 public static int $noinline$intToDoubleToInt(int value) {
1486 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001487 // Lossless conversion followed by a conversion back.
1488 return (int) (double) value;
1489 }
1490
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001491 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001492 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1493 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1494 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1495
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001496 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001497 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1498 /// CHECK-DAG: {{d\d+}} TypeConversion [<<Arg>>]
1499
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001500 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001501 /// CHECK-DAG: TypeConversion
1502 /// CHECK-NOT: TypeConversion
1503
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001504 public static String $noinline$intToDoubleToIntPrint(int value) {
1505 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001506 // Lossless conversion followed by a conversion back
1507 // with another use of the intermediate result.
1508 double d = (double) value;
1509 int i = (int) d;
1510 return "d=" + d + ", i=" + i;
1511 }
1512
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001513 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001514 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1515 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1516 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1517 /// CHECK-DAG: Return [<<Int>>]
1518
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001519 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001520 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1521 /// CHECK-DAG: Return [<<Arg>>]
1522
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001523 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001524 /// CHECK-NOT: TypeConversion
1525
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001526 public static int $noinline$byteToDoubleToInt(byte value) {
1527 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001528 // Lossless conversion followed by another conversion, use implicit conversion.
1529 return (int) (double) value;
1530 }
1531
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001532 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001533 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1534 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1535 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1536 /// CHECK-DAG: Return [<<Int>>]
1537
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001538 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001539 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1540 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1541 /// CHECK-DAG: Return [<<Int>>]
1542
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001543 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001544 /// CHECK-DAG: TypeConversion
1545 /// CHECK-NOT: TypeConversion
1546
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001547 public static int $noinline$floatToDoubleToInt(float value) {
1548 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001549 // Lossless conversion followed by another conversion.
1550 return (int) (double) value;
1551 }
1552
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001553 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001554 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1555 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1556 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1557
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001558 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001559 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1560 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1561 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1562
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001563 public static String $noinline$floatToDoubleToIntPrint(float value) {
1564 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001565 // Lossless conversion followed by another conversion with
1566 // an extra use of the intermediate result.
1567 double d = (double) value;
1568 int i = (int) d;
1569 return "d=" + d + ", i=" + i;
1570 }
1571
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001572 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001573 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1574 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1575 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1576 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1577 /// CHECK-DAG: Return [<<Short>>]
1578
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001579 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001580 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1581 /// CHECK-DAG: Return [<<Arg>>]
1582
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001583 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001584 /// CHECK-NOT: TypeConversion
1585
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001586 public static short $noinline$byteToDoubleToShort(byte value) {
1587 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001588 // Originally, this is byte->double->int->short. The first conversion is lossless,
1589 // so we merge this with the second one to byte->int which we omit as it's an implicit
1590 // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1591 return (short) (double) value;
1592 }
1593
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001594 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001595 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1596 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1597 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1598 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1599 /// CHECK-DAG: Return [<<Short>>]
1600
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001601 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001602 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1603 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Arg>>]
1604 /// CHECK-DAG: Return [<<Short>>]
1605
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001606 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001607 /// CHECK-DAG: TypeConversion
1608 /// CHECK-NOT: TypeConversion
1609
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001610 public static short $noinline$charToDoubleToShort(char value) {
1611 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001612 // Originally, this is char->double->int->short. The first conversion is lossless,
1613 // so we merge this with the second one to char->int which we omit as it's an implicit
1614 // conversion. Then we are left with the resulting char->short conversion.
1615 return (short) (double) value;
1616 }
1617
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001618 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001619 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1620 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1621 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1622 /// CHECK-DAG: Return [<<Short>>]
1623
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001624 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001625 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1626 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1627 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1628 /// CHECK-DAG: Return [<<Short>>]
1629
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001630 public static short $noinline$floatToIntToShort(float value) {
1631 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001632 // Lossy FP to integral conversion followed by another conversion: no simplification.
1633 return (short) value;
1634 }
1635
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001636 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001637 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1638 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1639 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1640 /// CHECK-DAG: Return [<<Int>>]
1641
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001642 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001643 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1644 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1645 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1646 /// CHECK-DAG: Return [<<Int>>]
1647
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001648 public static int $noinline$intToFloatToInt(int value) {
1649 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001650 // Lossy integral to FP conversion followed another conversion: no simplification.
1651 return (int) (float) value;
1652 }
1653
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001654 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001655 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1656 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1657 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1658 /// CHECK-DAG: Return [<<Double>>]
1659
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001660 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001661 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1662 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1663 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1664 /// CHECK-DAG: Return [<<Double>>]
1665
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001666 public static double $noinline$longToIntToDouble(long value) {
1667 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001668 // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1669 return (double) (int) value;
1670 }
1671
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001672 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001673 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1674 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1675 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1676 /// CHECK-DAG: Return [<<Long>>]
1677
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001678 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001679 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1680 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1681 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1682 /// CHECK-DAG: Return [<<Long>>]
1683
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001684 public static long $noinline$longToIntToLong(long value) {
1685 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001686 // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1687 return (long) (int) value;
1688 }
1689
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001690 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001691 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1692 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1693 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Char>>]
1694 /// CHECK-DAG: Return [<<Short>>]
1695
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001696 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001697 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1698 /// CHECK-DAG: Return [<<Arg>>]
1699
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001700 public static short $noinline$shortToCharToShort(short value) {
1701 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001702 // Integral conversion followed by non-widening integral conversion to original type.
1703 return (short) (char) value;
1704 }
1705
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001706 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001707 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1708 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1709 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Long>>]
1710 /// CHECK-DAG: Return [<<Int>>]
1711
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001712 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001713 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1714 /// CHECK-DAG: Return [<<Arg>>]
1715
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001716 public static int $noinline$shortToLongToInt(short value) {
1717 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001718 // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1719 return (int) (long) value;
1720 }
1721
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001722 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001723 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1724 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1725 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Char>>]
1726 /// CHECK-DAG: Return [<<Byte>>]
1727
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001728 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001729 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1730 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1731 /// CHECK-DAG: Return [<<Byte>>]
1732
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001733 public static byte $noinline$shortToCharToByte(short value) {
1734 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001735 // Integral conversion followed by non-widening integral conversion losing bits
1736 // from the original type. Simplify to use only one conversion.
1737 return (byte) (char) value;
1738 }
1739
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001740 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001741 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1742 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1743 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1744
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001745 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001746 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1747 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1748 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1749
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001750 public static String $noinline$shortToCharToBytePrint(short value) {
1751 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001752 // Integral conversion followed by non-widening integral conversion losing bits
1753 // from the original type with an extra use of the intermediate result.
1754 char c = (char) value;
1755 byte b = (byte) c;
1756 return "c=" + ((int) c) + ", b=" + ((int) b); // implicit conversions.
1757 }
1758
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001759 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001760 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1761 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 255
1762 /// CHECK-DAG: <<And:j\d+>> And [<<Mask>>,<<Arg>>]
1763 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<And>>]
1764 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Int>>]
1765 /// CHECK-DAG: Return [<<Byte>>]
1766
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001767 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001768 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1769 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1770 /// CHECK-DAG: Return [<<Byte>>]
1771
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001772 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001773 /// CHECK-NOT: And
1774
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001775 public static byte $noinline$longAnd0xffToByte(long value) {
1776 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001777 return (byte) (value & 0xff);
1778 }
1779
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001780 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001781 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1782 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 131071
1783 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1784 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<And>>]
1785 /// CHECK-DAG: Return [<<Char>>]
1786
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001787 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001788 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1789 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1790 /// CHECK-DAG: Return [<<Char>>]
1791
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001792 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001793 /// CHECK-NOT: And
1794
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001795 public static char $noinline$intAnd0x1ffffToChar(int value) {
1796 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001797 // Keeping all significant bits and one more.
1798 return (char) (value & 0x1ffff);
1799 }
1800
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001801 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001802 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1803 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1804 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1805 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1806 /// CHECK-DAG: Return [<<Short>>]
1807
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001808 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001809 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1810 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1811 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1812 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1813 /// CHECK-DAG: Return [<<Short>>]
1814
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001815 public static short $noinline$intAnd0x17fffToShort(int value) {
1816 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001817 // No simplification: clearing a significant bit.
1818 return (short) (value & 0x17fff);
1819 }
1820
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001821 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (before)
Vladimir Marko625090f2016-03-14 18:00:05 +00001822 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1823 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 65535
1824 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1825 /// CHECK-DAG: <<Same:s\d+>> TypeConversion [<<And>>]
1826 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Same>>]
1827 /// CHECK-DAG: Return [<<Double>>]
1828
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001829 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (after)
Vladimir Marko625090f2016-03-14 18:00:05 +00001830 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1831 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1832 /// CHECK-DAG: Return [<<Double>>]
1833
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001834 public static double $noinline$shortAnd0xffffToShortToDouble(short value) {
1835 if (doThrow) { throw new Error(); }
Vladimir Marko625090f2016-03-14 18:00:05 +00001836 short same = (short) (value & 0xffff);
1837 return (double) same;
1838 }
1839
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001840 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001841 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1842 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1843 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Const42>>,<<Arg>>]
1844
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001845 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001846 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1847 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1848 /// CHECK-DAG: <<GE:z\d+>> GreaterThanOrEqual [<<Arg>>,<<Const42>>]
1849
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001850 public static int $noinline$intReverseCondition(int i) {
1851 if (doThrow) { throw new Error(); }
Anton Shaminbdd79352016-02-15 12:48:36 +06001852 return (42 > i) ? 13 : 54;
1853 }
1854
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001855 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001856 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1857 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1858 /// CHECK-DAG: <<CMP:i\d+>> Compare [<<Const42>>,<<Result>>]
1859
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001860 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001861 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1862 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1863 /// CHECK-DAG: <<EQ:z\d+>> Equal [<<Result>>,<<Const42>>]
1864
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001865 public static int $noinline$intReverseConditionNaN(int i) {
1866 if (doThrow) { throw new Error(); }
Anton Shaminbdd79352016-02-15 12:48:36 +06001867 return (42 != Math.sqrt(i)) ? 13 : 54;
1868 }
1869
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001870 public static int $noinline$runSmaliTest(String name, boolean input) {
1871 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001872 try {
1873 Class<?> c = Class.forName("SmaliTests");
Andreas Gampe166aaee2016-07-18 08:27:23 -07001874 Method m = c.getMethod(name, boolean.class);
David Brazdilf02c3cf2016-02-29 09:14:51 +00001875 return (Integer) m.invoke(null, input);
1876 } catch (Exception ex) {
1877 throw new Error(ex);
1878 }
1879 }
1880
Anton Kirilove14dc862016-05-13 17:56:15 +01001881 public static int $noinline$runSmaliTestConst(String name, int arg) {
1882 if (doThrow) { throw new Error(); }
1883 try {
1884 Class<?> c = Class.forName("SmaliTests");
1885 Method m = c.getMethod(name, int.class);
1886 return (Integer) m.invoke(null, arg);
1887 } catch (Exception ex) {
1888 throw new Error(ex);
1889 }
1890 }
1891
Alexandre Rames50518442016-06-27 11:39:19 +01001892 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1893 /// CHECK: <<Value:i\d+>> ParameterValue
1894 /// CHECK: <<Shift:i\d+>> ParameterValue
1895 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1896 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1897 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<And>>]
1898 /// CHECK-DAG: Return [<<Shl>>]
1899
1900 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1901 /// CHECK: <<Value:i\d+>> ParameterValue
1902 /// CHECK: <<Shift:i\d+>> ParameterValue
1903 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<Shift>>]
1904 /// CHECK-DAG: Return [<<Shl>>]
1905
1906 public static int $noinline$intUnnecessaryShiftMasking(int value, int shift) {
1907 if (doThrow) { throw new Error(); }
1908 return value << (shift & 31);
1909 }
1910
1911 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (before)
1912 /// CHECK: <<Value:j\d+>> ParameterValue
1913 /// CHECK: <<Shift:i\d+>> ParameterValue
1914 /// CHECK-DAG: <<Const63:i\d+>> IntConstant 63
1915 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const63>>]
1916 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<And>>]
1917 /// CHECK-DAG: Return [<<Shr>>]
1918
1919 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (after)
1920 /// CHECK: <<Value:j\d+>> ParameterValue
1921 /// CHECK: <<Shift:i\d+>> ParameterValue
1922 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<Shift>>]
1923 /// CHECK-DAG: Return [<<Shr>>]
1924
1925 public static long $noinline$longUnnecessaryShiftMasking(long value, int shift) {
1926 if (doThrow) { throw new Error(); }
1927 return value >> (shift & 63);
1928 }
1929
1930 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (before)
1931 /// CHECK: <<Value:i\d+>> ParameterValue
1932 /// CHECK: <<Shift:i\d+>> ParameterValue
1933 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
1934 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const255>>]
1935 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<And>>]
1936 /// CHECK-DAG: Return [<<UShr>>]
1937
1938 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (after)
1939 /// CHECK: <<Value:i\d+>> ParameterValue
1940 /// CHECK: <<Shift:i\d+>> ParameterValue
1941 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<Shift>>]
1942 /// CHECK-DAG: Return [<<UShr>>]
1943
1944 public static int $noinline$intUnnecessaryWiderShiftMasking(int value, int shift) {
1945 if (doThrow) { throw new Error(); }
1946 return value >>> (shift & 0xff);
1947 }
1948
1949 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (before)
1950 /// CHECK: <<Value:j\d+>> ParameterValue
1951 /// CHECK: <<Shift:i\d+>> ParameterValue
1952 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1953 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
1954 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
1955 /// CHECK-DAG: Return [<<Shl>>]
1956
1957 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (after)
1958 /// CHECK: <<Value:j\d+>> ParameterValue
1959 /// CHECK: <<Shift:i\d+>> ParameterValue
1960 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1961 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
1962 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
1963 /// CHECK-DAG: Return [<<Shl>>]
1964
1965 public static long $noinline$longSmallerShiftMasking(long value, int shift) {
1966 if (doThrow) { throw new Error(); }
1967 return value << (shift & 3);
1968 }
1969
1970 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1971 /// CHECK: <<Value:i\d+>> ParameterValue
1972 /// CHECK: <<Shift:i\d+>> ParameterValue
1973 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1974 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1975 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<And>>]
1976 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
1977 /// CHECK-DAG: Return [<<Add>>]
1978
1979 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1980 /// CHECK: <<Value:i\d+>> ParameterValue
1981 /// CHECK: <<Shift:i\d+>> ParameterValue
1982 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1983 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1984 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<Shift>>]
1985 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
1986 /// CHECK-DAG: Return [<<Add>>]
1987
1988 public static int $noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift) {
1989 if (doThrow) { throw new Error(); }
1990 int temp = shift & 31;
1991 return (value >> temp) + temp;
1992 }
1993
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06001994 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (before)
1995 /// CHECK: <<X:i\d+>> ParameterValue
1996 /// CHECK: <<Y:i\d+>> ParameterValue
1997 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
1998 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<X>>]
1999 /// CHECK-DAG: Return [<<Res>>]
2000
2001 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (after)
2002 /// CHECK: <<X:i\d+>> ParameterValue
2003 /// CHECK: <<Y:i\d+>> ParameterValue
2004 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2005 /// CHECK-DAG: Return [<<Y>>]
2006
2007 public static int $noinline$intAddSubSimplifyArg1(int x, int y) {
2008 if (doThrow) { throw new Error(); }
2009 int sum = x + y;
2010 return sum - x;
2011 }
2012
2013 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (before)
2014 /// CHECK: <<X:i\d+>> ParameterValue
2015 /// CHECK: <<Y:i\d+>> ParameterValue
2016 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2017 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<Y>>]
2018 /// CHECK-DAG: Return [<<Res>>]
2019
2020 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (after)
2021 /// CHECK: <<X:i\d+>> ParameterValue
2022 /// CHECK: <<Y:i\d+>> ParameterValue
2023 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2024 /// CHECK-DAG: Return [<<X>>]
2025
2026 public static int $noinline$intAddSubSimplifyArg2(int x, int y) {
2027 if (doThrow) { throw new Error(); }
2028 int sum = x + y;
2029 return sum - y;
2030 }
2031
2032 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (before)
2033 /// CHECK: <<X:i\d+>> ParameterValue
2034 /// CHECK: <<Y:i\d+>> ParameterValue
2035 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2036 /// CHECK-DAG: <<Res:i\d+>> Add [<<Sub>>,<<Y>>]
2037 /// CHECK-DAG: Return [<<Res>>]
2038
2039 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (after)
2040 /// CHECK: <<X:i\d+>> ParameterValue
2041 /// CHECK: <<Y:i\d+>> ParameterValue
2042 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2043 /// CHECK-DAG: Return [<<X>>]
2044
2045 public static int $noinline$intSubAddSimplifyLeft(int x, int y) {
2046 if (doThrow) { throw new Error(); }
2047 int sub = x - y;
2048 return sub + y;
2049 }
2050
2051 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (before)
2052 /// CHECK: <<X:i\d+>> ParameterValue
2053 /// CHECK: <<Y:i\d+>> ParameterValue
2054 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2055 /// CHECK-DAG: <<Res:i\d+>> Add [<<Y>>,<<Sub>>]
2056 /// CHECK-DAG: Return [<<Res>>]
2057
2058 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (after)
2059 /// CHECK: <<X:i\d+>> ParameterValue
2060 /// CHECK: <<Y:i\d+>> ParameterValue
2061 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2062 /// CHECK-DAG: Return [<<X>>]
2063
2064 public static int $noinline$intSubAddSimplifyRight(int x, int y) {
2065 if (doThrow) { throw new Error(); }
2066 int sub = x - y;
2067 return y + sub;
2068 }
2069
2070 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (before)
2071 /// CHECK: <<X:f\d+>> ParameterValue
2072 /// CHECK: <<Y:f\d+>> ParameterValue
2073 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2074 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2075 /// CHECK-DAG: Return [<<Res>>]
2076
2077 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (after)
2078 /// CHECK: <<X:f\d+>> ParameterValue
2079 /// CHECK: <<Y:f\d+>> ParameterValue
2080 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2081 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2082 /// CHECK-DAG: Return [<<Res>>]
2083
2084 public static float $noinline$floatAddSubSimplifyArg1(float x, float y) {
2085 if (doThrow) { throw new Error(); }
2086 float sum = x + y;
2087 return sum - x;
2088 }
2089
2090 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (before)
2091 /// CHECK: <<X:f\d+>> ParameterValue
2092 /// CHECK: <<Y:f\d+>> ParameterValue
2093 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2094 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2095 /// CHECK-DAG: Return [<<Res>>]
2096
2097 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (after)
2098 /// CHECK: <<X:f\d+>> ParameterValue
2099 /// CHECK: <<Y:f\d+>> ParameterValue
2100 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2101 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2102 /// CHECK-DAG: Return [<<Res>>]
2103
2104 public static float $noinline$floatAddSubSimplifyArg2(float x, float y) {
2105 if (doThrow) { throw new Error(); }
2106 float sum = x + y;
2107 return sum - y;
2108 }
2109
2110 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (before)
2111 /// CHECK: <<X:f\d+>> ParameterValue
2112 /// CHECK: <<Y:f\d+>> ParameterValue
2113 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2114 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2115 /// CHECK-DAG: Return [<<Res>>]
2116
2117 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (after)
2118 /// CHECK: <<X:f\d+>> ParameterValue
2119 /// CHECK: <<Y:f\d+>> ParameterValue
2120 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2121 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2122 /// CHECK-DAG: Return [<<Res>>]
2123
2124 public static float $noinline$floatSubAddSimplifyLeft(float x, float y) {
2125 if (doThrow) { throw new Error(); }
2126 float sub = x - y;
2127 return sub + y;
2128 }
2129
2130 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (before)
2131 /// CHECK: <<X:f\d+>> ParameterValue
2132 /// CHECK: <<Y:f\d+>> ParameterValue
2133 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2134 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2135 /// CHECK-DAG: Return [<<Res>>]
2136
2137 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (after)
2138 /// CHECK: <<X:f\d+>> ParameterValue
2139 /// CHECK: <<Y:f\d+>> ParameterValue
2140 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2141 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2142 /// CHECK-DAG: Return [<<Res>>]
2143
2144 public static float $noinline$floatSubAddSimplifyRight(float x, float y) {
2145 if (doThrow) { throw new Error(); }
2146 float sub = x - y;
2147 return y + sub;
2148 }
2149
2150 public static void main(String[] args) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002151 int arg = 123456;
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002152 float floatArg = 123456.125f;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002153
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002154 assertLongEquals(arg, $noinline$Add0(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002155 assertIntEquals(5, $noinline$AddAddSubAddConst(1));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002156 assertIntEquals(arg, $noinline$AndAllOnes(arg));
2157 assertLongEquals(arg, $noinline$Div1(arg));
2158 assertIntEquals(-arg, $noinline$DivN1(arg));
2159 assertLongEquals(arg, $noinline$Mul1(arg));
2160 assertIntEquals(-arg, $noinline$MulN1(arg));
2161 assertLongEquals((128 * arg), $noinline$MulPowerOfTwo128(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002162 assertLongEquals(2640, $noinline$MulMulMulConst(2));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002163 assertIntEquals(arg, $noinline$Or0(arg));
2164 assertLongEquals(arg, $noinline$OrSame(arg));
2165 assertIntEquals(arg, $noinline$Shl0(arg));
2166 assertLongEquals(arg, $noinline$Shr0(arg));
2167 assertLongEquals(arg, $noinline$Shr64(arg));
2168 assertLongEquals(arg, $noinline$Sub0(arg));
2169 assertIntEquals(-arg, $noinline$SubAliasNeg(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002170 assertIntEquals(9, $noinline$SubAddConst1(2));
2171 assertIntEquals(-2, $noinline$SubAddConst2(3));
2172 assertLongEquals(3, $noinline$SubSubConst(4));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002173 assertLongEquals(arg, $noinline$UShr0(arg));
2174 assertIntEquals(arg, $noinline$Xor0(arg));
2175 assertIntEquals(~arg, $noinline$XorAllOnes(arg));
2176 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs1(arg, arg + 1));
2177 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs2(arg, arg + 1));
2178 assertLongEquals(-(2 * arg + 1), $noinline$AddNegs3(arg, arg + 1));
2179 assertLongEquals(1, $noinline$AddNeg1(arg, arg + 1));
2180 assertLongEquals(-1, $noinline$AddNeg2(arg, arg + 1));
2181 assertLongEquals(arg, $noinline$NegNeg1(arg));
2182 assertIntEquals(0, $noinline$NegNeg2(arg));
2183 assertLongEquals(arg, $noinline$NegNeg3(arg));
2184 assertIntEquals(1, $noinline$NegSub1(arg, arg + 1));
2185 assertIntEquals(1, $noinline$NegSub2(arg, arg + 1));
2186 assertLongEquals(arg, $noinline$NotNot1(arg));
2187 assertIntEquals(-1, $noinline$NotNot2(arg));
2188 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg1(arg, arg + 1));
2189 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg2(arg, arg + 1));
2190 assertLongEquals(-(2 * arg + 1), $noinline$SubNeg3(arg, arg + 1));
2191 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2192 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2193 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2194 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2195 assertBooleanEquals(true, $noinline$NotNotBool(true));
2196 assertBooleanEquals(false, $noinline$NotNotBool(false));
2197 assertFloatEquals(50.0f, $noinline$Div2(100.0f));
2198 assertDoubleEquals(75.0, $noinline$Div2(150.0));
2199 assertFloatEquals(-400.0f, $noinline$DivMP25(100.0f));
2200 assertDoubleEquals(-600.0, $noinline$DivMP25(150.0));
2201 assertIntEquals(0xc, $noinline$UShr28And15(0xc1234567));
2202 assertLongEquals(0xcL, $noinline$UShr60And15(0xc123456787654321L));
2203 assertIntEquals(0x4, $noinline$UShr28And7(0xc1234567));
2204 assertLongEquals(0x4L, $noinline$UShr60And7(0xc123456787654321L));
2205 assertIntEquals(0xc1, $noinline$Shr24And255(0xc1234567));
2206 assertLongEquals(0xc1L, $noinline$Shr56And255(0xc123456787654321L));
2207 assertIntEquals(0x41, $noinline$Shr24And127(0xc1234567));
2208 assertLongEquals(0x41L, $noinline$Shr56And127(0xc123456787654321L));
2209 assertIntEquals(0, $noinline$mulPow2Plus1(0));
2210 assertIntEquals(9, $noinline$mulPow2Plus1(1));
2211 assertIntEquals(18, $noinline$mulPow2Plus1(2));
2212 assertIntEquals(900, $noinline$mulPow2Plus1(100));
2213 assertIntEquals(111105, $noinline$mulPow2Plus1(12345));
2214 assertLongEquals(0, $noinline$mulPow2Minus1(0));
2215 assertLongEquals(31, $noinline$mulPow2Minus1(1));
2216 assertLongEquals(62, $noinline$mulPow2Minus1(2));
2217 assertLongEquals(3100, $noinline$mulPow2Minus1(100));
2218 assertLongEquals(382695, $noinline$mulPow2Minus1(12345));
Mark Mendellf6529172015-11-17 11:16:56 -05002219
2220 booleanField = false;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002221 assertIntEquals($noinline$booleanFieldNotEqualOne(), 54);
2222 assertIntEquals($noinline$booleanFieldEqualZero(), 54);
Mark Mendellf6529172015-11-17 11:16:56 -05002223 booleanField = true;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002224 assertIntEquals(13, $noinline$booleanFieldNotEqualOne());
2225 assertIntEquals(13, $noinline$booleanFieldEqualZero());
2226 assertIntEquals(54, $noinline$intConditionNotEqualOne(6));
2227 assertIntEquals(13, $noinline$intConditionNotEqualOne(43));
2228 assertIntEquals(54, $noinline$intConditionEqualZero(6));
2229 assertIntEquals(13, $noinline$intConditionEqualZero(43));
2230 assertIntEquals(54, $noinline$floatConditionNotEqualOne(6.0f));
2231 assertIntEquals(13, $noinline$floatConditionNotEqualOne(43.0f));
2232 assertIntEquals(54, $noinline$doubleConditionEqualZero(6.0));
2233 assertIntEquals(13, $noinline$doubleConditionEqualZero(43.0));
Vladimir Markob52bbde2016-02-12 12:06:05 +00002234
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002235 assertIntEquals(1234567, $noinline$intToDoubleToInt(1234567));
2236 assertIntEquals(Integer.MIN_VALUE, $noinline$intToDoubleToInt(Integer.MIN_VALUE));
2237 assertIntEquals(Integer.MAX_VALUE, $noinline$intToDoubleToInt(Integer.MAX_VALUE));
2238 assertStringEquals("d=7654321.0, i=7654321", $noinline$intToDoubleToIntPrint(7654321));
2239 assertIntEquals(12, $noinline$byteToDoubleToInt((byte) 12));
2240 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToInt(Byte.MIN_VALUE));
2241 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToInt(Byte.MAX_VALUE));
2242 assertIntEquals(11, $noinline$floatToDoubleToInt(11.3f));
2243 assertStringEquals("d=12.25, i=12", $noinline$floatToDoubleToIntPrint(12.25f));
2244 assertIntEquals(123, $noinline$byteToDoubleToShort((byte) 123));
2245 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToShort(Byte.MIN_VALUE));
2246 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToShort(Byte.MAX_VALUE));
2247 assertIntEquals(1234, $noinline$charToDoubleToShort((char) 1234));
2248 assertIntEquals(Character.MIN_VALUE, $noinline$charToDoubleToShort(Character.MIN_VALUE));
2249 assertIntEquals(/* sign-extended */ -1, $noinline$charToDoubleToShort(Character.MAX_VALUE));
2250 assertIntEquals(12345, $noinline$floatToIntToShort(12345.75f));
2251 assertIntEquals(Short.MAX_VALUE, $noinline$floatToIntToShort((float)(Short.MIN_VALUE - 1)));
2252 assertIntEquals(Short.MIN_VALUE, $noinline$floatToIntToShort((float)(Short.MAX_VALUE + 1)));
2253 assertIntEquals(-54321, $noinline$intToFloatToInt(-54321));
2254 assertDoubleEquals((double) 0x12345678, $noinline$longToIntToDouble(0x1234567812345678L));
2255 assertDoubleEquals(0.0, $noinline$longToIntToDouble(Long.MIN_VALUE));
2256 assertDoubleEquals(-1.0, $noinline$longToIntToDouble(Long.MAX_VALUE));
2257 assertLongEquals(0x0000000012345678L, $noinline$longToIntToLong(0x1234567812345678L));
2258 assertLongEquals(0xffffffff87654321L, $noinline$longToIntToLong(0x1234567887654321L));
2259 assertLongEquals(0L, $noinline$longToIntToLong(Long.MIN_VALUE));
2260 assertLongEquals(-1L, $noinline$longToIntToLong(Long.MAX_VALUE));
2261 assertIntEquals((short) -5678, $noinline$shortToCharToShort((short) -5678));
2262 assertIntEquals(Short.MIN_VALUE, $noinline$shortToCharToShort(Short.MIN_VALUE));
2263 assertIntEquals(Short.MAX_VALUE, $noinline$shortToCharToShort(Short.MAX_VALUE));
2264 assertIntEquals(5678, $noinline$shortToLongToInt((short) 5678));
2265 assertIntEquals(Short.MIN_VALUE, $noinline$shortToLongToInt(Short.MIN_VALUE));
2266 assertIntEquals(Short.MAX_VALUE, $noinline$shortToLongToInt(Short.MAX_VALUE));
2267 assertIntEquals(0x34, $noinline$shortToCharToByte((short) 0x1234));
2268 assertIntEquals(-0x10, $noinline$shortToCharToByte((short) 0x12f0));
2269 assertIntEquals(0, $noinline$shortToCharToByte(Short.MIN_VALUE));
2270 assertIntEquals(-1, $noinline$shortToCharToByte(Short.MAX_VALUE));
2271 assertStringEquals("c=1025, b=1", $noinline$shortToCharToBytePrint((short) 1025));
2272 assertStringEquals("c=1023, b=-1", $noinline$shortToCharToBytePrint((short) 1023));
2273 assertStringEquals("c=65535, b=-1", $noinline$shortToCharToBytePrint((short) -1));
Vladimir Marko8428bd32016-02-12 16:53:57 +00002274
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002275 assertIntEquals(0x21, $noinline$longAnd0xffToByte(0x1234432112344321L));
2276 assertIntEquals(0, $noinline$longAnd0xffToByte(Long.MIN_VALUE));
2277 assertIntEquals(-1, $noinline$longAnd0xffToByte(Long.MAX_VALUE));
2278 assertIntEquals(0x1234, $noinline$intAnd0x1ffffToChar(0x43211234));
2279 assertIntEquals(0, $noinline$intAnd0x1ffffToChar(Integer.MIN_VALUE));
2280 assertIntEquals(Character.MAX_VALUE, $noinline$intAnd0x1ffffToChar(Integer.MAX_VALUE));
2281 assertIntEquals(0x4321, $noinline$intAnd0x17fffToShort(0x87654321));
2282 assertIntEquals(0x0888, $noinline$intAnd0x17fffToShort(0x88888888));
2283 assertIntEquals(0, $noinline$intAnd0x17fffToShort(Integer.MIN_VALUE));
2284 assertIntEquals(Short.MAX_VALUE, $noinline$intAnd0x17fffToShort(Integer.MAX_VALUE));
Vladimir Marko625090f2016-03-14 18:00:05 +00002285
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002286 assertDoubleEquals(0.0, $noinline$shortAnd0xffffToShortToDouble((short) 0));
2287 assertDoubleEquals(1.0, $noinline$shortAnd0xffffToShortToDouble((short) 1));
2288 assertDoubleEquals(-2.0, $noinline$shortAnd0xffffToShortToDouble((short) -2));
2289 assertDoubleEquals(12345.0, $noinline$shortAnd0xffffToShortToDouble((short) 12345));
2290 assertDoubleEquals((double)Short.MAX_VALUE,
2291 $noinline$shortAnd0xffffToShortToDouble(Short.MAX_VALUE));
2292 assertDoubleEquals((double)Short.MIN_VALUE,
2293 $noinline$shortAnd0xffffToShortToDouble(Short.MIN_VALUE));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002294
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002295 assertIntEquals(13, $noinline$intReverseCondition(41));
2296 assertIntEquals(13, $noinline$intReverseConditionNaN(-5));
Anton Shaminbdd79352016-02-15 12:48:36 +06002297
David Brazdilf02c3cf2016-02-29 09:14:51 +00002298 for (String condition : new String[] { "Equal", "NotEqual" }) {
2299 for (String constant : new String[] { "True", "False" }) {
2300 for (String side : new String[] { "Rhs", "Lhs" }) {
2301 String name = condition + constant + side;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002302 assertIntEquals(5, $noinline$runSmaliTest(name, true));
2303 assertIntEquals(3, $noinline$runSmaliTest(name, false));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002304 }
2305 }
2306 }
Alexandre Rames50518442016-06-27 11:39:19 +01002307
Anton Kirilove14dc862016-05-13 17:56:15 +01002308 assertIntEquals(0, $noinline$runSmaliTestConst("AddSubConst", 1));
2309 assertIntEquals(3, $noinline$runSmaliTestConst("SubAddConst", 2));
2310 assertIntEquals(-16, $noinline$runSmaliTestConst("SubSubConst1", 3));
2311 assertIntEquals(-5, $noinline$runSmaliTestConst("SubSubConst2", 4));
2312 assertIntEquals(26, $noinline$runSmaliTestConst("SubSubConst3", 5));
Alexandre Rames50518442016-06-27 11:39:19 +01002313 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3));
2314 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3 + 32));
2315 assertLongEquals(0xffffffffffffeaf3L, $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50));
2316 assertLongEquals(0xffffffffffffeaf3L, $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50 + 64));
2317 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10));
2318 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10 + 128));
2319 assertLongEquals(0xaf37bc048d159e24L, $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2));
2320 assertLongEquals(0xaf37bc048d159e24L, $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2 + 256));
2321 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13));
2322 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13 + 512));
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002323
2324 assertIntEquals(654321, $noinline$intAddSubSimplifyArg1(arg, 654321));
2325 assertIntEquals(arg, $noinline$intAddSubSimplifyArg2(arg, 654321));
2326 assertIntEquals(arg, $noinline$intSubAddSimplifyLeft(arg, 654321));
2327 assertIntEquals(arg, $noinline$intSubAddSimplifyRight(arg, 654321));
2328 assertFloatEquals(654321.125f, $noinline$floatAddSubSimplifyArg1(floatArg, 654321.125f));
2329 assertFloatEquals(floatArg, $noinline$floatAddSubSimplifyArg2(floatArg, 654321.125f));
2330 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyLeft(floatArg, 654321.125f));
2331 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyRight(floatArg, 654321.125f));
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002332 }
Mark Mendellf6529172015-11-17 11:16:56 -05002333
David Brazdilf02c3cf2016-02-29 09:14:51 +00002334 private static boolean $inline$true() { return true; }
2335 private static boolean $inline$false() { return false; }
2336
Mark Mendellf6529172015-11-17 11:16:56 -05002337 public static boolean booleanField;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002338}