blob: 40baa15938c43f053f4d9430b1a105344e646280 [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
Sebastien Hertz55418e12016-09-23 16:51:42 +02001205 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) dead_code_elimination$final (after)
1206 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1207 /// CHECK-DAG: Return [<<Arg>>]
1208
David Brazdil769c9e52015-04-27 13:54:09 +01001209 public static boolean NegateValue(boolean arg) {
1210 return !arg;
1211 }
1212
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001213 public static boolean $noinline$NotNotBool(boolean arg) {
1214 if (doThrow) { throw new Error(); }
David Brazdil769c9e52015-04-27 13:54:09 +01001215 return !(NegateValue(arg));
David Brazdil0d13fee2015-04-17 14:52:19 +01001216 }
1217
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001218 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001219 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1220 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
1221 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>]
1222 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001223
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001224 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001225 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1226 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5
1227 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>]
1228 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001229
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001230 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001231 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001232
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001233 public static float $noinline$Div2(float arg) {
1234 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001235 return arg / 2.0f;
1236 }
1237
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001238 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001239 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1240 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
1241 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>]
1242 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001243
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001244 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001245 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1246 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5
1247 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>]
1248 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001249
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001250 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001251 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001252 public static double $noinline$Div2(double arg) {
1253 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001254 return arg / 2.0;
1255 }
1256
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001257 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001258 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1259 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25
1260 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>]
1261 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001262
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001263 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001264 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1265 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4
1266 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>]
1267 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001268
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001269 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001270 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001271
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001272 public static float $noinline$DivMP25(float arg) {
1273 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001274 return arg / -0.25f;
1275 }
1276
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001277 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001278 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1279 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25
1280 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>]
1281 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001282
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001283 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001284 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1285 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4
1286 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>]
1287 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001288
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001289 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001290 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001291 public static double $noinline$DivMP25(double arg) {
1292 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001293 return arg / -0.25f;
1294 }
1295
Alexandre Rames38db7852015-11-20 15:02:45 +00001296 /**
1297 * Test strength reduction of factors of the form (2^n + 1).
1298 */
1299
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001300 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001301 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1302 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
1303 /// CHECK: Mul [<<Arg>>,<<Const9>>]
1304
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001305 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001306 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1307 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1308 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>]
1309 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>]
1310
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001311 public static int $noinline$mulPow2Plus1(int arg) {
1312 if (doThrow) { throw new Error(); }
Alexandre Rames38db7852015-11-20 15:02:45 +00001313 return arg * 9;
1314 }
1315
Alexandre Rames38db7852015-11-20 15:02:45 +00001316 /**
1317 * Test strength reduction of factors of the form (2^n - 1).
1318 */
1319
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001320 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001321 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1322 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31
David Brazdil57e863c2016-01-11 10:27:13 +00001323 /// CHECK: Mul [<<Const31>>,<<Arg>>]
Alexandre Rames38db7852015-11-20 15:02:45 +00001324
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001325 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001326 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1327 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1328 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>]
1329 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>]
1330
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001331 public static long $noinline$mulPow2Minus1(long arg) {
1332 if (doThrow) { throw new Error(); }
Alexandre Rames38db7852015-11-20 15:02:45 +00001333 return arg * 31;
1334 }
1335
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001336 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001337 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdilf02c3cf2016-02-29 09:14:51 +00001338 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1339 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001340 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
Mark Mendellf6529172015-11-17 11:16:56 -05001341 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1342 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +00001343 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1344 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001345
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001346 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_bce (after)
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001347 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001348 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1349 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1350 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1351 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1352 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001353
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001354 public static int $noinline$booleanFieldNotEqualOne() {
1355 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001356 return (booleanField == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001357 }
1358
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001359 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001360 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdilf02c3cf2016-02-29 09:14:51 +00001361 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1362 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001363 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
Mark Mendellf6529172015-11-17 11:16:56 -05001364 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdilf02c3cf2016-02-29 09:14:51 +00001365 /// CHECK-DAG: <<NE:z\d+>> Equal [<<Field>>,<<Const0>>]
1366 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1367 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001368
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001369 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_bce (after)
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001370 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001371 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1372 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1373 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1374 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1375 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001376
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001377 public static int $noinline$booleanFieldEqualZero() {
1378 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001379 return (booleanField != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001380 }
1381
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001382 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001383 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001384 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
Mark Mendellf6529172015-11-17 11:16:56 -05001385 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +00001386 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001387 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001388 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1389 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1390 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001391 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001392 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1393 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001394
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001395 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_bce (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001396 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001397 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001398 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001399 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1400 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001401 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001402 /// CHECK-DAG: Return [<<Result>>]
1403 // Note that we match `LE` from Select because there are two identical
1404 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001405
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001406 public static int $noinline$intConditionNotEqualOne(int i) {
1407 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001408 return ((i > 42) == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001409 }
1410
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001411 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001412 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1413 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001414 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1415 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001416 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001417 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1418 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1419 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
1420 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>]
1421 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1422 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001423
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001424 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_bce (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001425 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001426 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001427 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001428 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1429 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001430 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001431 /// CHECK-DAG: Return [<<Result>>]
1432 // Note that we match `LE` from Select because there are two identical
1433 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001434
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001435 public static int $noinline$intConditionEqualZero(int i) {
1436 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001437 return ((i > 42) != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001438 }
1439
1440 // Test that conditions on float/double are not flipped.
1441
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001442 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001443 /// CHECK: LessThanOrEqual
1444
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001445 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001446 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1447 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1448 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1449 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
1450 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1451 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1452 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001453
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001454 public static int $noinline$floatConditionNotEqualOne(float f) {
1455 if (doThrow) { throw new Error(); }
Mark Mendellf6529172015-11-17 11:16:56 -05001456 return ((f > 42.0f) == true) ? 13 : 54;
1457 }
1458
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001459 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001460 /// CHECK: LessThanOrEqual
1461
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001462 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001463 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1464 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1465 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1466 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1467 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1468 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1469 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001470
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001471 public static int $noinline$doubleConditionEqualZero(double d) {
1472 if (doThrow) { throw new Error(); }
Mark Mendellf6529172015-11-17 11:16:56 -05001473 return ((d > 42.0) != false) ? 13 : 54;
1474 }
Alexandre Rames38db7852015-11-20 15:02:45 +00001475
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001476 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001477 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1478 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1479 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1480 /// CHECK-DAG: Return [<<Int>>]
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-DAG: <<Arg:i\d+>> ParameterValue
1484 /// CHECK-DAG: Return [<<Arg>>]
1485
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001486 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001487 /// CHECK-NOT: TypeConversion
1488
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001489 public static int $noinline$intToDoubleToInt(int value) {
1490 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001491 // Lossless conversion followed by a conversion back.
1492 return (int) (double) value;
1493 }
1494
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001495 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001496 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1497 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1498 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
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: <<Arg:i\d+>> ParameterValue
1502 /// CHECK-DAG: {{d\d+}} TypeConversion [<<Arg>>]
1503
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001504 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001505 /// CHECK-DAG: TypeConversion
1506 /// CHECK-NOT: TypeConversion
1507
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001508 public static String $noinline$intToDoubleToIntPrint(int value) {
1509 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001510 // Lossless conversion followed by a conversion back
1511 // with another use of the intermediate result.
1512 double d = (double) value;
1513 int i = (int) d;
1514 return "d=" + d + ", i=" + i;
1515 }
1516
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001517 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001518 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1519 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1520 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1521 /// CHECK-DAG: Return [<<Int>>]
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-DAG: <<Arg:b\d+>> ParameterValue
1525 /// CHECK-DAG: Return [<<Arg>>]
1526
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001527 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001528 /// CHECK-NOT: TypeConversion
1529
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001530 public static int $noinline$byteToDoubleToInt(byte value) {
1531 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001532 // Lossless conversion followed by another conversion, use implicit conversion.
1533 return (int) (double) value;
1534 }
1535
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001536 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001537 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1538 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1539 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1540 /// CHECK-DAG: Return [<<Int>>]
1541
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001542 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001543 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1544 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1545 /// CHECK-DAG: Return [<<Int>>]
1546
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001547 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001548 /// CHECK-DAG: TypeConversion
1549 /// CHECK-NOT: TypeConversion
1550
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001551 public static int $noinline$floatToDoubleToInt(float value) {
1552 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001553 // Lossless conversion followed by another conversion.
1554 return (int) (double) value;
1555 }
1556
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001557 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001558 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1559 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1560 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1561
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001562 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001563 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1564 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1565 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1566
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001567 public static String $noinline$floatToDoubleToIntPrint(float value) {
1568 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001569 // Lossless conversion followed by another conversion with
1570 // an extra use of the intermediate result.
1571 double d = (double) value;
1572 int i = (int) d;
1573 return "d=" + d + ", i=" + i;
1574 }
1575
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001576 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001577 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1578 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1579 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1580 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1581 /// CHECK-DAG: Return [<<Short>>]
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-DAG: <<Arg:b\d+>> ParameterValue
1585 /// CHECK-DAG: Return [<<Arg>>]
1586
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001587 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001588 /// CHECK-NOT: TypeConversion
1589
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001590 public static short $noinline$byteToDoubleToShort(byte value) {
1591 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001592 // Originally, this is byte->double->int->short. The first conversion is lossless,
1593 // so we merge this with the second one to byte->int which we omit as it's an implicit
1594 // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1595 return (short) (double) value;
1596 }
1597
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001598 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001599 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1600 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1601 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1602 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1603 /// CHECK-DAG: Return [<<Short>>]
1604
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001605 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001606 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1607 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Arg>>]
1608 /// CHECK-DAG: Return [<<Short>>]
1609
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001610 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001611 /// CHECK-DAG: TypeConversion
1612 /// CHECK-NOT: TypeConversion
1613
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001614 public static short $noinline$charToDoubleToShort(char value) {
1615 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001616 // Originally, this is char->double->int->short. The first conversion is lossless,
1617 // so we merge this with the second one to char->int which we omit as it's an implicit
1618 // conversion. Then we are left with the resulting char->short conversion.
1619 return (short) (double) value;
1620 }
1621
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001622 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001623 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1624 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1625 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1626 /// CHECK-DAG: Return [<<Short>>]
1627
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001628 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001629 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1630 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1631 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1632 /// CHECK-DAG: Return [<<Short>>]
1633
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001634 public static short $noinline$floatToIntToShort(float value) {
1635 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001636 // Lossy FP to integral conversion followed by another conversion: no simplification.
1637 return (short) value;
1638 }
1639
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001640 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001641 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1642 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1643 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1644 /// CHECK-DAG: Return [<<Int>>]
1645
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001646 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001647 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1648 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1649 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1650 /// CHECK-DAG: Return [<<Int>>]
1651
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001652 public static int $noinline$intToFloatToInt(int value) {
1653 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001654 // Lossy integral to FP conversion followed another conversion: no simplification.
1655 return (int) (float) value;
1656 }
1657
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001658 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001659 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1660 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1661 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1662 /// CHECK-DAG: Return [<<Double>>]
1663
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001664 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001665 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1666 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1667 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1668 /// CHECK-DAG: Return [<<Double>>]
1669
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001670 public static double $noinline$longToIntToDouble(long value) {
1671 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001672 // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1673 return (double) (int) value;
1674 }
1675
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001676 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001677 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1678 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1679 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1680 /// CHECK-DAG: Return [<<Long>>]
1681
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001682 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001683 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1684 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1685 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1686 /// CHECK-DAG: Return [<<Long>>]
1687
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001688 public static long $noinline$longToIntToLong(long value) {
1689 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001690 // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1691 return (long) (int) value;
1692 }
1693
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001694 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001695 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1696 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1697 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Char>>]
1698 /// CHECK-DAG: Return [<<Short>>]
1699
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001700 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001701 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1702 /// CHECK-DAG: Return [<<Arg>>]
1703
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001704 public static short $noinline$shortToCharToShort(short value) {
1705 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001706 // Integral conversion followed by non-widening integral conversion to original type.
1707 return (short) (char) value;
1708 }
1709
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001710 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001711 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1712 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1713 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Long>>]
1714 /// CHECK-DAG: Return [<<Int>>]
1715
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001716 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001717 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1718 /// CHECK-DAG: Return [<<Arg>>]
1719
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001720 public static int $noinline$shortToLongToInt(short value) {
1721 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001722 // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1723 return (int) (long) value;
1724 }
1725
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001726 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001727 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1728 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1729 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Char>>]
1730 /// CHECK-DAG: Return [<<Byte>>]
1731
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001732 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001733 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1734 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1735 /// CHECK-DAG: Return [<<Byte>>]
1736
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001737 public static byte $noinline$shortToCharToByte(short value) {
1738 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001739 // Integral conversion followed by non-widening integral conversion losing bits
1740 // from the original type. Simplify to use only one conversion.
1741 return (byte) (char) value;
1742 }
1743
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001744 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001745 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1746 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1747 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1748
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001749 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001750 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1751 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1752 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1753
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001754 public static String $noinline$shortToCharToBytePrint(short value) {
1755 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001756 // Integral conversion followed by non-widening integral conversion losing bits
1757 // from the original type with an extra use of the intermediate result.
1758 char c = (char) value;
1759 byte b = (byte) c;
1760 return "c=" + ((int) c) + ", b=" + ((int) b); // implicit conversions.
1761 }
1762
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001763 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001764 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1765 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 255
1766 /// CHECK-DAG: <<And:j\d+>> And [<<Mask>>,<<Arg>>]
1767 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<And>>]
1768 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Int>>]
1769 /// CHECK-DAG: Return [<<Byte>>]
1770
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001771 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001772 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1773 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1774 /// CHECK-DAG: Return [<<Byte>>]
1775
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001776 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001777 /// CHECK-NOT: And
1778
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001779 public static byte $noinline$longAnd0xffToByte(long value) {
1780 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001781 return (byte) (value & 0xff);
1782 }
1783
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001784 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001785 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1786 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 131071
1787 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1788 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<And>>]
1789 /// CHECK-DAG: Return [<<Char>>]
1790
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001791 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001792 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1793 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1794 /// CHECK-DAG: Return [<<Char>>]
1795
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001796 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001797 /// CHECK-NOT: And
1798
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001799 public static char $noinline$intAnd0x1ffffToChar(int value) {
1800 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001801 // Keeping all significant bits and one more.
1802 return (char) (value & 0x1ffff);
1803 }
1804
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001805 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001806 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1807 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1808 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1809 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1810 /// CHECK-DAG: Return [<<Short>>]
1811
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001812 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001813 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1814 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1815 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1816 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1817 /// CHECK-DAG: Return [<<Short>>]
1818
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001819 public static short $noinline$intAnd0x17fffToShort(int value) {
1820 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001821 // No simplification: clearing a significant bit.
1822 return (short) (value & 0x17fff);
1823 }
1824
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001825 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (before)
Vladimir Marko625090f2016-03-14 18:00:05 +00001826 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1827 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 65535
1828 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1829 /// CHECK-DAG: <<Same:s\d+>> TypeConversion [<<And>>]
1830 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Same>>]
1831 /// CHECK-DAG: Return [<<Double>>]
1832
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001833 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (after)
Vladimir Marko625090f2016-03-14 18:00:05 +00001834 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1835 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1836 /// CHECK-DAG: Return [<<Double>>]
1837
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001838 public static double $noinline$shortAnd0xffffToShortToDouble(short value) {
1839 if (doThrow) { throw new Error(); }
Vladimir Marko625090f2016-03-14 18:00:05 +00001840 short same = (short) (value & 0xffff);
1841 return (double) same;
1842 }
1843
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001844 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001845 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1846 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1847 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Const42>>,<<Arg>>]
1848
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001849 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001850 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1851 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1852 /// CHECK-DAG: <<GE:z\d+>> GreaterThanOrEqual [<<Arg>>,<<Const42>>]
1853
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001854 public static int $noinline$intReverseCondition(int i) {
1855 if (doThrow) { throw new Error(); }
Anton Shaminbdd79352016-02-15 12:48:36 +06001856 return (42 > i) ? 13 : 54;
1857 }
1858
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001859 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001860 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1861 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1862 /// CHECK-DAG: <<CMP:i\d+>> Compare [<<Const42>>,<<Result>>]
1863
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001864 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001865 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1866 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1867 /// CHECK-DAG: <<EQ:z\d+>> Equal [<<Result>>,<<Const42>>]
1868
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001869 public static int $noinline$intReverseConditionNaN(int i) {
1870 if (doThrow) { throw new Error(); }
Anton Shaminbdd79352016-02-15 12:48:36 +06001871 return (42 != Math.sqrt(i)) ? 13 : 54;
1872 }
1873
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001874 public static int $noinline$runSmaliTest(String name, boolean input) {
1875 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001876 try {
1877 Class<?> c = Class.forName("SmaliTests");
Andreas Gampe166aaee2016-07-18 08:27:23 -07001878 Method m = c.getMethod(name, boolean.class);
David Brazdilf02c3cf2016-02-29 09:14:51 +00001879 return (Integer) m.invoke(null, input);
1880 } catch (Exception ex) {
1881 throw new Error(ex);
1882 }
1883 }
1884
Anton Kirilove14dc862016-05-13 17:56:15 +01001885 public static int $noinline$runSmaliTestConst(String name, int arg) {
1886 if (doThrow) { throw new Error(); }
1887 try {
1888 Class<?> c = Class.forName("SmaliTests");
1889 Method m = c.getMethod(name, int.class);
1890 return (Integer) m.invoke(null, arg);
1891 } catch (Exception ex) {
1892 throw new Error(ex);
1893 }
1894 }
1895
Alexandre Rames50518442016-06-27 11:39:19 +01001896 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1897 /// CHECK: <<Value:i\d+>> ParameterValue
1898 /// CHECK: <<Shift:i\d+>> ParameterValue
1899 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1900 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1901 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<And>>]
1902 /// CHECK-DAG: Return [<<Shl>>]
1903
1904 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1905 /// CHECK: <<Value:i\d+>> ParameterValue
1906 /// CHECK: <<Shift:i\d+>> ParameterValue
1907 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<Shift>>]
1908 /// CHECK-DAG: Return [<<Shl>>]
1909
1910 public static int $noinline$intUnnecessaryShiftMasking(int value, int shift) {
1911 if (doThrow) { throw new Error(); }
1912 return value << (shift & 31);
1913 }
1914
1915 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (before)
1916 /// CHECK: <<Value:j\d+>> ParameterValue
1917 /// CHECK: <<Shift:i\d+>> ParameterValue
1918 /// CHECK-DAG: <<Const63:i\d+>> IntConstant 63
1919 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const63>>]
1920 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<And>>]
1921 /// CHECK-DAG: Return [<<Shr>>]
1922
1923 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (after)
1924 /// CHECK: <<Value:j\d+>> ParameterValue
1925 /// CHECK: <<Shift:i\d+>> ParameterValue
1926 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<Shift>>]
1927 /// CHECK-DAG: Return [<<Shr>>]
1928
1929 public static long $noinline$longUnnecessaryShiftMasking(long value, int shift) {
1930 if (doThrow) { throw new Error(); }
1931 return value >> (shift & 63);
1932 }
1933
1934 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (before)
1935 /// CHECK: <<Value:i\d+>> ParameterValue
1936 /// CHECK: <<Shift:i\d+>> ParameterValue
1937 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
1938 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const255>>]
1939 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<And>>]
1940 /// CHECK-DAG: Return [<<UShr>>]
1941
1942 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (after)
1943 /// CHECK: <<Value:i\d+>> ParameterValue
1944 /// CHECK: <<Shift:i\d+>> ParameterValue
1945 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<Shift>>]
1946 /// CHECK-DAG: Return [<<UShr>>]
1947
1948 public static int $noinline$intUnnecessaryWiderShiftMasking(int value, int shift) {
1949 if (doThrow) { throw new Error(); }
1950 return value >>> (shift & 0xff);
1951 }
1952
1953 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (before)
1954 /// CHECK: <<Value:j\d+>> ParameterValue
1955 /// CHECK: <<Shift:i\d+>> ParameterValue
1956 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1957 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
1958 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
1959 /// CHECK-DAG: Return [<<Shl>>]
1960
1961 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (after)
1962 /// CHECK: <<Value:j\d+>> ParameterValue
1963 /// CHECK: <<Shift:i\d+>> ParameterValue
1964 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1965 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
1966 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
1967 /// CHECK-DAG: Return [<<Shl>>]
1968
1969 public static long $noinline$longSmallerShiftMasking(long value, int shift) {
1970 if (doThrow) { throw new Error(); }
1971 return value << (shift & 3);
1972 }
1973
1974 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1975 /// CHECK: <<Value:i\d+>> ParameterValue
1976 /// CHECK: <<Shift:i\d+>> ParameterValue
1977 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1978 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1979 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<And>>]
1980 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
1981 /// CHECK-DAG: Return [<<Add>>]
1982
1983 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1984 /// CHECK: <<Value:i\d+>> ParameterValue
1985 /// CHECK: <<Shift:i\d+>> ParameterValue
1986 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1987 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1988 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<Shift>>]
1989 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
1990 /// CHECK-DAG: Return [<<Add>>]
1991
1992 public static int $noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift) {
1993 if (doThrow) { throw new Error(); }
1994 int temp = shift & 31;
1995 return (value >> temp) + temp;
1996 }
1997
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06001998 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (before)
1999 /// CHECK: <<X:i\d+>> ParameterValue
2000 /// CHECK: <<Y:i\d+>> ParameterValue
2001 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2002 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<X>>]
2003 /// CHECK-DAG: Return [<<Res>>]
2004
2005 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (after)
2006 /// CHECK: <<X:i\d+>> ParameterValue
2007 /// CHECK: <<Y:i\d+>> ParameterValue
2008 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2009 /// CHECK-DAG: Return [<<Y>>]
2010
2011 public static int $noinline$intAddSubSimplifyArg1(int x, int y) {
2012 if (doThrow) { throw new Error(); }
2013 int sum = x + y;
2014 return sum - x;
2015 }
2016
2017 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (before)
2018 /// CHECK: <<X:i\d+>> ParameterValue
2019 /// CHECK: <<Y:i\d+>> ParameterValue
2020 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2021 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<Y>>]
2022 /// CHECK-DAG: Return [<<Res>>]
2023
2024 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (after)
2025 /// CHECK: <<X:i\d+>> ParameterValue
2026 /// CHECK: <<Y:i\d+>> ParameterValue
2027 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2028 /// CHECK-DAG: Return [<<X>>]
2029
2030 public static int $noinline$intAddSubSimplifyArg2(int x, int y) {
2031 if (doThrow) { throw new Error(); }
2032 int sum = x + y;
2033 return sum - y;
2034 }
2035
2036 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (before)
2037 /// CHECK: <<X:i\d+>> ParameterValue
2038 /// CHECK: <<Y:i\d+>> ParameterValue
2039 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2040 /// CHECK-DAG: <<Res:i\d+>> Add [<<Sub>>,<<Y>>]
2041 /// CHECK-DAG: Return [<<Res>>]
2042
2043 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (after)
2044 /// CHECK: <<X:i\d+>> ParameterValue
2045 /// CHECK: <<Y:i\d+>> ParameterValue
2046 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2047 /// CHECK-DAG: Return [<<X>>]
2048
2049 public static int $noinline$intSubAddSimplifyLeft(int x, int y) {
2050 if (doThrow) { throw new Error(); }
2051 int sub = x - y;
2052 return sub + y;
2053 }
2054
2055 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (before)
2056 /// CHECK: <<X:i\d+>> ParameterValue
2057 /// CHECK: <<Y:i\d+>> ParameterValue
2058 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2059 /// CHECK-DAG: <<Res:i\d+>> Add [<<Y>>,<<Sub>>]
2060 /// CHECK-DAG: Return [<<Res>>]
2061
2062 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (after)
2063 /// CHECK: <<X:i\d+>> ParameterValue
2064 /// CHECK: <<Y:i\d+>> ParameterValue
2065 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2066 /// CHECK-DAG: Return [<<X>>]
2067
2068 public static int $noinline$intSubAddSimplifyRight(int x, int y) {
2069 if (doThrow) { throw new Error(); }
2070 int sub = x - y;
2071 return y + sub;
2072 }
2073
2074 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (before)
2075 /// CHECK: <<X:f\d+>> ParameterValue
2076 /// CHECK: <<Y:f\d+>> ParameterValue
2077 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2078 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2079 /// CHECK-DAG: Return [<<Res>>]
2080
2081 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (after)
2082 /// CHECK: <<X:f\d+>> ParameterValue
2083 /// CHECK: <<Y:f\d+>> ParameterValue
2084 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2085 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2086 /// CHECK-DAG: Return [<<Res>>]
2087
2088 public static float $noinline$floatAddSubSimplifyArg1(float x, float y) {
2089 if (doThrow) { throw new Error(); }
2090 float sum = x + y;
2091 return sum - x;
2092 }
2093
2094 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (before)
2095 /// CHECK: <<X:f\d+>> ParameterValue
2096 /// CHECK: <<Y:f\d+>> ParameterValue
2097 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2098 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2099 /// CHECK-DAG: Return [<<Res>>]
2100
2101 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (after)
2102 /// CHECK: <<X:f\d+>> ParameterValue
2103 /// CHECK: <<Y:f\d+>> ParameterValue
2104 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2105 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2106 /// CHECK-DAG: Return [<<Res>>]
2107
2108 public static float $noinline$floatAddSubSimplifyArg2(float x, float y) {
2109 if (doThrow) { throw new Error(); }
2110 float sum = x + y;
2111 return sum - y;
2112 }
2113
2114 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (before)
2115 /// CHECK: <<X:f\d+>> ParameterValue
2116 /// CHECK: <<Y:f\d+>> ParameterValue
2117 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2118 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2119 /// CHECK-DAG: Return [<<Res>>]
2120
2121 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (after)
2122 /// CHECK: <<X:f\d+>> ParameterValue
2123 /// CHECK: <<Y:f\d+>> ParameterValue
2124 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2125 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2126 /// CHECK-DAG: Return [<<Res>>]
2127
2128 public static float $noinline$floatSubAddSimplifyLeft(float x, float y) {
2129 if (doThrow) { throw new Error(); }
2130 float sub = x - y;
2131 return sub + y;
2132 }
2133
2134 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (before)
2135 /// CHECK: <<X:f\d+>> ParameterValue
2136 /// CHECK: <<Y:f\d+>> ParameterValue
2137 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2138 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2139 /// CHECK-DAG: Return [<<Res>>]
2140
2141 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (after)
2142 /// CHECK: <<X:f\d+>> ParameterValue
2143 /// CHECK: <<Y:f\d+>> ParameterValue
2144 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2145 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2146 /// CHECK-DAG: Return [<<Res>>]
2147
2148 public static float $noinline$floatSubAddSimplifyRight(float x, float y) {
2149 if (doThrow) { throw new Error(); }
2150 float sub = x - y;
2151 return y + sub;
2152 }
2153
2154 public static void main(String[] args) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002155 int arg = 123456;
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002156 float floatArg = 123456.125f;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002157
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002158 assertLongEquals(arg, $noinline$Add0(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002159 assertIntEquals(5, $noinline$AddAddSubAddConst(1));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002160 assertIntEquals(arg, $noinline$AndAllOnes(arg));
2161 assertLongEquals(arg, $noinline$Div1(arg));
2162 assertIntEquals(-arg, $noinline$DivN1(arg));
2163 assertLongEquals(arg, $noinline$Mul1(arg));
2164 assertIntEquals(-arg, $noinline$MulN1(arg));
2165 assertLongEquals((128 * arg), $noinline$MulPowerOfTwo128(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002166 assertLongEquals(2640, $noinline$MulMulMulConst(2));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002167 assertIntEquals(arg, $noinline$Or0(arg));
2168 assertLongEquals(arg, $noinline$OrSame(arg));
2169 assertIntEquals(arg, $noinline$Shl0(arg));
2170 assertLongEquals(arg, $noinline$Shr0(arg));
2171 assertLongEquals(arg, $noinline$Shr64(arg));
2172 assertLongEquals(arg, $noinline$Sub0(arg));
2173 assertIntEquals(-arg, $noinline$SubAliasNeg(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002174 assertIntEquals(9, $noinline$SubAddConst1(2));
2175 assertIntEquals(-2, $noinline$SubAddConst2(3));
2176 assertLongEquals(3, $noinline$SubSubConst(4));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002177 assertLongEquals(arg, $noinline$UShr0(arg));
2178 assertIntEquals(arg, $noinline$Xor0(arg));
2179 assertIntEquals(~arg, $noinline$XorAllOnes(arg));
2180 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs1(arg, arg + 1));
2181 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs2(arg, arg + 1));
2182 assertLongEquals(-(2 * arg + 1), $noinline$AddNegs3(arg, arg + 1));
2183 assertLongEquals(1, $noinline$AddNeg1(arg, arg + 1));
2184 assertLongEquals(-1, $noinline$AddNeg2(arg, arg + 1));
2185 assertLongEquals(arg, $noinline$NegNeg1(arg));
2186 assertIntEquals(0, $noinline$NegNeg2(arg));
2187 assertLongEquals(arg, $noinline$NegNeg3(arg));
2188 assertIntEquals(1, $noinline$NegSub1(arg, arg + 1));
2189 assertIntEquals(1, $noinline$NegSub2(arg, arg + 1));
2190 assertLongEquals(arg, $noinline$NotNot1(arg));
2191 assertIntEquals(-1, $noinline$NotNot2(arg));
2192 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg1(arg, arg + 1));
2193 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg2(arg, arg + 1));
2194 assertLongEquals(-(2 * arg + 1), $noinline$SubNeg3(arg, arg + 1));
2195 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2196 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2197 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2198 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2199 assertBooleanEquals(true, $noinline$NotNotBool(true));
2200 assertBooleanEquals(false, $noinline$NotNotBool(false));
2201 assertFloatEquals(50.0f, $noinline$Div2(100.0f));
2202 assertDoubleEquals(75.0, $noinline$Div2(150.0));
2203 assertFloatEquals(-400.0f, $noinline$DivMP25(100.0f));
2204 assertDoubleEquals(-600.0, $noinline$DivMP25(150.0));
2205 assertIntEquals(0xc, $noinline$UShr28And15(0xc1234567));
2206 assertLongEquals(0xcL, $noinline$UShr60And15(0xc123456787654321L));
2207 assertIntEquals(0x4, $noinline$UShr28And7(0xc1234567));
2208 assertLongEquals(0x4L, $noinline$UShr60And7(0xc123456787654321L));
2209 assertIntEquals(0xc1, $noinline$Shr24And255(0xc1234567));
2210 assertLongEquals(0xc1L, $noinline$Shr56And255(0xc123456787654321L));
2211 assertIntEquals(0x41, $noinline$Shr24And127(0xc1234567));
2212 assertLongEquals(0x41L, $noinline$Shr56And127(0xc123456787654321L));
2213 assertIntEquals(0, $noinline$mulPow2Plus1(0));
2214 assertIntEquals(9, $noinline$mulPow2Plus1(1));
2215 assertIntEquals(18, $noinline$mulPow2Plus1(2));
2216 assertIntEquals(900, $noinline$mulPow2Plus1(100));
2217 assertIntEquals(111105, $noinline$mulPow2Plus1(12345));
2218 assertLongEquals(0, $noinline$mulPow2Minus1(0));
2219 assertLongEquals(31, $noinline$mulPow2Minus1(1));
2220 assertLongEquals(62, $noinline$mulPow2Minus1(2));
2221 assertLongEquals(3100, $noinline$mulPow2Minus1(100));
2222 assertLongEquals(382695, $noinline$mulPow2Minus1(12345));
Mark Mendellf6529172015-11-17 11:16:56 -05002223
2224 booleanField = false;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002225 assertIntEquals($noinline$booleanFieldNotEqualOne(), 54);
2226 assertIntEquals($noinline$booleanFieldEqualZero(), 54);
Mark Mendellf6529172015-11-17 11:16:56 -05002227 booleanField = true;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002228 assertIntEquals(13, $noinline$booleanFieldNotEqualOne());
2229 assertIntEquals(13, $noinline$booleanFieldEqualZero());
2230 assertIntEquals(54, $noinline$intConditionNotEqualOne(6));
2231 assertIntEquals(13, $noinline$intConditionNotEqualOne(43));
2232 assertIntEquals(54, $noinline$intConditionEqualZero(6));
2233 assertIntEquals(13, $noinline$intConditionEqualZero(43));
2234 assertIntEquals(54, $noinline$floatConditionNotEqualOne(6.0f));
2235 assertIntEquals(13, $noinline$floatConditionNotEqualOne(43.0f));
2236 assertIntEquals(54, $noinline$doubleConditionEqualZero(6.0));
2237 assertIntEquals(13, $noinline$doubleConditionEqualZero(43.0));
Vladimir Markob52bbde2016-02-12 12:06:05 +00002238
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002239 assertIntEquals(1234567, $noinline$intToDoubleToInt(1234567));
2240 assertIntEquals(Integer.MIN_VALUE, $noinline$intToDoubleToInt(Integer.MIN_VALUE));
2241 assertIntEquals(Integer.MAX_VALUE, $noinline$intToDoubleToInt(Integer.MAX_VALUE));
2242 assertStringEquals("d=7654321.0, i=7654321", $noinline$intToDoubleToIntPrint(7654321));
2243 assertIntEquals(12, $noinline$byteToDoubleToInt((byte) 12));
2244 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToInt(Byte.MIN_VALUE));
2245 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToInt(Byte.MAX_VALUE));
2246 assertIntEquals(11, $noinline$floatToDoubleToInt(11.3f));
2247 assertStringEquals("d=12.25, i=12", $noinline$floatToDoubleToIntPrint(12.25f));
2248 assertIntEquals(123, $noinline$byteToDoubleToShort((byte) 123));
2249 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToShort(Byte.MIN_VALUE));
2250 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToShort(Byte.MAX_VALUE));
2251 assertIntEquals(1234, $noinline$charToDoubleToShort((char) 1234));
2252 assertIntEquals(Character.MIN_VALUE, $noinline$charToDoubleToShort(Character.MIN_VALUE));
2253 assertIntEquals(/* sign-extended */ -1, $noinline$charToDoubleToShort(Character.MAX_VALUE));
2254 assertIntEquals(12345, $noinline$floatToIntToShort(12345.75f));
2255 assertIntEquals(Short.MAX_VALUE, $noinline$floatToIntToShort((float)(Short.MIN_VALUE - 1)));
2256 assertIntEquals(Short.MIN_VALUE, $noinline$floatToIntToShort((float)(Short.MAX_VALUE + 1)));
2257 assertIntEquals(-54321, $noinline$intToFloatToInt(-54321));
2258 assertDoubleEquals((double) 0x12345678, $noinline$longToIntToDouble(0x1234567812345678L));
2259 assertDoubleEquals(0.0, $noinline$longToIntToDouble(Long.MIN_VALUE));
2260 assertDoubleEquals(-1.0, $noinline$longToIntToDouble(Long.MAX_VALUE));
2261 assertLongEquals(0x0000000012345678L, $noinline$longToIntToLong(0x1234567812345678L));
2262 assertLongEquals(0xffffffff87654321L, $noinline$longToIntToLong(0x1234567887654321L));
2263 assertLongEquals(0L, $noinline$longToIntToLong(Long.MIN_VALUE));
2264 assertLongEquals(-1L, $noinline$longToIntToLong(Long.MAX_VALUE));
2265 assertIntEquals((short) -5678, $noinline$shortToCharToShort((short) -5678));
2266 assertIntEquals(Short.MIN_VALUE, $noinline$shortToCharToShort(Short.MIN_VALUE));
2267 assertIntEquals(Short.MAX_VALUE, $noinline$shortToCharToShort(Short.MAX_VALUE));
2268 assertIntEquals(5678, $noinline$shortToLongToInt((short) 5678));
2269 assertIntEquals(Short.MIN_VALUE, $noinline$shortToLongToInt(Short.MIN_VALUE));
2270 assertIntEquals(Short.MAX_VALUE, $noinline$shortToLongToInt(Short.MAX_VALUE));
2271 assertIntEquals(0x34, $noinline$shortToCharToByte((short) 0x1234));
2272 assertIntEquals(-0x10, $noinline$shortToCharToByte((short) 0x12f0));
2273 assertIntEquals(0, $noinline$shortToCharToByte(Short.MIN_VALUE));
2274 assertIntEquals(-1, $noinline$shortToCharToByte(Short.MAX_VALUE));
2275 assertStringEquals("c=1025, b=1", $noinline$shortToCharToBytePrint((short) 1025));
2276 assertStringEquals("c=1023, b=-1", $noinline$shortToCharToBytePrint((short) 1023));
2277 assertStringEquals("c=65535, b=-1", $noinline$shortToCharToBytePrint((short) -1));
Vladimir Marko8428bd32016-02-12 16:53:57 +00002278
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002279 assertIntEquals(0x21, $noinline$longAnd0xffToByte(0x1234432112344321L));
2280 assertIntEquals(0, $noinline$longAnd0xffToByte(Long.MIN_VALUE));
2281 assertIntEquals(-1, $noinline$longAnd0xffToByte(Long.MAX_VALUE));
2282 assertIntEquals(0x1234, $noinline$intAnd0x1ffffToChar(0x43211234));
2283 assertIntEquals(0, $noinline$intAnd0x1ffffToChar(Integer.MIN_VALUE));
2284 assertIntEquals(Character.MAX_VALUE, $noinline$intAnd0x1ffffToChar(Integer.MAX_VALUE));
2285 assertIntEquals(0x4321, $noinline$intAnd0x17fffToShort(0x87654321));
2286 assertIntEquals(0x0888, $noinline$intAnd0x17fffToShort(0x88888888));
2287 assertIntEquals(0, $noinline$intAnd0x17fffToShort(Integer.MIN_VALUE));
2288 assertIntEquals(Short.MAX_VALUE, $noinline$intAnd0x17fffToShort(Integer.MAX_VALUE));
Vladimir Marko625090f2016-03-14 18:00:05 +00002289
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002290 assertDoubleEquals(0.0, $noinline$shortAnd0xffffToShortToDouble((short) 0));
2291 assertDoubleEquals(1.0, $noinline$shortAnd0xffffToShortToDouble((short) 1));
2292 assertDoubleEquals(-2.0, $noinline$shortAnd0xffffToShortToDouble((short) -2));
2293 assertDoubleEquals(12345.0, $noinline$shortAnd0xffffToShortToDouble((short) 12345));
2294 assertDoubleEquals((double)Short.MAX_VALUE,
2295 $noinline$shortAnd0xffffToShortToDouble(Short.MAX_VALUE));
2296 assertDoubleEquals((double)Short.MIN_VALUE,
2297 $noinline$shortAnd0xffffToShortToDouble(Short.MIN_VALUE));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002298
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002299 assertIntEquals(13, $noinline$intReverseCondition(41));
2300 assertIntEquals(13, $noinline$intReverseConditionNaN(-5));
Anton Shaminbdd79352016-02-15 12:48:36 +06002301
David Brazdilf02c3cf2016-02-29 09:14:51 +00002302 for (String condition : new String[] { "Equal", "NotEqual" }) {
2303 for (String constant : new String[] { "True", "False" }) {
2304 for (String side : new String[] { "Rhs", "Lhs" }) {
2305 String name = condition + constant + side;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002306 assertIntEquals(5, $noinline$runSmaliTest(name, true));
2307 assertIntEquals(3, $noinline$runSmaliTest(name, false));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002308 }
2309 }
2310 }
Alexandre Rames50518442016-06-27 11:39:19 +01002311
Anton Kirilove14dc862016-05-13 17:56:15 +01002312 assertIntEquals(0, $noinline$runSmaliTestConst("AddSubConst", 1));
2313 assertIntEquals(3, $noinline$runSmaliTestConst("SubAddConst", 2));
2314 assertIntEquals(-16, $noinline$runSmaliTestConst("SubSubConst1", 3));
2315 assertIntEquals(-5, $noinline$runSmaliTestConst("SubSubConst2", 4));
2316 assertIntEquals(26, $noinline$runSmaliTestConst("SubSubConst3", 5));
Alexandre Rames50518442016-06-27 11:39:19 +01002317 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3));
2318 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3 + 32));
2319 assertLongEquals(0xffffffffffffeaf3L, $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50));
2320 assertLongEquals(0xffffffffffffeaf3L, $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50 + 64));
2321 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10));
2322 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10 + 128));
2323 assertLongEquals(0xaf37bc048d159e24L, $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2));
2324 assertLongEquals(0xaf37bc048d159e24L, $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2 + 256));
2325 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13));
2326 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13 + 512));
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002327
2328 assertIntEquals(654321, $noinline$intAddSubSimplifyArg1(arg, 654321));
2329 assertIntEquals(arg, $noinline$intAddSubSimplifyArg2(arg, 654321));
2330 assertIntEquals(arg, $noinline$intSubAddSimplifyLeft(arg, 654321));
2331 assertIntEquals(arg, $noinline$intSubAddSimplifyRight(arg, 654321));
2332 assertFloatEquals(654321.125f, $noinline$floatAddSubSimplifyArg1(floatArg, 654321.125f));
2333 assertFloatEquals(floatArg, $noinline$floatAddSubSimplifyArg2(floatArg, 654321.125f));
2334 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyLeft(floatArg, 654321.125f));
2335 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyRight(floatArg, 654321.125f));
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002336 }
Mark Mendellf6529172015-11-17 11:16:56 -05002337
David Brazdilf02c3cf2016-02-29 09:14:51 +00002338 private static boolean $inline$true() { return true; }
2339 private static boolean $inline$false() { return false; }
2340
Mark Mendellf6529172015-11-17 11:16:56 -05002341 public static boolean booleanField;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002342}