blob: 86401487953f149e27b70c154248f40ab525c074 [file] [log] [blame]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000016
David Brazdilf02c3cf2016-02-29 09:14:51 +000017import java.lang.reflect.Method;
18
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000019public class Main {
20
David Brazdil0d13fee2015-04-17 14:52:19 +010021 public static void assertBooleanEquals(boolean expected, boolean result) {
22 if (expected != result) {
23 throw new Error("Expected: " + expected + ", found: " + result);
24 }
25 }
26
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000027 public static void assertIntEquals(int expected, int result) {
28 if (expected != result) {
29 throw new Error("Expected: " + expected + ", found: " + result);
30 }
31 }
32
33 public static void assertLongEquals(long expected, long result) {
34 if (expected != result) {
35 throw new Error("Expected: " + expected + ", found: " + result);
36 }
37 }
38
Nicolas Geoffray0d221842015-04-27 08:53:46 +000039 public static void assertFloatEquals(float expected, float result) {
40 if (expected != result) {
41 throw new Error("Expected: " + expected + ", found: " + result);
42 }
43 }
44
45 public static void assertDoubleEquals(double expected, double result) {
46 if (expected != result) {
47 throw new Error("Expected: " + expected + ", found: " + result);
48 }
49 }
50
Vladimir Markob52bbde2016-02-12 12:06:05 +000051 public static void assertStringEquals(String expected, String result) {
52 if (expected == null ? result != null : !expected.equals(result)) {
53 throw new Error("Expected: " + expected + ", found: " + result);
54 }
55 }
56
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000057 /**
58 * Tiny programs exercising optimizations of arithmetic identities.
59 */
60
David Brazdila06d66a2015-05-28 11:14:54 +010061 /// CHECK-START: long Main.Add0(long) instruction_simplifier (before)
62 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
63 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
64 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const0>>,<<Arg>>]
65 /// CHECK-DAG: Return [<<Add>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000066
David Brazdila06d66a2015-05-28 11:14:54 +010067 /// CHECK-START: long Main.Add0(long) instruction_simplifier (after)
68 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
69 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +010070
David Brazdila06d66a2015-05-28 11:14:54 +010071 /// CHECK-START: long Main.Add0(long) instruction_simplifier (after)
72 /// CHECK-NOT: Add
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000073
74 public static long Add0(long arg) {
75 return 0 + arg;
76 }
77
David Brazdila06d66a2015-05-28 11:14:54 +010078 /// CHECK-START: int Main.AndAllOnes(int) instruction_simplifier (before)
79 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
80 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
81 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<ConstF>>]
82 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000083
David Brazdila06d66a2015-05-28 11:14:54 +010084 /// CHECK-START: int Main.AndAllOnes(int) instruction_simplifier (after)
85 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
86 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000087
David Brazdila06d66a2015-05-28 11:14:54 +010088 /// CHECK-START: int Main.AndAllOnes(int) instruction_simplifier (after)
89 /// CHECK-NOT: And
Alexandre Rames74417692015-04-09 15:21:41 +010090
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000091 public static int AndAllOnes(int arg) {
92 return arg & -1;
93 }
94
Vladimir Marko452c1b62015-09-25 14:44:17 +010095 /// CHECK-START: int Main.UShr28And15(int) instruction_simplifier (before)
96 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
97 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
98 /// CHECK-DAG: <<Const15:i\d+>> IntConstant 15
99 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
100 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const15>>]
101 /// CHECK-DAG: Return [<<And>>]
102
103 /// CHECK-START: int Main.UShr28And15(int) instruction_simplifier (after)
104 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
105 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
106 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
107 /// CHECK-DAG: Return [<<UShr>>]
108
109 /// CHECK-START: int Main.UShr28And15(int) instruction_simplifier (after)
110 /// CHECK-NOT: And
111
112 public static int UShr28And15(int arg) {
113 return (arg >>> 28) & 15;
114 }
115
116 /// CHECK-START: long Main.UShr60And15(long) instruction_simplifier (before)
117 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
118 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
119 /// CHECK-DAG: <<Const15:j\d+>> LongConstant 15
120 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
121 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const15>>]
122 /// CHECK-DAG: Return [<<And>>]
123
124 /// CHECK-START: long Main.UShr60And15(long) instruction_simplifier (after)
125 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
126 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
127 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
128 /// CHECK-DAG: Return [<<UShr>>]
129
130 /// CHECK-START: long Main.UShr60And15(long) instruction_simplifier (after)
131 /// CHECK-NOT: And
132
133 public static long UShr60And15(long arg) {
134 return (arg >>> 60) & 15;
135 }
136
137 /// CHECK-START: int Main.UShr28And7(int) instruction_simplifier (before)
138 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
139 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
140 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
141 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
142 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
143 /// CHECK-DAG: Return [<<And>>]
144
145 /// CHECK-START: int Main.UShr28And7(int) instruction_simplifier (after)
146 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
147 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
148 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
149 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
150 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
151 /// CHECK-DAG: Return [<<And>>]
152
153 public static int UShr28And7(int arg) {
154 return (arg >>> 28) & 7;
155 }
156
157 /// CHECK-START: long Main.UShr60And7(long) instruction_simplifier (before)
158 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
159 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
160 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
161 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
162 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
163 /// CHECK-DAG: Return [<<And>>]
164
165 /// CHECK-START: long Main.UShr60And7(long) instruction_simplifier (after)
166 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
167 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
168 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
169 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
170 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
171 /// CHECK-DAG: Return [<<And>>]
172
173 public static long UShr60And7(long arg) {
174 return (arg >>> 60) & 7;
175 }
176
177 /// CHECK-START: int Main.Shr24And255(int) instruction_simplifier (before)
178 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
179 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
180 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
181 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
182 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const255>>]
183 /// CHECK-DAG: Return [<<And>>]
184
185 /// CHECK-START: int Main.Shr24And255(int) instruction_simplifier (after)
186 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
187 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
188 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const24>>]
189 /// CHECK-DAG: Return [<<UShr>>]
190
191 /// CHECK-START: int Main.Shr24And255(int) instruction_simplifier (after)
192 /// CHECK-NOT: Shr
193 /// CHECK-NOT: And
194
195 public static int Shr24And255(int arg) {
196 return (arg >> 24) & 255;
197 }
198
199 /// CHECK-START: long Main.Shr56And255(long) instruction_simplifier (before)
200 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
201 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
202 /// CHECK-DAG: <<Const255:j\d+>> LongConstant 255
203 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
204 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const255>>]
205 /// CHECK-DAG: Return [<<And>>]
206
207 /// CHECK-START: long Main.Shr56And255(long) instruction_simplifier (after)
208 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
209 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
210 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const56>>]
211 /// CHECK-DAG: Return [<<UShr>>]
212
213 /// CHECK-START: long Main.Shr56And255(long) instruction_simplifier (after)
214 /// CHECK-NOT: Shr
215 /// CHECK-NOT: And
216
217 public static long Shr56And255(long arg) {
218 return (arg >> 56) & 255;
219 }
220
221 /// CHECK-START: int Main.Shr24And127(int) instruction_simplifier (before)
222 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
223 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
224 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
225 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
226 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
227 /// CHECK-DAG: Return [<<And>>]
228
229 /// CHECK-START: int Main.Shr24And127(int) instruction_simplifier (after)
230 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
231 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
232 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
233 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
234 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
235 /// CHECK-DAG: Return [<<And>>]
236
237 public static int Shr24And127(int arg) {
238 return (arg >> 24) & 127;
239 }
240
241 /// CHECK-START: long Main.Shr56And127(long) instruction_simplifier (before)
242 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
243 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
244 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
245 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
246 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
247 /// CHECK-DAG: Return [<<And>>]
248
249 /// CHECK-START: long Main.Shr56And127(long) instruction_simplifier (after)
250 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
251 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
252 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
253 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
254 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
255 /// CHECK-DAG: Return [<<And>>]
256
257 public static long Shr56And127(long arg) {
258 return (arg >> 56) & 127;
259 }
260
David Brazdila06d66a2015-05-28 11:14:54 +0100261 /// CHECK-START: long Main.Div1(long) instruction_simplifier (before)
262 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
263 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
264 /// CHECK-DAG: <<Div:j\d+>> Div [<<Arg>>,<<Const1>>]
265 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000266
David Brazdila06d66a2015-05-28 11:14:54 +0100267 /// CHECK-START: long Main.Div1(long) instruction_simplifier (after)
268 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
269 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000270
David Brazdila06d66a2015-05-28 11:14:54 +0100271 /// CHECK-START: long Main.Div1(long) instruction_simplifier (after)
272 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100273
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000274 public static long Div1(long arg) {
275 return arg / 1;
276 }
277
David Brazdila06d66a2015-05-28 11:14:54 +0100278 /// CHECK-START: int Main.DivN1(int) instruction_simplifier (before)
279 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
280 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
281 /// CHECK-DAG: <<Div:i\d+>> Div [<<Arg>>,<<ConstN1>>]
282 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000283
David Brazdila06d66a2015-05-28 11:14:54 +0100284 /// CHECK-START: int Main.DivN1(int) instruction_simplifier (after)
285 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
286 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
287 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000288
David Brazdila06d66a2015-05-28 11:14:54 +0100289 /// CHECK-START: int Main.DivN1(int) instruction_simplifier (after)
290 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100291
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000292 public static int DivN1(int arg) {
293 return arg / -1;
294 }
295
David Brazdila06d66a2015-05-28 11:14:54 +0100296 /// CHECK-START: long Main.Mul1(long) instruction_simplifier (before)
297 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
298 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
David Brazdil57e863c2016-01-11 10:27:13 +0000299 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const1>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100300 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000301
David Brazdila06d66a2015-05-28 11:14:54 +0100302 /// CHECK-START: long Main.Mul1(long) instruction_simplifier (after)
303 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
304 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000305
David Brazdila06d66a2015-05-28 11:14:54 +0100306 /// CHECK-START: long Main.Mul1(long) instruction_simplifier (after)
307 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100308
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000309 public static long Mul1(long arg) {
310 return arg * 1;
311 }
312
David Brazdila06d66a2015-05-28 11:14:54 +0100313 /// CHECK-START: int Main.MulN1(int) instruction_simplifier (before)
314 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
315 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
316 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Arg>>,<<ConstN1>>]
317 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000318
David Brazdila06d66a2015-05-28 11:14:54 +0100319 /// CHECK-START: int Main.MulN1(int) instruction_simplifier (after)
320 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
321 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
322 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000323
David Brazdila06d66a2015-05-28 11:14:54 +0100324 /// CHECK-START: int Main.MulN1(int) instruction_simplifier (after)
325 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100326
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000327 public static int MulN1(int arg) {
328 return arg * -1;
329 }
330
David Brazdila06d66a2015-05-28 11:14:54 +0100331 /// CHECK-START: long Main.MulPowerOfTwo128(long) instruction_simplifier (before)
332 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
333 /// CHECK-DAG: <<Const128:j\d+>> LongConstant 128
David Brazdil57e863c2016-01-11 10:27:13 +0000334 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const128>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100335 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000336
David Brazdila06d66a2015-05-28 11:14:54 +0100337 /// CHECK-START: long Main.MulPowerOfTwo128(long) instruction_simplifier (after)
338 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
339 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
340 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Arg>>,<<Const7>>]
341 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000342
David Brazdila06d66a2015-05-28 11:14:54 +0100343 /// CHECK-START: long Main.MulPowerOfTwo128(long) instruction_simplifier (after)
344 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100345
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000346 public static long MulPowerOfTwo128(long arg) {
347 return arg * 128;
348 }
349
David Brazdila06d66a2015-05-28 11:14:54 +0100350 /// CHECK-START: int Main.Or0(int) instruction_simplifier (before)
351 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
352 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
353 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<Const0>>]
354 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000355
David Brazdila06d66a2015-05-28 11:14:54 +0100356 /// CHECK-START: int Main.Or0(int) instruction_simplifier (after)
357 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
358 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000359
David Brazdila06d66a2015-05-28 11:14:54 +0100360 /// CHECK-START: int Main.Or0(int) instruction_simplifier (after)
361 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100362
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000363 public static int Or0(int arg) {
364 return arg | 0;
365 }
366
David Brazdila06d66a2015-05-28 11:14:54 +0100367 /// CHECK-START: long Main.OrSame(long) instruction_simplifier (before)
368 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
369 /// CHECK-DAG: <<Or:j\d+>> Or [<<Arg>>,<<Arg>>]
370 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000371
David Brazdila06d66a2015-05-28 11:14:54 +0100372 /// CHECK-START: long Main.OrSame(long) instruction_simplifier (after)
373 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
374 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000375
David Brazdila06d66a2015-05-28 11:14:54 +0100376 /// CHECK-START: long Main.OrSame(long) instruction_simplifier (after)
377 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100378
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000379 public static long OrSame(long arg) {
380 return arg | arg;
381 }
382
David Brazdila06d66a2015-05-28 11:14:54 +0100383 /// CHECK-START: int Main.Shl0(int) instruction_simplifier (before)
384 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
385 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
386 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Arg>>,<<Const0>>]
387 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000388
David Brazdila06d66a2015-05-28 11:14:54 +0100389 /// CHECK-START: int Main.Shl0(int) instruction_simplifier (after)
390 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
391 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000392
David Brazdila06d66a2015-05-28 11:14:54 +0100393 /// CHECK-START: int Main.Shl0(int) instruction_simplifier (after)
394 /// CHECK-NOT: Shl
Alexandre Rames74417692015-04-09 15:21:41 +0100395
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000396 public static int Shl0(int arg) {
397 return arg << 0;
398 }
399
David Brazdila06d66a2015-05-28 11:14:54 +0100400 /// CHECK-START: long Main.Shr0(long) instruction_simplifier (before)
401 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
402 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
403 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const0>>]
404 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000405
David Brazdila06d66a2015-05-28 11:14:54 +0100406 /// CHECK-START: long Main.Shr0(long) instruction_simplifier (after)
407 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
408 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000409
David Brazdila06d66a2015-05-28 11:14:54 +0100410 /// CHECK-START: long Main.Shr0(long) instruction_simplifier (after)
411 /// CHECK-NOT: Shr
Alexandre Rames74417692015-04-09 15:21:41 +0100412
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000413 public static long Shr0(long arg) {
414 return arg >> 0;
415 }
416
David Brazdila06d66a2015-05-28 11:14:54 +0100417 /// CHECK-START: long Main.Sub0(long) instruction_simplifier (before)
418 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
419 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
420 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Const0>>]
421 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000422
David Brazdila06d66a2015-05-28 11:14:54 +0100423 /// CHECK-START: long Main.Sub0(long) instruction_simplifier (after)
424 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
425 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000426
David Brazdila06d66a2015-05-28 11:14:54 +0100427 /// CHECK-START: long Main.Sub0(long) instruction_simplifier (after)
428 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100429
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000430 public static long Sub0(long arg) {
431 return arg - 0;
432 }
433
David Brazdila06d66a2015-05-28 11:14:54 +0100434 /// CHECK-START: int Main.SubAliasNeg(int) instruction_simplifier (before)
435 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
436 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
437 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const0>>,<<Arg>>]
438 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000439
David Brazdila06d66a2015-05-28 11:14:54 +0100440 /// CHECK-START: int Main.SubAliasNeg(int) instruction_simplifier (after)
441 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
442 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
443 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000444
David Brazdila06d66a2015-05-28 11:14:54 +0100445 /// CHECK-START: int Main.SubAliasNeg(int) instruction_simplifier (after)
446 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100447
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000448 public static int SubAliasNeg(int arg) {
449 return 0 - arg;
450 }
451
David Brazdila06d66a2015-05-28 11:14:54 +0100452 /// CHECK-START: long Main.UShr0(long) instruction_simplifier (before)
453 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
454 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
455 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const0>>]
456 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000457
David Brazdila06d66a2015-05-28 11:14:54 +0100458 /// CHECK-START: long Main.UShr0(long) instruction_simplifier (after)
459 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
460 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000461
David Brazdila06d66a2015-05-28 11:14:54 +0100462 /// CHECK-START: long Main.UShr0(long) instruction_simplifier (after)
463 /// CHECK-NOT: UShr
Alexandre Rames74417692015-04-09 15:21:41 +0100464
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000465 public static long UShr0(long arg) {
466 return arg >>> 0;
467 }
468
David Brazdila06d66a2015-05-28 11:14:54 +0100469 /// CHECK-START: int Main.Xor0(int) instruction_simplifier (before)
470 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
471 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
472 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Const0>>]
473 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000474
David Brazdila06d66a2015-05-28 11:14:54 +0100475 /// CHECK-START: int Main.Xor0(int) instruction_simplifier (after)
476 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
477 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000478
David Brazdila06d66a2015-05-28 11:14:54 +0100479 /// CHECK-START: int Main.Xor0(int) instruction_simplifier (after)
480 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100481
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000482 public static int Xor0(int arg) {
483 return arg ^ 0;
484 }
485
David Brazdila06d66a2015-05-28 11:14:54 +0100486 /// CHECK-START: int Main.XorAllOnes(int) instruction_simplifier (before)
487 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
488 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
489 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<ConstF>>]
490 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000491
David Brazdila06d66a2015-05-28 11:14:54 +0100492 /// CHECK-START: int Main.XorAllOnes(int) instruction_simplifier (after)
493 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
494 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
495 /// CHECK-DAG: Return [<<Not>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000496
David Brazdila06d66a2015-05-28 11:14:54 +0100497 /// CHECK-START: int Main.XorAllOnes(int) instruction_simplifier (after)
498 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100499
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000500 public static int XorAllOnes(int arg) {
501 return arg ^ -1;
502 }
503
Alexandre Rames188d4312015-04-09 18:30:21 +0100504 /**
505 * Test that addition or subtraction operation with both inputs negated are
506 * optimized to use a single negation after the operation.
507 * The transformation tested is implemented in
508 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
509 */
510
David Brazdila06d66a2015-05-28 11:14:54 +0100511 /// CHECK-START: int Main.AddNegs1(int, int) instruction_simplifier (before)
512 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
513 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
514 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
515 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
516 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
517 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100518
David Brazdila06d66a2015-05-28 11:14:54 +0100519 /// CHECK-START: int Main.AddNegs1(int, int) instruction_simplifier (after)
520 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
521 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
522 /// CHECK-NOT: Neg
523 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
524 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
525 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100526
527 public static int AddNegs1(int arg1, int arg2) {
528 return -arg1 + -arg2;
529 }
530
531 /**
532 * This is similar to the test-case AddNegs1, but the negations have
533 * multiple uses.
534 * The transformation tested is implemented in
535 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
536 * The current code won't perform the previous optimization. The
537 * transformations do not look at other uses of their inputs. As they don't
538 * know what will happen with other uses, they do not take the risk of
539 * increasing the register pressure by creating or extending live ranges.
540 */
541
David Brazdila06d66a2015-05-28 11:14:54 +0100542 /// CHECK-START: int Main.AddNegs2(int, int) instruction_simplifier (before)
543 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
544 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
545 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
546 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
547 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
548 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
549 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
550 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100551
David Brazdila06d66a2015-05-28 11:14:54 +0100552 /// CHECK-START: int Main.AddNegs2(int, int) instruction_simplifier (after)
553 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
554 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
555 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
556 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
557 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
558 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
559 /// CHECK-NOT: Neg
560 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
561 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100562
David Brazdila06d66a2015-05-28 11:14:54 +0100563 /// CHECK-START: int Main.AddNegs2(int, int) GVN (after)
564 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
565 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
566 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
567 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
568 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
569 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add>>,<<Add>>]
570 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100571
Alexandre Rames188d4312015-04-09 18:30:21 +0100572 public static int AddNegs2(int arg1, int arg2) {
573 int temp1 = -arg1;
574 int temp2 = -arg2;
575 return (temp1 + temp2) | (temp1 + temp2);
576 }
577
578 /**
579 * This follows test-cases AddNegs1 and AddNegs2.
580 * The transformation tested is implemented in
581 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
582 * The optimization should not happen if it moves an additional instruction in
583 * the loop.
584 */
585
David Brazdila06d66a2015-05-28 11:14:54 +0100586 /// CHECK-START: long Main.AddNegs3(long, long) instruction_simplifier (before)
587 // -------------- Arguments and initial negation operations.
588 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
589 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
590 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
591 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
592 /// CHECK: Goto
593 // -------------- Loop
594 /// CHECK: SuspendCheck
595 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
596 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100597
David Brazdila06d66a2015-05-28 11:14:54 +0100598 /// CHECK-START: long Main.AddNegs3(long, long) instruction_simplifier (after)
599 // -------------- Arguments and initial negation operations.
600 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
601 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
602 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
603 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
604 /// CHECK: Goto
605 // -------------- Loop
606 /// CHECK: SuspendCheck
607 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
608 /// CHECK-NOT: Neg
609 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100610
611 public static long AddNegs3(long arg1, long arg2) {
612 long res = 0;
613 long n_arg1 = -arg1;
614 long n_arg2 = -arg2;
615 for (long i = 0; i < 1; i++) {
616 res += n_arg1 + n_arg2 + i;
617 }
618 return res;
619 }
620
621 /**
622 * Test the simplification of an addition with a negated argument into a
623 * subtraction.
624 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
625 */
626
David Brazdila06d66a2015-05-28 11:14:54 +0100627 /// CHECK-START: long Main.AddNeg1(long, long) instruction_simplifier (before)
628 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
629 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
630 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
631 /// CHECK-DAG: <<Add:j\d+>> Add [<<Neg>>,<<Arg2>>]
632 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100633
David Brazdila06d66a2015-05-28 11:14:54 +0100634 /// CHECK-START: long Main.AddNeg1(long, long) instruction_simplifier (after)
635 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
636 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
637 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg2>>,<<Arg1>>]
638 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100639
David Brazdila06d66a2015-05-28 11:14:54 +0100640 /// CHECK-START: long Main.AddNeg1(long, long) instruction_simplifier (after)
641 /// CHECK-NOT: Neg
642 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100643
644 public static long AddNeg1(long arg1, long arg2) {
645 return -arg1 + arg2;
646 }
647
648 /**
649 * This is similar to the test-case AddNeg1, but the negation has two uses.
650 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
651 * The current code won't perform the previous optimization. The
652 * transformations do not look at other uses of their inputs. As they don't
653 * know what will happen with other uses, they do not take the risk of
654 * increasing the register pressure by creating or extending live ranges.
655 */
656
David Brazdila06d66a2015-05-28 11:14:54 +0100657 /// CHECK-START: long Main.AddNeg2(long, long) instruction_simplifier (before)
658 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
659 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
660 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
661 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
662 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
663 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
664 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100665
David Brazdila06d66a2015-05-28 11:14:54 +0100666 /// CHECK-START: long Main.AddNeg2(long, long) instruction_simplifier (after)
667 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
668 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
669 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
670 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
671 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
672 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
673 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100674
David Brazdila06d66a2015-05-28 11:14:54 +0100675 /// CHECK-START: long Main.AddNeg2(long, long) instruction_simplifier (after)
676 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100677
678 public static long AddNeg2(long arg1, long arg2) {
679 long temp = -arg2;
680 return (arg1 + temp) | (arg1 + temp);
681 }
682
683 /**
684 * Test simplification of the `-(-var)` pattern.
685 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
686 */
687
David Brazdila06d66a2015-05-28 11:14:54 +0100688 /// CHECK-START: long Main.NegNeg1(long) instruction_simplifier (before)
689 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
690 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg>>]
691 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Neg1>>]
692 /// CHECK-DAG: Return [<<Neg2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100693
David Brazdila06d66a2015-05-28 11:14:54 +0100694 /// CHECK-START: long Main.NegNeg1(long) instruction_simplifier (after)
695 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
696 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100697
David Brazdila06d66a2015-05-28 11:14:54 +0100698 /// CHECK-START: long Main.NegNeg1(long) instruction_simplifier (after)
699 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100700
701 public static long NegNeg1(long arg) {
702 return -(-arg);
703 }
704
705 /**
706 * Test 'multi-step' simplification, where a first transformation yields a
707 * new simplification possibility for the current instruction.
708 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
709 * and in `InstructionSimplifierVisitor::VisitAdd`.
710 */
711
David Brazdila06d66a2015-05-28 11:14:54 +0100712 /// CHECK-START: int Main.NegNeg2(int) instruction_simplifier (before)
713 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
714 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg>>]
715 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Neg1>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000716 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg2>>,<<Neg1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100717 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100718
David Brazdila06d66a2015-05-28 11:14:54 +0100719 /// CHECK-START: int Main.NegNeg2(int) instruction_simplifier (after)
720 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
721 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg>>,<<Arg>>]
722 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100723
David Brazdila06d66a2015-05-28 11:14:54 +0100724 /// CHECK-START: int Main.NegNeg2(int) instruction_simplifier (after)
725 /// CHECK-NOT: Neg
726 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100727
David Brazdila06d66a2015-05-28 11:14:54 +0100728 /// CHECK-START: int Main.NegNeg2(int) constant_folding_after_inlining (after)
729 /// CHECK: <<Const0:i\d+>> IntConstant 0
730 /// CHECK-NOT: Neg
731 /// CHECK-NOT: Add
732 /// CHECK: Return [<<Const0>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100733
Alexandre Rames188d4312015-04-09 18:30:21 +0100734 public static int NegNeg2(int arg) {
735 int temp = -arg;
736 return temp + -temp;
737 }
738
739 /**
740 * Test another 'multi-step' simplification, where a first transformation
741 * yields a new simplification possibility for the current instruction.
742 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
743 * and in `InstructionSimplifierVisitor::VisitSub`.
744 */
745
David Brazdila06d66a2015-05-28 11:14:54 +0100746 /// CHECK-START: long Main.NegNeg3(long) instruction_simplifier (before)
747 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
748 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
749 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg>>]
750 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const0>>,<<Neg>>]
751 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100752
David Brazdila06d66a2015-05-28 11:14:54 +0100753 /// CHECK-START: long Main.NegNeg3(long) instruction_simplifier (after)
754 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
755 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100756
David Brazdila06d66a2015-05-28 11:14:54 +0100757 /// CHECK-START: long Main.NegNeg3(long) instruction_simplifier (after)
758 /// CHECK-NOT: Neg
759 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100760
761 public static long NegNeg3(long arg) {
762 return 0 - -arg;
763 }
764
765 /**
766 * Test that a negated subtraction is simplified to a subtraction with its
767 * arguments reversed.
768 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
769 */
770
David Brazdila06d66a2015-05-28 11:14:54 +0100771 /// CHECK-START: int Main.NegSub1(int, int) instruction_simplifier (before)
772 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
773 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
774 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
775 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Sub>>]
776 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100777
David Brazdila06d66a2015-05-28 11:14:54 +0100778 /// CHECK-START: int Main.NegSub1(int, int) instruction_simplifier (after)
779 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
780 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
781 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg2>>,<<Arg1>>]
782 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100783
David Brazdila06d66a2015-05-28 11:14:54 +0100784 /// CHECK-START: int Main.NegSub1(int, int) instruction_simplifier (after)
785 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100786
787 public static int NegSub1(int arg1, int arg2) {
788 return -(arg1 - arg2);
789 }
790
791 /**
792 * This is similar to the test-case NegSub1, but the subtraction has
793 * multiple uses.
794 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
795 * The current code won't perform the previous optimization. The
796 * transformations do not look at other uses of their inputs. As they don't
797 * know what will happen with other uses, they do not take the risk of
798 * increasing the register pressure by creating or extending live ranges.
799 */
800
David Brazdila06d66a2015-05-28 11:14:54 +0100801 /// CHECK-START: int Main.NegSub2(int, int) instruction_simplifier (before)
802 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
803 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
804 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
805 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
806 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
807 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
808 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100809
David Brazdila06d66a2015-05-28 11:14:54 +0100810 /// CHECK-START: int Main.NegSub2(int, int) instruction_simplifier (after)
811 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
812 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
813 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
814 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
815 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
816 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
817 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100818
819 public static int NegSub2(int arg1, int arg2) {
820 int temp = arg1 - arg2;
821 return -temp | -temp;
822 }
823
824 /**
825 * Test simplification of the `~~var` pattern.
826 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`.
827 */
828
David Brazdila06d66a2015-05-28 11:14:54 +0100829 /// CHECK-START: long Main.NotNot1(long) instruction_simplifier (before)
830 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
David Brazdilf02c3cf2016-02-29 09:14:51 +0000831 /// CHECK-DAG: <<Not1:j\d+>> Not [<<Arg>>]
832 /// CHECK-DAG: <<Not2:j\d+>> Not [<<Not1>>]
833 /// CHECK-DAG: Return [<<Not2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100834
David Brazdila06d66a2015-05-28 11:14:54 +0100835 /// CHECK-START: long Main.NotNot1(long) instruction_simplifier (after)
836 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
837 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100838
David Brazdila06d66a2015-05-28 11:14:54 +0100839 /// CHECK-START: long Main.NotNot1(long) instruction_simplifier (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +0000840 /// CHECK-NOT: Not
Alexandre Rames188d4312015-04-09 18:30:21 +0100841
842 public static long NotNot1(long arg) {
843 return ~~arg;
844 }
845
David Brazdila06d66a2015-05-28 11:14:54 +0100846 /// CHECK-START: int Main.NotNot2(int) instruction_simplifier (before)
847 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdilf02c3cf2016-02-29 09:14:51 +0000848 /// CHECK-DAG: <<Not1:i\d+>> Not [<<Arg>>]
849 /// CHECK-DAG: <<Not2:i\d+>> Not [<<Not1>>]
850 /// CHECK-DAG: <<Add:i\d+>> Add [<<Not2>>,<<Not1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100851 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100852
David Brazdila06d66a2015-05-28 11:14:54 +0100853 /// CHECK-START: int Main.NotNot2(int) instruction_simplifier (after)
854 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
855 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000856 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg>>,<<Not>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100857 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100858
David Brazdila06d66a2015-05-28 11:14:54 +0100859 /// CHECK-START: int Main.NotNot2(int) instruction_simplifier (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +0000860 /// CHECK: Not
861 /// CHECK-NOT: Not
Alexandre Rames188d4312015-04-09 18:30:21 +0100862
863 public static int NotNot2(int arg) {
864 int temp = ~arg;
865 return temp + ~temp;
866 }
867
868 /**
869 * Test the simplification of a subtraction with a negated argument.
870 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
871 */
872
David Brazdila06d66a2015-05-28 11:14:54 +0100873 /// CHECK-START: int Main.SubNeg1(int, int) instruction_simplifier (before)
874 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
875 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
876 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
877 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Neg>>,<<Arg2>>]
878 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100879
David Brazdila06d66a2015-05-28 11:14:54 +0100880 /// CHECK-START: int Main.SubNeg1(int, int) instruction_simplifier (after)
881 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
882 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
883 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
884 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
885 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100886
David Brazdila06d66a2015-05-28 11:14:54 +0100887 /// CHECK-START: int Main.SubNeg1(int, int) instruction_simplifier (after)
888 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100889
890 public static int SubNeg1(int arg1, int arg2) {
891 return -arg1 - arg2;
892 }
893
894 /**
895 * This is similar to the test-case SubNeg1, but the negation has
896 * multiple uses.
897 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
898 * The current code won't perform the previous optimization. The
899 * transformations do not look at other uses of their inputs. As they don't
900 * know what will happen with other uses, they do not take the risk of
901 * increasing the register pressure by creating or extending live ranges.
902 */
903
David Brazdila06d66a2015-05-28 11:14:54 +0100904 /// CHECK-START: int Main.SubNeg2(int, int) instruction_simplifier (before)
905 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
906 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
907 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
908 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
909 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
910 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
911 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100912
David Brazdila06d66a2015-05-28 11:14:54 +0100913 /// CHECK-START: int Main.SubNeg2(int, int) instruction_simplifier (after)
914 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
915 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
916 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
917 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
918 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
919 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
920 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100921
David Brazdila06d66a2015-05-28 11:14:54 +0100922 /// CHECK-START: int Main.SubNeg2(int, int) instruction_simplifier (after)
923 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100924
925 public static int SubNeg2(int arg1, int arg2) {
926 int temp = -arg1;
927 return (temp - arg2) | (temp - arg2);
928 }
929
930 /**
931 * This follows test-cases SubNeg1 and SubNeg2.
932 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
933 * The optimization should not happen if it moves an additional instruction in
934 * the loop.
935 */
936
David Brazdila06d66a2015-05-28 11:14:54 +0100937 /// CHECK-START: long Main.SubNeg3(long, long) instruction_simplifier (before)
938 // -------------- Arguments and initial negation operation.
939 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
940 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
941 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
942 /// CHECK: Goto
943 // -------------- Loop
944 /// CHECK: SuspendCheck
945 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
946 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100947
David Brazdila06d66a2015-05-28 11:14:54 +0100948 /// CHECK-START: long Main.SubNeg3(long, long) instruction_simplifier (after)
949 // -------------- Arguments and initial negation operation.
950 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
951 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
952 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
953 /// CHECK-DAG: Goto
954 // -------------- Loop
955 /// CHECK: SuspendCheck
956 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
957 /// CHECK-NOT: Neg
958 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100959
960 public static long SubNeg3(long arg1, long arg2) {
961 long res = 0;
962 long temp = -arg1;
963 for (long i = 0; i < 1; i++) {
964 res += temp - arg2 - i;
965 }
966 return res;
967 }
968
David Brazdil1e9ec052015-06-22 10:26:45 +0100969 /// CHECK-START: boolean Main.EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
970 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +0000971 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
972 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +0100973 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +0000974 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
975 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<NotArg>>,<<Const2>>]
976 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
977 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +0100978
979 /// CHECK-START: boolean Main.EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +0000980 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
981 /// CHECK-DAG: Return [<<True>>]
David Brazdil1e9ec052015-06-22 10:26:45 +0100982
983 public static boolean EqualBoolVsIntConst(boolean arg) {
David Brazdil74eb1b22015-12-14 11:44:01 +0000984 return (arg ? 0 : 1) != 2;
David Brazdil1e9ec052015-06-22 10:26:45 +0100985 }
986
987 /// CHECK-START: boolean Main.NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
988 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +0000989 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
990 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +0100991 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +0000992 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
993 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<NotArg>>,<<Const2>>]
994 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
995 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +0100996
997 /// CHECK-START: boolean Main.NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +0000998 /// CHECK-DAG: <<False:i\d+>> IntConstant 0
999 /// CHECK-DAG: Return [<<False>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001000
1001 public static boolean NotEqualBoolVsIntConst(boolean arg) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001002 return (arg ? 0 : 1) == 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001003 }
1004
David Brazdil0d13fee2015-04-17 14:52:19 +01001005 /*
1006 * Test simplification of double Boolean negation. Note that sometimes
1007 * both negations can be removed but we only expect the simplifier to
1008 * remove the second.
1009 */
1010
Nicolas Geoffrayb2bdfce2015-06-18 15:46:47 +01001011 /// CHECK-START: boolean Main.NotNotBool(boolean) instruction_simplifier_after_bce (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001012 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001013 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1014 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1015 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1016 /// CHECK-DAG: <<NotNotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<NotArg>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001017 /// CHECK-DAG: Return [<<NotNotArg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001018
Nicolas Geoffrayb2bdfce2015-06-18 15:46:47 +01001019 /// CHECK-START: boolean Main.NotNotBool(boolean) instruction_simplifier_after_bce (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001020 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdila06d66a2015-05-28 11:14:54 +01001021 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001022
David Brazdil769c9e52015-04-27 13:54:09 +01001023 public static boolean NegateValue(boolean arg) {
1024 return !arg;
1025 }
1026
David Brazdil0d13fee2015-04-17 14:52:19 +01001027 public static boolean NotNotBool(boolean arg) {
David Brazdil769c9e52015-04-27 13:54:09 +01001028 return !(NegateValue(arg));
David Brazdil0d13fee2015-04-17 14:52:19 +01001029 }
1030
David Brazdila06d66a2015-05-28 11:14:54 +01001031 /// CHECK-START: float Main.Div2(float) instruction_simplifier (before)
1032 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1033 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
1034 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>]
1035 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001036
David Brazdila06d66a2015-05-28 11:14:54 +01001037 /// CHECK-START: float Main.Div2(float) instruction_simplifier (after)
1038 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1039 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5
1040 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>]
1041 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001042
David Brazdila06d66a2015-05-28 11:14:54 +01001043 /// CHECK-START: float Main.Div2(float) instruction_simplifier (after)
1044 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001045
1046 public static float Div2(float arg) {
1047 return arg / 2.0f;
1048 }
1049
David Brazdila06d66a2015-05-28 11:14:54 +01001050 /// CHECK-START: double Main.Div2(double) instruction_simplifier (before)
1051 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1052 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
1053 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>]
1054 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001055
David Brazdila06d66a2015-05-28 11:14:54 +01001056 /// CHECK-START: double Main.Div2(double) instruction_simplifier (after)
1057 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1058 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5
1059 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>]
1060 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001061
David Brazdila06d66a2015-05-28 11:14:54 +01001062 /// CHECK-START: double Main.Div2(double) instruction_simplifier (after)
1063 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001064 public static double Div2(double arg) {
1065 return arg / 2.0;
1066 }
1067
David Brazdila06d66a2015-05-28 11:14:54 +01001068 /// CHECK-START: float Main.DivMP25(float) instruction_simplifier (before)
1069 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1070 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25
1071 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>]
1072 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001073
David Brazdila06d66a2015-05-28 11:14:54 +01001074 /// CHECK-START: float Main.DivMP25(float) instruction_simplifier (after)
1075 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1076 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4
1077 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>]
1078 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001079
David Brazdila06d66a2015-05-28 11:14:54 +01001080 /// CHECK-START: float Main.DivMP25(float) instruction_simplifier (after)
1081 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001082
1083 public static float DivMP25(float arg) {
1084 return arg / -0.25f;
1085 }
1086
David Brazdila06d66a2015-05-28 11:14:54 +01001087 /// CHECK-START: double Main.DivMP25(double) instruction_simplifier (before)
1088 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1089 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25
1090 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>]
1091 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001092
David Brazdila06d66a2015-05-28 11:14:54 +01001093 /// CHECK-START: double Main.DivMP25(double) instruction_simplifier (after)
1094 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1095 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4
1096 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>]
1097 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001098
David Brazdila06d66a2015-05-28 11:14:54 +01001099 /// CHECK-START: double Main.DivMP25(double) instruction_simplifier (after)
1100 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001101 public static double DivMP25(double arg) {
1102 return arg / -0.25f;
1103 }
1104
Alexandre Rames38db7852015-11-20 15:02:45 +00001105 /**
1106 * Test strength reduction of factors of the form (2^n + 1).
1107 */
1108
1109 /// CHECK-START: int Main.mulPow2Plus1(int) instruction_simplifier (before)
1110 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1111 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
1112 /// CHECK: Mul [<<Arg>>,<<Const9>>]
1113
1114 /// CHECK-START: int Main.mulPow2Plus1(int) instruction_simplifier (after)
1115 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1116 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1117 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>]
1118 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>]
1119
1120 public static int mulPow2Plus1(int arg) {
1121 return arg * 9;
1122 }
1123
Alexandre Rames38db7852015-11-20 15:02:45 +00001124 /**
1125 * Test strength reduction of factors of the form (2^n - 1).
1126 */
1127
1128 /// CHECK-START: long Main.mulPow2Minus1(long) instruction_simplifier (before)
1129 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1130 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31
David Brazdil57e863c2016-01-11 10:27:13 +00001131 /// CHECK: Mul [<<Const31>>,<<Arg>>]
Alexandre Rames38db7852015-11-20 15:02:45 +00001132
1133 /// CHECK-START: long Main.mulPow2Minus1(long) instruction_simplifier (after)
1134 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1135 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1136 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>]
1137 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>]
1138
1139 public static long mulPow2Minus1(long arg) {
1140 return arg * 31;
1141 }
1142
David Brazdilf02c3cf2016-02-29 09:14:51 +00001143 /// CHECK-START: int Main.booleanFieldNotEqualOne() instruction_simplifier_after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001144 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdilf02c3cf2016-02-29 09:14:51 +00001145 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1146 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Mark Mendellf6529172015-11-17 11:16:56 -05001147 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1148 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +00001149 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1150 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001151
David Brazdilf02c3cf2016-02-29 09:14:51 +00001152 /// CHECK-START: int Main.booleanFieldNotEqualOne() instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001153 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1154 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1155 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1156 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1157 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001158
1159 public static int booleanFieldNotEqualOne() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001160 return (booleanField == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001161 }
1162
David Brazdilf02c3cf2016-02-29 09:14:51 +00001163 /// CHECK-START: int Main.booleanFieldEqualZero() instruction_simplifier_after_bce (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001164 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdilf02c3cf2016-02-29 09:14:51 +00001165 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1166 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Mark Mendellf6529172015-11-17 11:16:56 -05001167 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdilf02c3cf2016-02-29 09:14:51 +00001168 /// CHECK-DAG: <<NE:z\d+>> Equal [<<Field>>,<<Const0>>]
1169 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1170 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001171
David Brazdilf02c3cf2016-02-29 09:14:51 +00001172 /// CHECK-START: int Main.booleanFieldEqualZero() instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001173 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1174 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1175 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1176 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1177 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001178
1179 public static int booleanFieldEqualZero() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001180 return (booleanField != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001181 }
1182
1183 /// CHECK-START: int Main.intConditionNotEqualOne(int) instruction_simplifier_after_bce (before)
1184 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001185 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
Mark Mendellf6529172015-11-17 11:16:56 -05001186 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +00001187 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001188 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001189 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1190 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1191 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001192 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001193 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1194 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001195
1196 /// CHECK-START: int Main.intConditionNotEqualOne(int) instruction_simplifier_after_bce (after)
1197 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001198 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001199 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001200 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1201 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001202 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001203 /// CHECK-DAG: Return [<<Result>>]
1204 // Note that we match `LE` from Select because there are two identical
1205 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001206
1207 public static int intConditionNotEqualOne(int i) {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001208 return ((i > 42) == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001209 }
1210
1211 /// CHECK-START: int Main.intConditionEqualZero(int) instruction_simplifier_after_bce (before)
1212 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1213 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001214 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1215 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001216 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001217 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1218 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1219 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
1220 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>]
1221 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1222 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001223
1224 /// CHECK-START: int Main.intConditionEqualZero(int) instruction_simplifier_after_bce (after)
1225 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001226 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001227 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001228 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1229 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001230 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001231 /// CHECK-DAG: Return [<<Result>>]
1232 // Note that we match `LE` from Select because there are two identical
1233 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001234
1235 public static int intConditionEqualZero(int i) {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001236 return ((i > 42) != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001237 }
1238
1239 // Test that conditions on float/double are not flipped.
1240
David Brazdilbadd8262016-02-02 16:28:56 +00001241 /// CHECK-START: int Main.floatConditionNotEqualOne(float) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001242 /// CHECK: LessThanOrEqual
1243
Mark P Mendell2f10a5f2016-01-25 14:47:50 +00001244 /// CHECK-START: int Main.floatConditionNotEqualOne(float) instruction_simplifier_before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001245 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1246 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1247 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1248 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
1249 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1250 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1251 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001252
1253 public static int floatConditionNotEqualOne(float f) {
1254 return ((f > 42.0f) == true) ? 13 : 54;
1255 }
1256
David Brazdilbadd8262016-02-02 16:28:56 +00001257 /// CHECK-START: int Main.doubleConditionEqualZero(double) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001258 /// CHECK: LessThanOrEqual
1259
Mark P Mendell2f10a5f2016-01-25 14:47:50 +00001260 /// CHECK-START: int Main.doubleConditionEqualZero(double) instruction_simplifier_before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001261 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1262 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1263 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1264 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1265 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1266 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1267 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001268
1269 public static int doubleConditionEqualZero(double d) {
1270 return ((d > 42.0) != false) ? 13 : 54;
1271 }
Alexandre Rames38db7852015-11-20 15:02:45 +00001272
Vladimir Markob52bbde2016-02-12 12:06:05 +00001273 /// CHECK-START: int Main.intToDoubleToInt(int) instruction_simplifier (before)
1274 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1275 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1276 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1277 /// CHECK-DAG: Return [<<Int>>]
1278
1279 /// CHECK-START: int Main.intToDoubleToInt(int) instruction_simplifier (after)
1280 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1281 /// CHECK-DAG: Return [<<Arg>>]
1282
1283 /// CHECK-START: int Main.intToDoubleToInt(int) instruction_simplifier (after)
1284 /// CHECK-NOT: TypeConversion
1285
1286 public static int intToDoubleToInt(int value) {
1287 // Lossless conversion followed by a conversion back.
1288 return (int) (double) value;
1289 }
1290
1291 /// CHECK-START: java.lang.String Main.intToDoubleToIntPrint(int) instruction_simplifier (before)
1292 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1293 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1294 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1295
1296 /// CHECK-START: java.lang.String Main.intToDoubleToIntPrint(int) instruction_simplifier (after)
1297 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1298 /// CHECK-DAG: {{d\d+}} TypeConversion [<<Arg>>]
1299
1300 /// CHECK-START: java.lang.String Main.intToDoubleToIntPrint(int) instruction_simplifier (after)
1301 /// CHECK-DAG: TypeConversion
1302 /// CHECK-NOT: TypeConversion
1303
1304 public static String intToDoubleToIntPrint(int value) {
1305 // Lossless conversion followed by a conversion back
1306 // with another use of the intermediate result.
1307 double d = (double) value;
1308 int i = (int) d;
1309 return "d=" + d + ", i=" + i;
1310 }
1311
1312 /// CHECK-START: int Main.byteToDoubleToInt(byte) instruction_simplifier (before)
1313 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1314 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1315 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1316 /// CHECK-DAG: Return [<<Int>>]
1317
1318 /// CHECK-START: int Main.byteToDoubleToInt(byte) instruction_simplifier (after)
1319 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1320 /// CHECK-DAG: Return [<<Arg>>]
1321
1322 /// CHECK-START: int Main.byteToDoubleToInt(byte) instruction_simplifier (after)
1323 /// CHECK-NOT: TypeConversion
1324
1325 public static int byteToDoubleToInt(byte value) {
1326 // Lossless conversion followed by another conversion, use implicit conversion.
1327 return (int) (double) value;
1328 }
1329
1330 /// CHECK-START: int Main.floatToDoubleToInt(float) instruction_simplifier (before)
1331 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1332 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1333 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1334 /// CHECK-DAG: Return [<<Int>>]
1335
1336 /// CHECK-START: int Main.floatToDoubleToInt(float) instruction_simplifier (after)
1337 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1338 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1339 /// CHECK-DAG: Return [<<Int>>]
1340
1341 /// CHECK-START: int Main.floatToDoubleToInt(float) instruction_simplifier (after)
1342 /// CHECK-DAG: TypeConversion
1343 /// CHECK-NOT: TypeConversion
1344
1345 public static int floatToDoubleToInt(float value) {
1346 // Lossless conversion followed by another conversion.
1347 return (int) (double) value;
1348 }
1349
1350 /// CHECK-START: java.lang.String Main.floatToDoubleToIntPrint(float) instruction_simplifier (before)
1351 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1352 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1353 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1354
1355 /// CHECK-START: java.lang.String Main.floatToDoubleToIntPrint(float) instruction_simplifier (after)
1356 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1357 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1358 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1359
1360 public static String floatToDoubleToIntPrint(float value) {
1361 // Lossless conversion followed by another conversion with
1362 // an extra use of the intermediate result.
1363 double d = (double) value;
1364 int i = (int) d;
1365 return "d=" + d + ", i=" + i;
1366 }
1367
1368 /// CHECK-START: short Main.byteToDoubleToShort(byte) instruction_simplifier (before)
1369 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1370 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1371 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1372 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1373 /// CHECK-DAG: Return [<<Short>>]
1374
1375 /// CHECK-START: short Main.byteToDoubleToShort(byte) instruction_simplifier (after)
1376 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1377 /// CHECK-DAG: Return [<<Arg>>]
1378
1379 /// CHECK-START: short Main.byteToDoubleToShort(byte) instruction_simplifier (after)
1380 /// CHECK-NOT: TypeConversion
1381
1382 public static short byteToDoubleToShort(byte value) {
1383 // Originally, this is byte->double->int->short. The first conversion is lossless,
1384 // so we merge this with the second one to byte->int which we omit as it's an implicit
1385 // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1386 return (short) (double) value;
1387 }
1388
1389 /// CHECK-START: short Main.charToDoubleToShort(char) instruction_simplifier (before)
1390 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1391 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1392 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1393 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1394 /// CHECK-DAG: Return [<<Short>>]
1395
1396 /// CHECK-START: short Main.charToDoubleToShort(char) instruction_simplifier (after)
1397 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1398 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Arg>>]
1399 /// CHECK-DAG: Return [<<Short>>]
1400
1401 /// CHECK-START: short Main.charToDoubleToShort(char) instruction_simplifier (after)
1402 /// CHECK-DAG: TypeConversion
1403 /// CHECK-NOT: TypeConversion
1404
1405 public static short charToDoubleToShort(char value) {
1406 // Originally, this is char->double->int->short. The first conversion is lossless,
1407 // so we merge this with the second one to char->int which we omit as it's an implicit
1408 // conversion. Then we are left with the resulting char->short conversion.
1409 return (short) (double) value;
1410 }
1411
1412 /// CHECK-START: short Main.floatToIntToShort(float) instruction_simplifier (before)
1413 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1414 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1415 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1416 /// CHECK-DAG: Return [<<Short>>]
1417
1418 /// CHECK-START: short Main.floatToIntToShort(float) instruction_simplifier (after)
1419 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1420 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1421 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1422 /// CHECK-DAG: Return [<<Short>>]
1423
1424 public static short floatToIntToShort(float value) {
1425 // Lossy FP to integral conversion followed by another conversion: no simplification.
1426 return (short) value;
1427 }
1428
1429 /// CHECK-START: int Main.intToFloatToInt(int) instruction_simplifier (before)
1430 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1431 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1432 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1433 /// CHECK-DAG: Return [<<Int>>]
1434
1435 /// CHECK-START: int Main.intToFloatToInt(int) instruction_simplifier (after)
1436 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1437 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1438 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1439 /// CHECK-DAG: Return [<<Int>>]
1440
1441 public static int intToFloatToInt(int value) {
1442 // Lossy integral to FP conversion followed another conversion: no simplification.
1443 return (int) (float) value;
1444 }
1445
1446 /// CHECK-START: double Main.longToIntToDouble(long) instruction_simplifier (before)
1447 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1448 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1449 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1450 /// CHECK-DAG: Return [<<Double>>]
1451
1452 /// CHECK-START: double Main.longToIntToDouble(long) instruction_simplifier (after)
1453 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1454 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1455 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1456 /// CHECK-DAG: Return [<<Double>>]
1457
1458 public static double longToIntToDouble(long value) {
1459 // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1460 return (double) (int) value;
1461 }
1462
1463 /// CHECK-START: long Main.longToIntToLong(long) instruction_simplifier (before)
1464 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1465 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1466 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1467 /// CHECK-DAG: Return [<<Long>>]
1468
1469 /// CHECK-START: long Main.longToIntToLong(long) instruction_simplifier (after)
1470 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1471 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1472 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1473 /// CHECK-DAG: Return [<<Long>>]
1474
1475 public static long longToIntToLong(long value) {
1476 // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1477 return (long) (int) value;
1478 }
1479
1480 /// CHECK-START: short Main.shortToCharToShort(short) instruction_simplifier (before)
1481 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1482 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1483 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Char>>]
1484 /// CHECK-DAG: Return [<<Short>>]
1485
1486 /// CHECK-START: short Main.shortToCharToShort(short) instruction_simplifier (after)
1487 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1488 /// CHECK-DAG: Return [<<Arg>>]
1489
1490 public static short shortToCharToShort(short value) {
1491 // Integral conversion followed by non-widening integral conversion to original type.
1492 return (short) (char) value;
1493 }
1494
1495 /// CHECK-START: int Main.shortToLongToInt(short) instruction_simplifier (before)
1496 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1497 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1498 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Long>>]
1499 /// CHECK-DAG: Return [<<Int>>]
1500
1501 /// CHECK-START: int Main.shortToLongToInt(short) instruction_simplifier (after)
1502 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1503 /// CHECK-DAG: Return [<<Arg>>]
1504
1505 public static int shortToLongToInt(short value) {
1506 // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1507 return (int) (long) value;
1508 }
1509
1510 /// CHECK-START: byte Main.shortToCharToByte(short) instruction_simplifier (before)
1511 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1512 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1513 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Char>>]
1514 /// CHECK-DAG: Return [<<Byte>>]
1515
1516 /// CHECK-START: byte Main.shortToCharToByte(short) instruction_simplifier (after)
1517 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1518 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1519 /// CHECK-DAG: Return [<<Byte>>]
1520
1521 public static byte shortToCharToByte(short value) {
1522 // Integral conversion followed by non-widening integral conversion losing bits
1523 // from the original type. Simplify to use only one conversion.
1524 return (byte) (char) value;
1525 }
1526
1527 /// CHECK-START: java.lang.String Main.shortToCharToBytePrint(short) instruction_simplifier (before)
1528 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1529 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1530 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1531
1532 /// CHECK-START: java.lang.String Main.shortToCharToBytePrint(short) instruction_simplifier (after)
1533 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1534 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1535 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1536
1537 public static String shortToCharToBytePrint(short value) {
1538 // Integral conversion followed by non-widening integral conversion losing bits
1539 // from the original type with an extra use of the intermediate result.
1540 char c = (char) value;
1541 byte b = (byte) c;
1542 return "c=" + ((int) c) + ", b=" + ((int) b); // implicit conversions.
1543 }
1544
Vladimir Marko8428bd32016-02-12 16:53:57 +00001545 /// CHECK-START: byte Main.longAnd0xffToByte(long) instruction_simplifier (before)
1546 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1547 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 255
1548 /// CHECK-DAG: <<And:j\d+>> And [<<Mask>>,<<Arg>>]
1549 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<And>>]
1550 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Int>>]
1551 /// CHECK-DAG: Return [<<Byte>>]
1552
1553 /// CHECK-START: byte Main.longAnd0xffToByte(long) instruction_simplifier (after)
1554 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1555 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1556 /// CHECK-DAG: Return [<<Byte>>]
1557
1558 /// CHECK-START: byte Main.longAnd0xffToByte(long) instruction_simplifier (after)
1559 /// CHECK-NOT: And
1560
1561 public static byte longAnd0xffToByte(long value) {
1562 return (byte) (value & 0xff);
1563 }
1564
1565 /// CHECK-START: char Main.intAnd0x1ffffToChar(int) instruction_simplifier (before)
1566 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1567 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 131071
1568 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1569 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<And>>]
1570 /// CHECK-DAG: Return [<<Char>>]
1571
1572 /// CHECK-START: char Main.intAnd0x1ffffToChar(int) instruction_simplifier (after)
1573 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1574 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1575 /// CHECK-DAG: Return [<<Char>>]
1576
1577 /// CHECK-START: char Main.intAnd0x1ffffToChar(int) instruction_simplifier (after)
1578 /// CHECK-NOT: And
1579
1580 public static char intAnd0x1ffffToChar(int value) {
1581 // Keeping all significant bits and one more.
1582 return (char) (value & 0x1ffff);
1583 }
1584
1585 /// CHECK-START: short Main.intAnd0x17fffToShort(int) instruction_simplifier (before)
1586 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1587 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1588 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1589 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1590 /// CHECK-DAG: Return [<<Short>>]
1591
1592 /// CHECK-START: short Main.intAnd0x17fffToShort(int) instruction_simplifier (after)
1593 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1594 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1595 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1596 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1597 /// CHECK-DAG: Return [<<Short>>]
1598
1599 public static short intAnd0x17fffToShort(int value) {
1600 // No simplification: clearing a significant bit.
1601 return (short) (value & 0x17fff);
1602 }
1603
David Brazdilf02c3cf2016-02-29 09:14:51 +00001604 public static int runSmaliTest(String name, boolean input) {
1605 try {
1606 Class<?> c = Class.forName("SmaliTests");
1607 Method m = c.getMethod(name, new Class[] { boolean.class });
1608 return (Integer) m.invoke(null, input);
1609 } catch (Exception ex) {
1610 throw new Error(ex);
1611 }
1612 }
1613
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001614 public static void main(String[] args) {
1615 int arg = 123456;
1616
1617 assertLongEquals(Add0(arg), arg);
1618 assertIntEquals(AndAllOnes(arg), arg);
1619 assertLongEquals(Div1(arg), arg);
1620 assertIntEquals(DivN1(arg), -arg);
1621 assertLongEquals(Mul1(arg), arg);
1622 assertIntEquals(MulN1(arg), -arg);
1623 assertLongEquals(MulPowerOfTwo128(arg), (128 * arg));
1624 assertIntEquals(Or0(arg), arg);
1625 assertLongEquals(OrSame(arg), arg);
1626 assertIntEquals(Shl0(arg), arg);
1627 assertLongEquals(Shr0(arg), arg);
1628 assertLongEquals(Sub0(arg), arg);
1629 assertIntEquals(SubAliasNeg(arg), -arg);
1630 assertLongEquals(UShr0(arg), arg);
1631 assertIntEquals(Xor0(arg), arg);
1632 assertIntEquals(XorAllOnes(arg), ~arg);
Alexandre Rames188d4312015-04-09 18:30:21 +01001633 assertIntEquals(AddNegs1(arg, arg + 1), -(arg + arg + 1));
1634 assertIntEquals(AddNegs2(arg, arg + 1), -(arg + arg + 1));
1635 assertLongEquals(AddNegs3(arg, arg + 1), -(2 * arg + 1));
1636 assertLongEquals(AddNeg1(arg, arg + 1), 1);
1637 assertLongEquals(AddNeg2(arg, arg + 1), -1);
1638 assertLongEquals(NegNeg1(arg), arg);
1639 assertIntEquals(NegNeg2(arg), 0);
1640 assertLongEquals(NegNeg3(arg), arg);
1641 assertIntEquals(NegSub1(arg, arg + 1), 1);
1642 assertIntEquals(NegSub2(arg, arg + 1), 1);
1643 assertLongEquals(NotNot1(arg), arg);
1644 assertIntEquals(NotNot2(arg), -1);
1645 assertIntEquals(SubNeg1(arg, arg + 1), -(arg + arg + 1));
1646 assertIntEquals(SubNeg2(arg, arg + 1), -(arg + arg + 1));
1647 assertLongEquals(SubNeg3(arg, arg + 1), -(2 * arg + 1));
David Brazdil74eb1b22015-12-14 11:44:01 +00001648 assertBooleanEquals(EqualBoolVsIntConst(true), true);
1649 assertBooleanEquals(EqualBoolVsIntConst(true), true);
1650 assertBooleanEquals(NotEqualBoolVsIntConst(false), false);
1651 assertBooleanEquals(NotEqualBoolVsIntConst(false), false);
David Brazdil0d13fee2015-04-17 14:52:19 +01001652 assertBooleanEquals(NotNotBool(true), true);
1653 assertBooleanEquals(NotNotBool(false), false);
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001654 assertFloatEquals(Div2(100.0f), 50.0f);
1655 assertDoubleEquals(Div2(150.0), 75.0);
1656 assertFloatEquals(DivMP25(100.0f), -400.0f);
1657 assertDoubleEquals(DivMP25(150.0), -600.0);
Vladimir Marko452c1b62015-09-25 14:44:17 +01001658 assertIntEquals(UShr28And15(0xc1234567), 0xc);
1659 assertLongEquals(UShr60And15(0xc123456787654321L), 0xcL);
1660 assertIntEquals(UShr28And7(0xc1234567), 0x4);
1661 assertLongEquals(UShr60And7(0xc123456787654321L), 0x4L);
1662 assertIntEquals(Shr24And255(0xc1234567), 0xc1);
1663 assertLongEquals(Shr56And255(0xc123456787654321L), 0xc1L);
1664 assertIntEquals(Shr24And127(0xc1234567), 0x41);
1665 assertLongEquals(Shr56And127(0xc123456787654321L), 0x41L);
Alexandre Rames38db7852015-11-20 15:02:45 +00001666 assertIntEquals(0, mulPow2Plus1(0));
1667 assertIntEquals(9, mulPow2Plus1(1));
1668 assertIntEquals(18, mulPow2Plus1(2));
1669 assertIntEquals(900, mulPow2Plus1(100));
1670 assertIntEquals(111105, mulPow2Plus1(12345));
1671 assertLongEquals(0, mulPow2Minus1(0));
1672 assertLongEquals(31, mulPow2Minus1(1));
1673 assertLongEquals(62, mulPow2Minus1(2));
1674 assertLongEquals(3100, mulPow2Minus1(100));
1675 assertLongEquals(382695, mulPow2Minus1(12345));
Mark Mendellf6529172015-11-17 11:16:56 -05001676
1677 booleanField = false;
1678 assertIntEquals(booleanFieldNotEqualOne(), 54);
1679 assertIntEquals(booleanFieldEqualZero(), 54);
1680 booleanField = true;
1681 assertIntEquals(booleanFieldNotEqualOne(), 13);
1682 assertIntEquals(booleanFieldEqualZero(), 13);
1683 assertIntEquals(intConditionNotEqualOne(6), 54);
1684 assertIntEquals(intConditionNotEqualOne(43), 13);
1685 assertIntEquals(intConditionEqualZero(6), 54);
1686 assertIntEquals(intConditionEqualZero(43), 13);
1687 assertIntEquals(floatConditionNotEqualOne(6.0f), 54);
1688 assertIntEquals(floatConditionNotEqualOne(43.0f), 13);
1689 assertIntEquals(doubleConditionEqualZero(6.0), 54);
1690 assertIntEquals(doubleConditionEqualZero(43.0), 13);
Vladimir Markob52bbde2016-02-12 12:06:05 +00001691
1692 assertIntEquals(intToDoubleToInt(1234567), 1234567);
1693 assertIntEquals(intToDoubleToInt(Integer.MIN_VALUE), Integer.MIN_VALUE);
1694 assertIntEquals(intToDoubleToInt(Integer.MAX_VALUE), Integer.MAX_VALUE);
1695 assertStringEquals(intToDoubleToIntPrint(7654321), "d=7654321.0, i=7654321");
1696 assertIntEquals(byteToDoubleToInt((byte) 12), 12);
1697 assertIntEquals(byteToDoubleToInt(Byte.MIN_VALUE), Byte.MIN_VALUE);
1698 assertIntEquals(byteToDoubleToInt(Byte.MAX_VALUE), Byte.MAX_VALUE);
1699 assertIntEquals(floatToDoubleToInt(11.3f), 11);
1700 assertStringEquals(floatToDoubleToIntPrint(12.25f), "d=12.25, i=12");
1701 assertIntEquals(byteToDoubleToShort((byte) 123), 123);
1702 assertIntEquals(byteToDoubleToShort(Byte.MIN_VALUE), Byte.MIN_VALUE);
1703 assertIntEquals(byteToDoubleToShort(Byte.MAX_VALUE), Byte.MAX_VALUE);
1704 assertIntEquals(charToDoubleToShort((char) 1234), 1234);
1705 assertIntEquals(charToDoubleToShort(Character.MIN_VALUE), Character.MIN_VALUE);
1706 assertIntEquals(charToDoubleToShort(Character.MAX_VALUE), /* sign-extended */ -1);
1707 assertIntEquals(floatToIntToShort(12345.75f), 12345);
1708 assertIntEquals(floatToIntToShort((float)(Short.MIN_VALUE - 1)), Short.MAX_VALUE);
1709 assertIntEquals(floatToIntToShort((float)(Short.MAX_VALUE + 1)), Short.MIN_VALUE);
1710 assertIntEquals(intToFloatToInt(-54321), -54321);
1711 assertDoubleEquals(longToIntToDouble(0x1234567812345678L), (double) 0x12345678);
1712 assertDoubleEquals(longToIntToDouble(Long.MIN_VALUE), 0.0);
1713 assertDoubleEquals(longToIntToDouble(Long.MAX_VALUE), -1.0);
1714 assertLongEquals(longToIntToLong(0x1234567812345678L), 0x0000000012345678L);
1715 assertLongEquals(longToIntToLong(0x1234567887654321L), 0xffffffff87654321L);
1716 assertLongEquals(longToIntToLong(Long.MIN_VALUE), 0L);
1717 assertLongEquals(longToIntToLong(Long.MAX_VALUE), -1L);
1718 assertIntEquals(shortToCharToShort((short) -5678), (short) -5678);
1719 assertIntEquals(shortToCharToShort(Short.MIN_VALUE), Short.MIN_VALUE);
1720 assertIntEquals(shortToCharToShort(Short.MAX_VALUE), Short.MAX_VALUE);
1721 assertIntEquals(shortToLongToInt((short) 5678), 5678);
1722 assertIntEquals(shortToLongToInt(Short.MIN_VALUE), Short.MIN_VALUE);
1723 assertIntEquals(shortToLongToInt(Short.MAX_VALUE), Short.MAX_VALUE);
1724 assertIntEquals(shortToCharToByte((short) 0x1234), 0x34);
1725 assertIntEquals(shortToCharToByte((short) 0x12f0), -0x10);
1726 assertIntEquals(shortToCharToByte(Short.MIN_VALUE), 0);
1727 assertIntEquals(shortToCharToByte(Short.MAX_VALUE), -1);
1728 assertStringEquals(shortToCharToBytePrint((short) 1025), "c=1025, b=1");
1729 assertStringEquals(shortToCharToBytePrint((short) 1023), "c=1023, b=-1");
1730 assertStringEquals(shortToCharToBytePrint((short) -1), "c=65535, b=-1");
Vladimir Marko8428bd32016-02-12 16:53:57 +00001731
1732 assertIntEquals(longAnd0xffToByte(0x1234432112344321L), 0x21);
1733 assertIntEquals(longAnd0xffToByte(Long.MIN_VALUE), 0);
1734 assertIntEquals(longAnd0xffToByte(Long.MAX_VALUE), -1);
1735 assertIntEquals(intAnd0x1ffffToChar(0x43211234), 0x1234);
1736 assertIntEquals(intAnd0x1ffffToChar(Integer.MIN_VALUE), 0);
1737 assertIntEquals(intAnd0x1ffffToChar(Integer.MAX_VALUE), Character.MAX_VALUE);
1738 assertIntEquals(intAnd0x17fffToShort(0x87654321), 0x4321);
1739 assertIntEquals(intAnd0x17fffToShort(0x88888888), 0x0888);
1740 assertIntEquals(intAnd0x17fffToShort(Integer.MIN_VALUE), 0);
1741 assertIntEquals(intAnd0x17fffToShort(Integer.MAX_VALUE), Short.MAX_VALUE);
David Brazdilf02c3cf2016-02-29 09:14:51 +00001742
1743 for (String condition : new String[] { "Equal", "NotEqual" }) {
1744 for (String constant : new String[] { "True", "False" }) {
1745 for (String side : new String[] { "Rhs", "Lhs" }) {
1746 String name = condition + constant + side;
1747 assertIntEquals(runSmaliTest(name, true), 5);
1748 assertIntEquals(runSmaliTest(name, false), 3);
1749 }
1750 }
1751 }
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001752 }
Mark Mendellf6529172015-11-17 11:16:56 -05001753
David Brazdilf02c3cf2016-02-29 09:14:51 +00001754 private static boolean $inline$true() { return true; }
1755 private static boolean $inline$false() { return false; }
1756
Mark Mendellf6529172015-11-17 11:16:56 -05001757 public static boolean booleanField;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001758}