blob: ffce49d2e124a9f1bcd1d83b1bb2d28548de9217 [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
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010081 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +010082 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
83 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
84 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<ConstF>>]
85 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000086
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010087 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +010088 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
89 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000090
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010091 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +010092 /// CHECK-NOT: And
Alexandre Rames74417692015-04-09 15:21:41 +010093
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010094 public static int $noinline$AndAllOnes(int arg) {
95 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000096 return arg & -1;
97 }
98
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010099 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100100 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
101 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
102 /// CHECK-DAG: <<Const15:i\d+>> IntConstant 15
103 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
104 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const15>>]
105 /// CHECK-DAG: Return [<<And>>]
106
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100107 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100108 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
109 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
110 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
111 /// CHECK-DAG: Return [<<UShr>>]
112
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100113 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100114 /// CHECK-NOT: And
115
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100116 public static int $noinline$UShr28And15(int arg) {
117 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100118 return (arg >>> 28) & 15;
119 }
120
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100121 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100122 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
123 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
124 /// CHECK-DAG: <<Const15:j\d+>> LongConstant 15
125 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
126 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const15>>]
127 /// CHECK-DAG: Return [<<And>>]
128
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100129 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100130 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
131 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
132 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
133 /// CHECK-DAG: Return [<<UShr>>]
134
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100135 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100136 /// CHECK-NOT: And
137
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100138 public static long $noinline$UShr60And15(long arg) {
139 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100140 return (arg >>> 60) & 15;
141 }
142
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100143 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100144 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
145 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
146 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
147 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
148 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
149 /// CHECK-DAG: Return [<<And>>]
150
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100151 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100152 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
153 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
154 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
155 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
156 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
157 /// CHECK-DAG: Return [<<And>>]
158
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100159 public static int $noinline$UShr28And7(int arg) {
160 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100161 return (arg >>> 28) & 7;
162 }
163
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100164 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100165 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
166 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
167 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
168 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
169 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
170 /// CHECK-DAG: Return [<<And>>]
171
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100172 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100173 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
174 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
175 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
176 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
177 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
178 /// CHECK-DAG: Return [<<And>>]
179
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100180 public static long $noinline$UShr60And7(long arg) {
181 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100182 return (arg >>> 60) & 7;
183 }
184
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100185 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100186 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
187 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
188 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
189 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
190 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const255>>]
191 /// CHECK-DAG: Return [<<And>>]
192
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100193 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100194 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
195 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
196 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const24>>]
197 /// CHECK-DAG: Return [<<UShr>>]
198
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100199 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100200 /// CHECK-NOT: Shr
201 /// CHECK-NOT: And
202
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100203 public static int $noinline$Shr24And255(int arg) {
204 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100205 return (arg >> 24) & 255;
206 }
207
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100208 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100209 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
210 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
211 /// CHECK-DAG: <<Const255:j\d+>> LongConstant 255
212 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
213 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const255>>]
214 /// CHECK-DAG: Return [<<And>>]
215
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100216 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100217 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
218 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
219 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const56>>]
220 /// CHECK-DAG: Return [<<UShr>>]
221
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100222 /// CHECK-START: long Main.$noinline$Shr56And255(long) 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 long $noinline$Shr56And255(long arg) {
227 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100228 return (arg >> 56) & 255;
229 }
230
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100231 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100232 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
233 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
234 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
235 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
236 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
237 /// CHECK-DAG: Return [<<And>>]
238
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100239 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100240 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
241 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
242 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
243 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
244 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
245 /// CHECK-DAG: Return [<<And>>]
246
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100247 public static int $noinline$Shr24And127(int arg) {
248 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100249 return (arg >> 24) & 127;
250 }
251
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100252 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100253 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
254 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
255 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
256 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
257 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
258 /// CHECK-DAG: Return [<<And>>]
259
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100260 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100261 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
262 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
263 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
264 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
265 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
266 /// CHECK-DAG: Return [<<And>>]
267
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100268 public static long $noinline$Shr56And127(long arg) {
269 if (doThrow) { throw new Error(); }
Vladimir Marko452c1b62015-09-25 14:44:17 +0100270 return (arg >> 56) & 127;
271 }
272
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100273 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100274 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
275 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
276 /// CHECK-DAG: <<Div:j\d+>> Div [<<Arg>>,<<Const1>>]
277 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000278
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100279 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100280 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
281 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000282
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100283 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100284 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100285
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100286 public static long $noinline$Div1(long arg) {
287 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000288 return arg / 1;
289 }
290
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100291 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100292 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
293 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
294 /// CHECK-DAG: <<Div:i\d+>> Div [<<Arg>>,<<ConstN1>>]
295 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000296
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100297 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100298 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
299 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
300 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000301
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100302 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100303 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100304
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100305 public static int $noinline$DivN1(int arg) {
306 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000307 return arg / -1;
308 }
309
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100310 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100311 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
312 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
David Brazdil57e863c2016-01-11 10:27:13 +0000313 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const1>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100314 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000315
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100316 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100317 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
318 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000319
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100320 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100321 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100322
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100323 public static long $noinline$Mul1(long arg) {
324 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000325 return arg * 1;
326 }
327
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100328 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100329 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
330 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
331 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Arg>>,<<ConstN1>>]
332 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000333
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100334 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100335 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
336 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
337 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000338
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100339 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100340 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100341
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100342 public static int $noinline$MulN1(int arg) {
343 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000344 return arg * -1;
345 }
346
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100347 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100348 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
349 /// CHECK-DAG: <<Const128:j\d+>> LongConstant 128
David Brazdil57e863c2016-01-11 10:27:13 +0000350 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const128>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100351 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000352
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100353 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100354 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
355 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
356 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Arg>>,<<Const7>>]
357 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000358
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100359 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100360 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100361
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100362 public static long $noinline$MulPowerOfTwo128(long arg) {
363 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000364 return arg * 128;
365 }
366
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100367 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100368 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
369 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
370 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<Const0>>]
371 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000372
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100373 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100374 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
375 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000376
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100377 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100378 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100379
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100380 public static int $noinline$Or0(int arg) {
381 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000382 return arg | 0;
383 }
384
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100385 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100386 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
387 /// CHECK-DAG: <<Or:j\d+>> Or [<<Arg>>,<<Arg>>]
388 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000389
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100390 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100391 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
392 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000393
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100394 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100395 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100396
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100397 public static long $noinline$OrSame(long arg) {
398 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000399 return arg | arg;
400 }
401
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100402 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100403 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
404 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
405 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Arg>>,<<Const0>>]
406 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000407
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100408 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100409 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
410 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000411
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100412 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100413 /// CHECK-NOT: Shl
Alexandre Rames74417692015-04-09 15:21:41 +0100414
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100415 public static int $noinline$Shl0(int arg) {
416 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000417 return arg << 0;
418 }
419
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100420 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100421 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
422 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
423 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const0>>]
424 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000425
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100426 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100427 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
428 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000429
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100430 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100431 /// CHECK-NOT: Shr
Alexandre Rames74417692015-04-09 15:21:41 +0100432
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100433 public static long $noinline$Shr0(long arg) {
434 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000435 return arg >> 0;
436 }
437
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100438 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (before)
Vladimir Marko164306e2016-03-15 14:57:32 +0000439 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
440 /// CHECK-DAG: <<Const64:i\d+>> IntConstant 64
441 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const64>>]
442 /// CHECK-DAG: Return [<<Shr>>]
443
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100444 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
Vladimir Marko164306e2016-03-15 14:57:32 +0000445 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
446 /// CHECK-DAG: Return [<<Arg>>]
447
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100448 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
Vladimir Marko164306e2016-03-15 14:57:32 +0000449 /// CHECK-NOT: Shr
450
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100451 public static long $noinline$Shr64(long arg) {
452 if (doThrow) { throw new Error(); }
Vladimir Marko164306e2016-03-15 14:57:32 +0000453 return arg >> 64;
454 }
455
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100456 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100457 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
458 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
459 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Const0>>]
460 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000461
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100462 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100463 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
464 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000465
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100466 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100467 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100468
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100469 public static long $noinline$Sub0(long arg) {
470 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000471 return arg - 0;
472 }
473
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100474 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100475 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
476 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
477 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const0>>,<<Arg>>]
478 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000479
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100480 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100481 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
482 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
483 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000484
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100485 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100486 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100487
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100488 public static int $noinline$SubAliasNeg(int arg) {
489 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000490 return 0 - arg;
491 }
492
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100493 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100494 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
495 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
496 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const0>>]
497 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000498
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100499 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100500 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
501 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000502
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100503 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100504 /// CHECK-NOT: UShr
Alexandre Rames74417692015-04-09 15:21:41 +0100505
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100506 public static long $noinline$UShr0(long arg) {
507 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000508 return arg >>> 0;
509 }
510
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100511 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100512 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
513 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
514 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Const0>>]
515 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000516
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100517 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100518 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
519 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000520
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100521 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100522 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100523
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100524 public static int $noinline$Xor0(int arg) {
525 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000526 return arg ^ 0;
527 }
528
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100529 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100530 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
531 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
532 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<ConstF>>]
533 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000534
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100535 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100536 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
537 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
538 /// CHECK-DAG: Return [<<Not>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000539
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100540 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100541 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100542
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100543 public static int $noinline$XorAllOnes(int arg) {
544 if (doThrow) { throw new Error(); }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000545 return arg ^ -1;
546 }
547
Alexandre Rames188d4312015-04-09 18:30:21 +0100548 /**
549 * Test that addition or subtraction operation with both inputs negated are
550 * optimized to use a single negation after the operation.
551 * The transformation tested is implemented in
552 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
553 */
554
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100555 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100556 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
557 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
558 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
559 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
560 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
561 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100562
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100563 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100564 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
565 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
566 /// CHECK-NOT: Neg
567 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
568 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
569 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100570
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100571 public static int $noinline$AddNegs1(int arg1, int arg2) {
572 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100573 return -arg1 + -arg2;
574 }
575
576 /**
577 * This is similar to the test-case AddNegs1, but the negations have
578 * multiple uses.
579 * The transformation tested is implemented in
580 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
581 * The current code won't perform the previous optimization. The
582 * transformations do not look at other uses of their inputs. As they don't
583 * know what will happen with other uses, they do not take the risk of
584 * increasing the register pressure by creating or extending live ranges.
585 */
586
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100587 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100588 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
589 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
590 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
591 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
592 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
593 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
594 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
595 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100596
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100597 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100598 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
599 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
600 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
601 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
602 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
603 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
604 /// CHECK-NOT: Neg
605 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
606 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100607
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100608 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) GVN (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100609 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
610 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
611 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
612 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
613 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
614 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add>>,<<Add>>]
615 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100616
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100617 public static int $noinline$AddNegs2(int arg1, int arg2) {
618 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100619 int temp1 = -arg1;
620 int temp2 = -arg2;
621 return (temp1 + temp2) | (temp1 + temp2);
622 }
623
624 /**
625 * This follows test-cases AddNegs1 and AddNegs2.
626 * The transformation tested is implemented in
627 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
628 * The optimization should not happen if it moves an additional instruction in
629 * the loop.
630 */
631
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100632 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100633 // -------------- Arguments and initial negation operations.
634 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
635 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
636 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
637 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
638 /// CHECK: Goto
639 // -------------- Loop
640 /// CHECK: SuspendCheck
641 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
642 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100643
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100644 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100645 // -------------- Arguments and initial negation operations.
646 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
647 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
648 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
649 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
650 /// CHECK: Goto
651 // -------------- Loop
652 /// CHECK: SuspendCheck
653 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
654 /// CHECK-NOT: Neg
655 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100656
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100657 public static long $noinline$AddNegs3(long arg1, long arg2) {
658 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100659 long res = 0;
660 long n_arg1 = -arg1;
661 long n_arg2 = -arg2;
662 for (long i = 0; i < 1; i++) {
663 res += n_arg1 + n_arg2 + i;
664 }
665 return res;
666 }
667
668 /**
669 * Test the simplification of an addition with a negated argument into a
670 * subtraction.
671 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
672 */
673
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100674 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100675 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
676 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
677 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
678 /// CHECK-DAG: <<Add:j\d+>> Add [<<Neg>>,<<Arg2>>]
679 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100680
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100681 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100682 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
683 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
684 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg2>>,<<Arg1>>]
685 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100686
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100687 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100688 /// CHECK-NOT: Neg
689 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100690
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100691 public static long $noinline$AddNeg1(long arg1, long arg2) {
692 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100693 return -arg1 + arg2;
694 }
695
696 /**
697 * This is similar to the test-case AddNeg1, but the negation has two uses.
698 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
699 * The current code won't perform the previous optimization. The
700 * transformations do not look at other uses of their inputs. As they don't
701 * know what will happen with other uses, they do not take the risk of
702 * increasing the register pressure by creating or extending live ranges.
703 */
704
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100705 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100706 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
707 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
708 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
709 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
710 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
711 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
712 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100713
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100714 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100715 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
716 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
717 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
718 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
719 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
720 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
721 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100722
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100723 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100724 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100725
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100726 public static long $noinline$AddNeg2(long arg1, long arg2) {
727 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100728 long temp = -arg2;
729 return (arg1 + temp) | (arg1 + temp);
730 }
731
732 /**
733 * Test simplification of the `-(-var)` pattern.
734 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
735 */
736
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100737 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100738 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
739 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg>>]
740 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Neg1>>]
741 /// CHECK-DAG: Return [<<Neg2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100742
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100743 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100744 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
745 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100746
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100747 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100748 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100749
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100750 public static long $noinline$NegNeg1(long arg) {
751 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100752 return -(-arg);
753 }
754
755 /**
756 * Test 'multi-step' simplification, where a first transformation yields a
757 * new simplification possibility for the current instruction.
758 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
759 * and in `InstructionSimplifierVisitor::VisitAdd`.
760 */
761
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100762 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100763 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
764 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg>>]
765 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Neg1>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000766 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg2>>,<<Neg1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100767 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100768
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100769 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100770 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
771 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg>>,<<Arg>>]
772 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100773
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100774 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100775 /// CHECK-NOT: Neg
776 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100777
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100778 /// CHECK-START: int Main.$noinline$NegNeg2(int) constant_folding_after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100779 /// CHECK: <<Const0:i\d+>> IntConstant 0
780 /// CHECK-NOT: Neg
781 /// CHECK-NOT: Add
782 /// CHECK: Return [<<Const0>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100783
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100784 public static int $noinline$NegNeg2(int arg) {
785 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100786 int temp = -arg;
787 return temp + -temp;
788 }
789
790 /**
791 * Test another 'multi-step' simplification, where a first transformation
792 * yields a new simplification possibility for the current instruction.
793 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
794 * and in `InstructionSimplifierVisitor::VisitSub`.
795 */
796
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100797 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100798 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
799 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
800 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg>>]
801 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const0>>,<<Neg>>]
802 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100803
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100804 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100805 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
806 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100807
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100808 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100809 /// CHECK-NOT: Neg
810 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100811
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100812 public static long $noinline$NegNeg3(long arg) {
813 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100814 return 0 - -arg;
815 }
816
817 /**
818 * Test that a negated subtraction is simplified to a subtraction with its
819 * arguments reversed.
820 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
821 */
822
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100823 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100824 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
825 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
826 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
827 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Sub>>]
828 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100829
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100830 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100831 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
832 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
833 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg2>>,<<Arg1>>]
834 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100835
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100836 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100837 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100838
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100839 public static int $noinline$NegSub1(int arg1, int arg2) {
840 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100841 return -(arg1 - arg2);
842 }
843
844 /**
845 * This is similar to the test-case NegSub1, but the subtraction has
846 * multiple uses.
847 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
848 * The current code won't perform the previous optimization. The
849 * transformations do not look at other uses of their inputs. As they don't
850 * know what will happen with other uses, they do not take the risk of
851 * increasing the register pressure by creating or extending live ranges.
852 */
853
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100854 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100855 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
856 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
857 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
858 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
859 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
860 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
861 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100862
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100863 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100864 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
865 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
866 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
867 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
868 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
869 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
870 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100871
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100872 public static int $noinline$NegSub2(int arg1, int arg2) {
873 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100874 int temp = arg1 - arg2;
875 return -temp | -temp;
876 }
877
878 /**
879 * Test simplification of the `~~var` pattern.
880 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`.
881 */
882
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100883 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100884 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
David Brazdilf02c3cf2016-02-29 09:14:51 +0000885 /// CHECK-DAG: <<Not1:j\d+>> Not [<<Arg>>]
886 /// CHECK-DAG: <<Not2:j\d+>> Not [<<Not1>>]
887 /// CHECK-DAG: Return [<<Not2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100888
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100889 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100890 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
891 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100892
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100893 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +0000894 /// CHECK-NOT: Not
Alexandre Rames188d4312015-04-09 18:30:21 +0100895
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100896 public static long $noinline$NotNot1(long arg) {
897 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100898 return ~~arg;
899 }
900
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100901 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100902 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdilf02c3cf2016-02-29 09:14:51 +0000903 /// CHECK-DAG: <<Not1:i\d+>> Not [<<Arg>>]
904 /// CHECK-DAG: <<Not2:i\d+>> Not [<<Not1>>]
905 /// CHECK-DAG: <<Add:i\d+>> Add [<<Not2>>,<<Not1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100906 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100907
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100908 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100909 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
910 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000911 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg>>,<<Not>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100912 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100913
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100914 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +0000915 /// CHECK: Not
916 /// CHECK-NOT: Not
Alexandre Rames188d4312015-04-09 18:30:21 +0100917
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100918 public static int $noinline$NotNot2(int arg) {
919 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100920 int temp = ~arg;
921 return temp + ~temp;
922 }
923
924 /**
925 * Test the simplification of a subtraction with a negated argument.
926 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
927 */
928
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100929 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100930 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
931 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
932 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
933 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Neg>>,<<Arg2>>]
934 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100935
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100936 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100937 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
938 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
939 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
940 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
941 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100942
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100943 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100944 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100945
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100946 public static int $noinline$SubNeg1(int arg1, int arg2) {
947 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100948 return -arg1 - arg2;
949 }
950
951 /**
952 * This is similar to the test-case SubNeg1, but the negation has
953 * multiple uses.
954 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
955 * The current code won't perform the previous optimization. The
956 * transformations do not look at other uses of their inputs. As they don't
957 * know what will happen with other uses, they do not take the risk of
958 * increasing the register pressure by creating or extending live ranges.
959 */
960
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100961 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100962 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
963 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
964 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
965 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
966 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
967 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
968 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100969
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100970 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100971 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
972 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
973 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
974 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
975 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
976 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
977 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100978
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100979 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100980 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100981
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100982 public static int $noinline$SubNeg2(int arg1, int arg2) {
983 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +0100984 int temp = -arg1;
985 return (temp - arg2) | (temp - arg2);
986 }
987
988 /**
989 * This follows test-cases SubNeg1 and SubNeg2.
990 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
991 * The optimization should not happen if it moves an additional instruction in
992 * the loop.
993 */
994
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100995 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100996 // -------------- Arguments and initial negation operation.
997 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
998 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
999 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1000 /// CHECK: Goto
1001 // -------------- Loop
1002 /// CHECK: SuspendCheck
1003 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1004 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001005
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001006 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001007 // -------------- Arguments and initial negation operation.
1008 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
1009 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
1010 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1011 /// CHECK-DAG: Goto
1012 // -------------- Loop
1013 /// CHECK: SuspendCheck
1014 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1015 /// CHECK-NOT: Neg
1016 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001017
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001018 public static long $noinline$SubNeg3(long arg1, long arg2) {
1019 if (doThrow) { throw new Error(); }
Alexandre Rames188d4312015-04-09 18:30:21 +01001020 long res = 0;
1021 long temp = -arg1;
1022 for (long i = 0; i < 1; i++) {
1023 res += temp - arg2 - i;
1024 }
1025 return res;
1026 }
1027
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001028 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001029 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001030 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1031 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001032 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001033 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1034 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<NotArg>>,<<Const2>>]
1035 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1036 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001037
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001038 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001039 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
1040 /// CHECK-DAG: Return [<<True>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001041
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001042 public static boolean $noinline$EqualBoolVsIntConst(boolean arg) {
1043 if (doThrow) { throw new Error(); }
David Brazdil74eb1b22015-12-14 11:44:01 +00001044 return (arg ? 0 : 1) != 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001045 }
1046
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001047 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001048 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001049 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1050 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001051 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001052 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1053 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<NotArg>>,<<Const2>>]
1054 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1055 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001056
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001057 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001058 /// CHECK-DAG: <<False:i\d+>> IntConstant 0
1059 /// CHECK-DAG: Return [<<False>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001060
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001061 public static boolean $noinline$NotEqualBoolVsIntConst(boolean arg) {
1062 if (doThrow) { throw new Error(); }
David Brazdil74eb1b22015-12-14 11:44:01 +00001063 return (arg ? 0 : 1) == 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001064 }
1065
David Brazdil0d13fee2015-04-17 14:52:19 +01001066 /*
1067 * Test simplification of double Boolean negation. Note that sometimes
1068 * both negations can be removed but we only expect the simplifier to
1069 * remove the second.
1070 */
1071
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001072 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier_after_bce (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001073 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001074 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1075 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1076 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1077 /// CHECK-DAG: <<NotNotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<NotArg>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001078 /// CHECK-DAG: Return [<<NotNotArg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001079
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001080 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier_after_bce (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001081 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdila06d66a2015-05-28 11:14:54 +01001082 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001083
David Brazdil769c9e52015-04-27 13:54:09 +01001084 public static boolean NegateValue(boolean arg) {
1085 return !arg;
1086 }
1087
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001088 public static boolean $noinline$NotNotBool(boolean arg) {
1089 if (doThrow) { throw new Error(); }
David Brazdil769c9e52015-04-27 13:54:09 +01001090 return !(NegateValue(arg));
David Brazdil0d13fee2015-04-17 14:52:19 +01001091 }
1092
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001093 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001094 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1095 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
1096 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>]
1097 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001098
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001099 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001100 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1101 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5
1102 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>]
1103 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001104
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001105 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001106 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001107
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001108 public static float $noinline$Div2(float arg) {
1109 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001110 return arg / 2.0f;
1111 }
1112
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001113 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001114 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1115 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
1116 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>]
1117 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001118
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001119 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001120 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1121 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5
1122 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>]
1123 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001124
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001125 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001126 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001127 public static double $noinline$Div2(double arg) {
1128 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001129 return arg / 2.0;
1130 }
1131
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001132 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001133 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1134 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25
1135 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>]
1136 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001137
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001138 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001139 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1140 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4
1141 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>]
1142 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001143
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001144 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001145 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001146
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001147 public static float $noinline$DivMP25(float arg) {
1148 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001149 return arg / -0.25f;
1150 }
1151
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001152 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001153 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1154 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25
1155 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>]
1156 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001157
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001158 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001159 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1160 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4
1161 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>]
1162 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001163
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001164 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001165 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001166 public static double $noinline$DivMP25(double arg) {
1167 if (doThrow) { throw new Error(); }
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001168 return arg / -0.25f;
1169 }
1170
Alexandre Rames38db7852015-11-20 15:02:45 +00001171 /**
1172 * Test strength reduction of factors of the form (2^n + 1).
1173 */
1174
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001175 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001176 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1177 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
1178 /// CHECK: Mul [<<Arg>>,<<Const9>>]
1179
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001180 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001181 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1182 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1183 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>]
1184 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>]
1185
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001186 public static int $noinline$mulPow2Plus1(int arg) {
1187 if (doThrow) { throw new Error(); }
Alexandre Rames38db7852015-11-20 15:02:45 +00001188 return arg * 9;
1189 }
1190
Alexandre Rames38db7852015-11-20 15:02:45 +00001191 /**
1192 * Test strength reduction of factors of the form (2^n - 1).
1193 */
1194
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001195 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001196 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1197 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31
David Brazdil57e863c2016-01-11 10:27:13 +00001198 /// CHECK: Mul [<<Const31>>,<<Arg>>]
Alexandre Rames38db7852015-11-20 15:02:45 +00001199
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001200 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001201 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1202 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1203 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>]
1204 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>]
1205
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001206 public static long $noinline$mulPow2Minus1(long arg) {
1207 if (doThrow) { throw new Error(); }
Alexandre Rames38db7852015-11-20 15:02:45 +00001208 return arg * 31;
1209 }
1210
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001211 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier_after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001212 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdilf02c3cf2016-02-29 09:14:51 +00001213 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1214 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001215 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
Mark Mendellf6529172015-11-17 11:16:56 -05001216 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1217 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +00001218 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1219 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001220
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001221 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier_after_bce (after)
1222 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001223 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1224 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1225 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1226 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1227 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001228
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001229 public static int $noinline$booleanFieldNotEqualOne() {
1230 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001231 return (booleanField == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001232 }
1233
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001234 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier_after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001235 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdilf02c3cf2016-02-29 09:14:51 +00001236 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1237 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001238 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
Mark Mendellf6529172015-11-17 11:16:56 -05001239 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdilf02c3cf2016-02-29 09:14:51 +00001240 /// CHECK-DAG: <<NE:z\d+>> Equal [<<Field>>,<<Const0>>]
1241 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1242 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001243
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001244 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier_after_bce (after)
1245 /// CHECK-DAG: <<doThrow:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001246 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1247 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1248 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1249 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1250 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001251
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001252 public static int $noinline$booleanFieldEqualZero() {
1253 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001254 return (booleanField != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001255 }
1256
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001257 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier_after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001258 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001259 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
Mark Mendellf6529172015-11-17 11:16:56 -05001260 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +00001261 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001262 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001263 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1264 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1265 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001266 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001267 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1268 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001269
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001270 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier_after_bce (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001271 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001272 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001273 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001274 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1275 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001276 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001277 /// CHECK-DAG: Return [<<Result>>]
1278 // Note that we match `LE` from Select because there are two identical
1279 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001280
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001281 public static int $noinline$intConditionNotEqualOne(int i) {
1282 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001283 return ((i > 42) == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001284 }
1285
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001286 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier_after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001287 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1288 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001289 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1290 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001291 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001292 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1293 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1294 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
1295 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>]
1296 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1297 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001298
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001299 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier_after_bce (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001300 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001301 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001302 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001303 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1304 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001305 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001306 /// CHECK-DAG: Return [<<Result>>]
1307 // Note that we match `LE` from Select because there are two identical
1308 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001309
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001310 public static int $noinline$intConditionEqualZero(int i) {
1311 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001312 return ((i > 42) != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001313 }
1314
1315 // Test that conditions on float/double are not flipped.
1316
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001317 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001318 /// CHECK: LessThanOrEqual
1319
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001320 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) instruction_simplifier_before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001321 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1322 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1323 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1324 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
1325 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1326 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1327 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001328
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001329 public static int $noinline$floatConditionNotEqualOne(float f) {
1330 if (doThrow) { throw new Error(); }
Mark Mendellf6529172015-11-17 11:16:56 -05001331 return ((f > 42.0f) == true) ? 13 : 54;
1332 }
1333
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001334 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001335 /// CHECK: LessThanOrEqual
1336
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001337 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) instruction_simplifier_before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001338 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1339 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1340 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1341 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1342 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1343 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1344 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001345
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001346 public static int $noinline$doubleConditionEqualZero(double d) {
1347 if (doThrow) { throw new Error(); }
Mark Mendellf6529172015-11-17 11:16:56 -05001348 return ((d > 42.0) != false) ? 13 : 54;
1349 }
Alexandre Rames38db7852015-11-20 15:02:45 +00001350
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001351 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001352 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1353 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1354 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1355 /// CHECK-DAG: Return [<<Int>>]
1356
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001357 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001358 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1359 /// CHECK-DAG: Return [<<Arg>>]
1360
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001361 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001362 /// CHECK-NOT: TypeConversion
1363
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001364 public static int $noinline$intToDoubleToInt(int value) {
1365 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001366 // Lossless conversion followed by a conversion back.
1367 return (int) (double) value;
1368 }
1369
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001370 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001371 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1372 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1373 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1374
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001375 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001376 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1377 /// CHECK-DAG: {{d\d+}} TypeConversion [<<Arg>>]
1378
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001379 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001380 /// CHECK-DAG: TypeConversion
1381 /// CHECK-NOT: TypeConversion
1382
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001383 public static String $noinline$intToDoubleToIntPrint(int value) {
1384 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001385 // Lossless conversion followed by a conversion back
1386 // with another use of the intermediate result.
1387 double d = (double) value;
1388 int i = (int) d;
1389 return "d=" + d + ", i=" + i;
1390 }
1391
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001392 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001393 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1394 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1395 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1396 /// CHECK-DAG: Return [<<Int>>]
1397
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001398 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001399 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1400 /// CHECK-DAG: Return [<<Arg>>]
1401
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001402 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001403 /// CHECK-NOT: TypeConversion
1404
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001405 public static int $noinline$byteToDoubleToInt(byte value) {
1406 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001407 // Lossless conversion followed by another conversion, use implicit conversion.
1408 return (int) (double) value;
1409 }
1410
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001411 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001412 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1413 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1414 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1415 /// CHECK-DAG: Return [<<Int>>]
1416
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001417 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001418 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1419 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1420 /// CHECK-DAG: Return [<<Int>>]
1421
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001422 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001423 /// CHECK-DAG: TypeConversion
1424 /// CHECK-NOT: TypeConversion
1425
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001426 public static int $noinline$floatToDoubleToInt(float value) {
1427 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001428 // Lossless conversion followed by another conversion.
1429 return (int) (double) value;
1430 }
1431
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001432 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001433 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1434 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1435 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1436
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001437 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001438 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1439 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1440 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1441
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001442 public static String $noinline$floatToDoubleToIntPrint(float value) {
1443 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001444 // Lossless conversion followed by another conversion with
1445 // an extra use of the intermediate result.
1446 double d = (double) value;
1447 int i = (int) d;
1448 return "d=" + d + ", i=" + i;
1449 }
1450
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001451 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001452 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1453 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1454 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1455 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1456 /// CHECK-DAG: Return [<<Short>>]
1457
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001458 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001459 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1460 /// CHECK-DAG: Return [<<Arg>>]
1461
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001462 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001463 /// CHECK-NOT: TypeConversion
1464
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001465 public static short $noinline$byteToDoubleToShort(byte value) {
1466 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001467 // Originally, this is byte->double->int->short. The first conversion is lossless,
1468 // so we merge this with the second one to byte->int which we omit as it's an implicit
1469 // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1470 return (short) (double) value;
1471 }
1472
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001473 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001474 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1475 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1476 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1477 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1478 /// CHECK-DAG: Return [<<Short>>]
1479
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001480 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001481 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1482 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Arg>>]
1483 /// CHECK-DAG: Return [<<Short>>]
1484
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001485 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001486 /// CHECK-DAG: TypeConversion
1487 /// CHECK-NOT: TypeConversion
1488
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001489 public static short $noinline$charToDoubleToShort(char value) {
1490 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001491 // Originally, this is char->double->int->short. The first conversion is lossless,
1492 // so we merge this with the second one to char->int which we omit as it's an implicit
1493 // conversion. Then we are left with the resulting char->short conversion.
1494 return (short) (double) value;
1495 }
1496
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001497 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001498 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1499 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1500 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1501 /// CHECK-DAG: Return [<<Short>>]
1502
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001503 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001504 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1505 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1506 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1507 /// CHECK-DAG: Return [<<Short>>]
1508
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001509 public static short $noinline$floatToIntToShort(float value) {
1510 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001511 // Lossy FP to integral conversion followed by another conversion: no simplification.
1512 return (short) value;
1513 }
1514
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001515 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001516 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1517 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1518 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1519 /// CHECK-DAG: Return [<<Int>>]
1520
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001521 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001522 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1523 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1524 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1525 /// CHECK-DAG: Return [<<Int>>]
1526
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001527 public static int $noinline$intToFloatToInt(int value) {
1528 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001529 // Lossy integral to FP conversion followed another conversion: no simplification.
1530 return (int) (float) value;
1531 }
1532
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001533 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001534 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1535 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1536 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1537 /// CHECK-DAG: Return [<<Double>>]
1538
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001539 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001540 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1541 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1542 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1543 /// CHECK-DAG: Return [<<Double>>]
1544
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001545 public static double $noinline$longToIntToDouble(long value) {
1546 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001547 // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1548 return (double) (int) value;
1549 }
1550
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001551 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001552 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1553 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1554 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1555 /// CHECK-DAG: Return [<<Long>>]
1556
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001557 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001558 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1559 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1560 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1561 /// CHECK-DAG: Return [<<Long>>]
1562
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001563 public static long $noinline$longToIntToLong(long value) {
1564 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001565 // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1566 return (long) (int) value;
1567 }
1568
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001569 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001570 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1571 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1572 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Char>>]
1573 /// CHECK-DAG: Return [<<Short>>]
1574
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001575 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001576 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1577 /// CHECK-DAG: Return [<<Arg>>]
1578
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001579 public static short $noinline$shortToCharToShort(short value) {
1580 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001581 // Integral conversion followed by non-widening integral conversion to original type.
1582 return (short) (char) value;
1583 }
1584
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001585 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001586 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1587 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1588 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Long>>]
1589 /// CHECK-DAG: Return [<<Int>>]
1590
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001591 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001592 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1593 /// CHECK-DAG: Return [<<Arg>>]
1594
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001595 public static int $noinline$shortToLongToInt(short value) {
1596 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001597 // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1598 return (int) (long) value;
1599 }
1600
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001601 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001602 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1603 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1604 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Char>>]
1605 /// CHECK-DAG: Return [<<Byte>>]
1606
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001607 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001608 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1609 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1610 /// CHECK-DAG: Return [<<Byte>>]
1611
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001612 public static byte $noinline$shortToCharToByte(short value) {
1613 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001614 // Integral conversion followed by non-widening integral conversion losing bits
1615 // from the original type. Simplify to use only one conversion.
1616 return (byte) (char) value;
1617 }
1618
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001619 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001620 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1621 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1622 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1623
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001624 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001625 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1626 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1627 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1628
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001629 public static String $noinline$shortToCharToBytePrint(short value) {
1630 if (doThrow) { throw new Error(); }
Vladimir Markob52bbde2016-02-12 12:06:05 +00001631 // Integral conversion followed by non-widening integral conversion losing bits
1632 // from the original type with an extra use of the intermediate result.
1633 char c = (char) value;
1634 byte b = (byte) c;
1635 return "c=" + ((int) c) + ", b=" + ((int) b); // implicit conversions.
1636 }
1637
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001638 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001639 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1640 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 255
1641 /// CHECK-DAG: <<And:j\d+>> And [<<Mask>>,<<Arg>>]
1642 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<And>>]
1643 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Int>>]
1644 /// CHECK-DAG: Return [<<Byte>>]
1645
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001646 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001647 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1648 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1649 /// CHECK-DAG: Return [<<Byte>>]
1650
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001651 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001652 /// CHECK-NOT: And
1653
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001654 public static byte $noinline$longAnd0xffToByte(long value) {
1655 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001656 return (byte) (value & 0xff);
1657 }
1658
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001659 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001660 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1661 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 131071
1662 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1663 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<And>>]
1664 /// CHECK-DAG: Return [<<Char>>]
1665
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001666 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001667 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1668 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1669 /// CHECK-DAG: Return [<<Char>>]
1670
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001671 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001672 /// CHECK-NOT: And
1673
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001674 public static char $noinline$intAnd0x1ffffToChar(int value) {
1675 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001676 // Keeping all significant bits and one more.
1677 return (char) (value & 0x1ffff);
1678 }
1679
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001680 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001681 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1682 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1683 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1684 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1685 /// CHECK-DAG: Return [<<Short>>]
1686
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001687 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001688 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1689 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1690 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1691 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1692 /// CHECK-DAG: Return [<<Short>>]
1693
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001694 public static short $noinline$intAnd0x17fffToShort(int value) {
1695 if (doThrow) { throw new Error(); }
Vladimir Marko8428bd32016-02-12 16:53:57 +00001696 // No simplification: clearing a significant bit.
1697 return (short) (value & 0x17fff);
1698 }
1699
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001700 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (before)
Vladimir Marko625090f2016-03-14 18:00:05 +00001701 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1702 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 65535
1703 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1704 /// CHECK-DAG: <<Same:s\d+>> TypeConversion [<<And>>]
1705 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Same>>]
1706 /// CHECK-DAG: Return [<<Double>>]
1707
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001708 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (after)
Vladimir Marko625090f2016-03-14 18:00:05 +00001709 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1710 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1711 /// CHECK-DAG: Return [<<Double>>]
1712
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001713 public static double $noinline$shortAnd0xffffToShortToDouble(short value) {
1714 if (doThrow) { throw new Error(); }
Vladimir Marko625090f2016-03-14 18:00:05 +00001715 short same = (short) (value & 0xffff);
1716 return (double) same;
1717 }
1718
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001719 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001720 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1721 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1722 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Const42>>,<<Arg>>]
1723
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001724 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001725 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1726 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1727 /// CHECK-DAG: <<GE:z\d+>> GreaterThanOrEqual [<<Arg>>,<<Const42>>]
1728
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001729 public static int $noinline$intReverseCondition(int i) {
1730 if (doThrow) { throw new Error(); }
Anton Shaminbdd79352016-02-15 12:48:36 +06001731 return (42 > i) ? 13 : 54;
1732 }
1733
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001734 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001735 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1736 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1737 /// CHECK-DAG: <<CMP:i\d+>> Compare [<<Const42>>,<<Result>>]
1738
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001739 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001740 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1741 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1742 /// CHECK-DAG: <<EQ:z\d+>> Equal [<<Result>>,<<Const42>>]
1743
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001744 public static int $noinline$intReverseConditionNaN(int i) {
1745 if (doThrow) { throw new Error(); }
Anton Shaminbdd79352016-02-15 12:48:36 +06001746 return (42 != Math.sqrt(i)) ? 13 : 54;
1747 }
1748
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001749 public static int $noinline$runSmaliTest(String name, boolean input) {
1750 if (doThrow) { throw new Error(); }
David Brazdilf02c3cf2016-02-29 09:14:51 +00001751 try {
1752 Class<?> c = Class.forName("SmaliTests");
1753 Method m = c.getMethod(name, new Class[] { boolean.class });
1754 return (Integer) m.invoke(null, input);
1755 } catch (Exception ex) {
1756 throw new Error(ex);
1757 }
1758 }
1759
Alexandre Rames50518442016-06-27 11:39:19 +01001760 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1761 /// CHECK: <<Value:i\d+>> ParameterValue
1762 /// CHECK: <<Shift:i\d+>> ParameterValue
1763 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1764 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1765 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<And>>]
1766 /// CHECK-DAG: Return [<<Shl>>]
1767
1768 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1769 /// CHECK: <<Value:i\d+>> ParameterValue
1770 /// CHECK: <<Shift:i\d+>> ParameterValue
1771 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<Shift>>]
1772 /// CHECK-DAG: Return [<<Shl>>]
1773
1774 public static int $noinline$intUnnecessaryShiftMasking(int value, int shift) {
1775 if (doThrow) { throw new Error(); }
1776 return value << (shift & 31);
1777 }
1778
1779 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (before)
1780 /// CHECK: <<Value:j\d+>> ParameterValue
1781 /// CHECK: <<Shift:i\d+>> ParameterValue
1782 /// CHECK-DAG: <<Const63:i\d+>> IntConstant 63
1783 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const63>>]
1784 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<And>>]
1785 /// CHECK-DAG: Return [<<Shr>>]
1786
1787 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (after)
1788 /// CHECK: <<Value:j\d+>> ParameterValue
1789 /// CHECK: <<Shift:i\d+>> ParameterValue
1790 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<Shift>>]
1791 /// CHECK-DAG: Return [<<Shr>>]
1792
1793 public static long $noinline$longUnnecessaryShiftMasking(long value, int shift) {
1794 if (doThrow) { throw new Error(); }
1795 return value >> (shift & 63);
1796 }
1797
1798 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (before)
1799 /// CHECK: <<Value:i\d+>> ParameterValue
1800 /// CHECK: <<Shift:i\d+>> ParameterValue
1801 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
1802 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const255>>]
1803 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<And>>]
1804 /// CHECK-DAG: Return [<<UShr>>]
1805
1806 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (after)
1807 /// CHECK: <<Value:i\d+>> ParameterValue
1808 /// CHECK: <<Shift:i\d+>> ParameterValue
1809 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<Shift>>]
1810 /// CHECK-DAG: Return [<<UShr>>]
1811
1812 public static int $noinline$intUnnecessaryWiderShiftMasking(int value, int shift) {
1813 if (doThrow) { throw new Error(); }
1814 return value >>> (shift & 0xff);
1815 }
1816
1817 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (before)
1818 /// CHECK: <<Value:j\d+>> ParameterValue
1819 /// CHECK: <<Shift:i\d+>> ParameterValue
1820 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1821 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
1822 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
1823 /// CHECK-DAG: Return [<<Shl>>]
1824
1825 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (after)
1826 /// CHECK: <<Value:j\d+>> ParameterValue
1827 /// CHECK: <<Shift:i\d+>> ParameterValue
1828 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1829 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
1830 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
1831 /// CHECK-DAG: Return [<<Shl>>]
1832
1833 public static long $noinline$longSmallerShiftMasking(long value, int shift) {
1834 if (doThrow) { throw new Error(); }
1835 return value << (shift & 3);
1836 }
1837
1838 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1839 /// CHECK: <<Value:i\d+>> ParameterValue
1840 /// CHECK: <<Shift:i\d+>> ParameterValue
1841 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1842 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1843 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<And>>]
1844 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
1845 /// CHECK-DAG: Return [<<Add>>]
1846
1847 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1848 /// CHECK: <<Value:i\d+>> ParameterValue
1849 /// CHECK: <<Shift:i\d+>> ParameterValue
1850 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1851 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1852 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<Shift>>]
1853 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
1854 /// CHECK-DAG: Return [<<Add>>]
1855
1856 public static int $noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift) {
1857 if (doThrow) { throw new Error(); }
1858 int temp = shift & 31;
1859 return (value >> temp) + temp;
1860 }
1861
Anton Shaminbdd79352016-02-15 12:48:36 +06001862public static void main(String[] args) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001863 int arg = 123456;
1864
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001865 assertLongEquals(arg, $noinline$Add0(arg));
1866 assertIntEquals(arg, $noinline$AndAllOnes(arg));
1867 assertLongEquals(arg, $noinline$Div1(arg));
1868 assertIntEquals(-arg, $noinline$DivN1(arg));
1869 assertLongEquals(arg, $noinline$Mul1(arg));
1870 assertIntEquals(-arg, $noinline$MulN1(arg));
1871 assertLongEquals((128 * arg), $noinline$MulPowerOfTwo128(arg));
1872 assertIntEquals(arg, $noinline$Or0(arg));
1873 assertLongEquals(arg, $noinline$OrSame(arg));
1874 assertIntEquals(arg, $noinline$Shl0(arg));
1875 assertLongEquals(arg, $noinline$Shr0(arg));
1876 assertLongEquals(arg, $noinline$Shr64(arg));
1877 assertLongEquals(arg, $noinline$Sub0(arg));
1878 assertIntEquals(-arg, $noinline$SubAliasNeg(arg));
1879 assertLongEquals(arg, $noinline$UShr0(arg));
1880 assertIntEquals(arg, $noinline$Xor0(arg));
1881 assertIntEquals(~arg, $noinline$XorAllOnes(arg));
1882 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs1(arg, arg + 1));
1883 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs2(arg, arg + 1));
1884 assertLongEquals(-(2 * arg + 1), $noinline$AddNegs3(arg, arg + 1));
1885 assertLongEquals(1, $noinline$AddNeg1(arg, arg + 1));
1886 assertLongEquals(-1, $noinline$AddNeg2(arg, arg + 1));
1887 assertLongEquals(arg, $noinline$NegNeg1(arg));
1888 assertIntEquals(0, $noinline$NegNeg2(arg));
1889 assertLongEquals(arg, $noinline$NegNeg3(arg));
1890 assertIntEquals(1, $noinline$NegSub1(arg, arg + 1));
1891 assertIntEquals(1, $noinline$NegSub2(arg, arg + 1));
1892 assertLongEquals(arg, $noinline$NotNot1(arg));
1893 assertIntEquals(-1, $noinline$NotNot2(arg));
1894 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg1(arg, arg + 1));
1895 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg2(arg, arg + 1));
1896 assertLongEquals(-(2 * arg + 1), $noinline$SubNeg3(arg, arg + 1));
1897 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
1898 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
1899 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
1900 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
1901 assertBooleanEquals(true, $noinline$NotNotBool(true));
1902 assertBooleanEquals(false, $noinline$NotNotBool(false));
1903 assertFloatEquals(50.0f, $noinline$Div2(100.0f));
1904 assertDoubleEquals(75.0, $noinline$Div2(150.0));
1905 assertFloatEquals(-400.0f, $noinline$DivMP25(100.0f));
1906 assertDoubleEquals(-600.0, $noinline$DivMP25(150.0));
1907 assertIntEquals(0xc, $noinline$UShr28And15(0xc1234567));
1908 assertLongEquals(0xcL, $noinline$UShr60And15(0xc123456787654321L));
1909 assertIntEquals(0x4, $noinline$UShr28And7(0xc1234567));
1910 assertLongEquals(0x4L, $noinline$UShr60And7(0xc123456787654321L));
1911 assertIntEquals(0xc1, $noinline$Shr24And255(0xc1234567));
1912 assertLongEquals(0xc1L, $noinline$Shr56And255(0xc123456787654321L));
1913 assertIntEquals(0x41, $noinline$Shr24And127(0xc1234567));
1914 assertLongEquals(0x41L, $noinline$Shr56And127(0xc123456787654321L));
1915 assertIntEquals(0, $noinline$mulPow2Plus1(0));
1916 assertIntEquals(9, $noinline$mulPow2Plus1(1));
1917 assertIntEquals(18, $noinline$mulPow2Plus1(2));
1918 assertIntEquals(900, $noinline$mulPow2Plus1(100));
1919 assertIntEquals(111105, $noinline$mulPow2Plus1(12345));
1920 assertLongEquals(0, $noinline$mulPow2Minus1(0));
1921 assertLongEquals(31, $noinline$mulPow2Minus1(1));
1922 assertLongEquals(62, $noinline$mulPow2Minus1(2));
1923 assertLongEquals(3100, $noinline$mulPow2Minus1(100));
1924 assertLongEquals(382695, $noinline$mulPow2Minus1(12345));
Mark Mendellf6529172015-11-17 11:16:56 -05001925
1926 booleanField = false;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001927 assertIntEquals($noinline$booleanFieldNotEqualOne(), 54);
1928 assertIntEquals($noinline$booleanFieldEqualZero(), 54);
Mark Mendellf6529172015-11-17 11:16:56 -05001929 booleanField = true;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001930 assertIntEquals(13, $noinline$booleanFieldNotEqualOne());
1931 assertIntEquals(13, $noinline$booleanFieldEqualZero());
1932 assertIntEquals(54, $noinline$intConditionNotEqualOne(6));
1933 assertIntEquals(13, $noinline$intConditionNotEqualOne(43));
1934 assertIntEquals(54, $noinline$intConditionEqualZero(6));
1935 assertIntEquals(13, $noinline$intConditionEqualZero(43));
1936 assertIntEquals(54, $noinline$floatConditionNotEqualOne(6.0f));
1937 assertIntEquals(13, $noinline$floatConditionNotEqualOne(43.0f));
1938 assertIntEquals(54, $noinline$doubleConditionEqualZero(6.0));
1939 assertIntEquals(13, $noinline$doubleConditionEqualZero(43.0));
Vladimir Markob52bbde2016-02-12 12:06:05 +00001940
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001941 assertIntEquals(1234567, $noinline$intToDoubleToInt(1234567));
1942 assertIntEquals(Integer.MIN_VALUE, $noinline$intToDoubleToInt(Integer.MIN_VALUE));
1943 assertIntEquals(Integer.MAX_VALUE, $noinline$intToDoubleToInt(Integer.MAX_VALUE));
1944 assertStringEquals("d=7654321.0, i=7654321", $noinline$intToDoubleToIntPrint(7654321));
1945 assertIntEquals(12, $noinline$byteToDoubleToInt((byte) 12));
1946 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToInt(Byte.MIN_VALUE));
1947 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToInt(Byte.MAX_VALUE));
1948 assertIntEquals(11, $noinline$floatToDoubleToInt(11.3f));
1949 assertStringEquals("d=12.25, i=12", $noinline$floatToDoubleToIntPrint(12.25f));
1950 assertIntEquals(123, $noinline$byteToDoubleToShort((byte) 123));
1951 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToShort(Byte.MIN_VALUE));
1952 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToShort(Byte.MAX_VALUE));
1953 assertIntEquals(1234, $noinline$charToDoubleToShort((char) 1234));
1954 assertIntEquals(Character.MIN_VALUE, $noinline$charToDoubleToShort(Character.MIN_VALUE));
1955 assertIntEquals(/* sign-extended */ -1, $noinline$charToDoubleToShort(Character.MAX_VALUE));
1956 assertIntEquals(12345, $noinline$floatToIntToShort(12345.75f));
1957 assertIntEquals(Short.MAX_VALUE, $noinline$floatToIntToShort((float)(Short.MIN_VALUE - 1)));
1958 assertIntEquals(Short.MIN_VALUE, $noinline$floatToIntToShort((float)(Short.MAX_VALUE + 1)));
1959 assertIntEquals(-54321, $noinline$intToFloatToInt(-54321));
1960 assertDoubleEquals((double) 0x12345678, $noinline$longToIntToDouble(0x1234567812345678L));
1961 assertDoubleEquals(0.0, $noinline$longToIntToDouble(Long.MIN_VALUE));
1962 assertDoubleEquals(-1.0, $noinline$longToIntToDouble(Long.MAX_VALUE));
1963 assertLongEquals(0x0000000012345678L, $noinline$longToIntToLong(0x1234567812345678L));
1964 assertLongEquals(0xffffffff87654321L, $noinline$longToIntToLong(0x1234567887654321L));
1965 assertLongEquals(0L, $noinline$longToIntToLong(Long.MIN_VALUE));
1966 assertLongEquals(-1L, $noinline$longToIntToLong(Long.MAX_VALUE));
1967 assertIntEquals((short) -5678, $noinline$shortToCharToShort((short) -5678));
1968 assertIntEquals(Short.MIN_VALUE, $noinline$shortToCharToShort(Short.MIN_VALUE));
1969 assertIntEquals(Short.MAX_VALUE, $noinline$shortToCharToShort(Short.MAX_VALUE));
1970 assertIntEquals(5678, $noinline$shortToLongToInt((short) 5678));
1971 assertIntEquals(Short.MIN_VALUE, $noinline$shortToLongToInt(Short.MIN_VALUE));
1972 assertIntEquals(Short.MAX_VALUE, $noinline$shortToLongToInt(Short.MAX_VALUE));
1973 assertIntEquals(0x34, $noinline$shortToCharToByte((short) 0x1234));
1974 assertIntEquals(-0x10, $noinline$shortToCharToByte((short) 0x12f0));
1975 assertIntEquals(0, $noinline$shortToCharToByte(Short.MIN_VALUE));
1976 assertIntEquals(-1, $noinline$shortToCharToByte(Short.MAX_VALUE));
1977 assertStringEquals("c=1025, b=1", $noinline$shortToCharToBytePrint((short) 1025));
1978 assertStringEquals("c=1023, b=-1", $noinline$shortToCharToBytePrint((short) 1023));
1979 assertStringEquals("c=65535, b=-1", $noinline$shortToCharToBytePrint((short) -1));
Vladimir Marko8428bd32016-02-12 16:53:57 +00001980
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001981 assertIntEquals(0x21, $noinline$longAnd0xffToByte(0x1234432112344321L));
1982 assertIntEquals(0, $noinline$longAnd0xffToByte(Long.MIN_VALUE));
1983 assertIntEquals(-1, $noinline$longAnd0xffToByte(Long.MAX_VALUE));
1984 assertIntEquals(0x1234, $noinline$intAnd0x1ffffToChar(0x43211234));
1985 assertIntEquals(0, $noinline$intAnd0x1ffffToChar(Integer.MIN_VALUE));
1986 assertIntEquals(Character.MAX_VALUE, $noinline$intAnd0x1ffffToChar(Integer.MAX_VALUE));
1987 assertIntEquals(0x4321, $noinline$intAnd0x17fffToShort(0x87654321));
1988 assertIntEquals(0x0888, $noinline$intAnd0x17fffToShort(0x88888888));
1989 assertIntEquals(0, $noinline$intAnd0x17fffToShort(Integer.MIN_VALUE));
1990 assertIntEquals(Short.MAX_VALUE, $noinline$intAnd0x17fffToShort(Integer.MAX_VALUE));
Vladimir Marko625090f2016-03-14 18:00:05 +00001991
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001992 assertDoubleEquals(0.0, $noinline$shortAnd0xffffToShortToDouble((short) 0));
1993 assertDoubleEquals(1.0, $noinline$shortAnd0xffffToShortToDouble((short) 1));
1994 assertDoubleEquals(-2.0, $noinline$shortAnd0xffffToShortToDouble((short) -2));
1995 assertDoubleEquals(12345.0, $noinline$shortAnd0xffffToShortToDouble((short) 12345));
1996 assertDoubleEquals((double)Short.MAX_VALUE,
1997 $noinline$shortAnd0xffffToShortToDouble(Short.MAX_VALUE));
1998 assertDoubleEquals((double)Short.MIN_VALUE,
1999 $noinline$shortAnd0xffffToShortToDouble(Short.MIN_VALUE));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002000
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002001 assertIntEquals(13, $noinline$intReverseCondition(41));
2002 assertIntEquals(13, $noinline$intReverseConditionNaN(-5));
Anton Shaminbdd79352016-02-15 12:48:36 +06002003
David Brazdilf02c3cf2016-02-29 09:14:51 +00002004 for (String condition : new String[] { "Equal", "NotEqual" }) {
2005 for (String constant : new String[] { "True", "False" }) {
2006 for (String side : new String[] { "Rhs", "Lhs" }) {
2007 String name = condition + constant + side;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002008 assertIntEquals(5, $noinline$runSmaliTest(name, true));
2009 assertIntEquals(3, $noinline$runSmaliTest(name, false));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002010 }
2011 }
2012 }
Alexandre Rames50518442016-06-27 11:39:19 +01002013
2014 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3));
2015 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3 + 32));
2016 assertLongEquals(0xffffffffffffeaf3L, $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50));
2017 assertLongEquals(0xffffffffffffeaf3L, $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50 + 64));
2018 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10));
2019 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10 + 128));
2020 assertLongEquals(0xaf37bc048d159e24L, $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2));
2021 assertLongEquals(0xaf37bc048d159e24L, $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2 + 256));
2022 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13));
2023 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13 + 512));
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002024 }
Mark Mendellf6529172015-11-17 11:16:56 -05002025
David Brazdilf02c3cf2016-02-29 09:14:51 +00002026 private static boolean $inline$true() { return true; }
2027 private static boolean $inline$false() { return false; }
2028
Mark Mendellf6529172015-11-17 11:16:56 -05002029 public static boolean booleanField;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002030}