blob: 3c8abeb841a52604daa0db1fb0dce6f290e664d5 [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
17public class Main {
18
David Brazdil0d13fee2015-04-17 14:52:19 +010019 public static void assertBooleanEquals(boolean expected, boolean result) {
20 if (expected != result) {
21 throw new Error("Expected: " + expected + ", found: " + result);
22 }
23 }
24
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000025 public static void assertIntEquals(int expected, int result) {
26 if (expected != result) {
27 throw new Error("Expected: " + expected + ", found: " + result);
28 }
29 }
30
31 public static void assertLongEquals(long expected, long result) {
32 if (expected != result) {
33 throw new Error("Expected: " + expected + ", found: " + result);
34 }
35 }
36
Nicolas Geoffray0d221842015-04-27 08:53:46 +000037 public static void assertFloatEquals(float expected, float result) {
38 if (expected != result) {
39 throw new Error("Expected: " + expected + ", found: " + result);
40 }
41 }
42
43 public static void assertDoubleEquals(double expected, double result) {
44 if (expected != result) {
45 throw new Error("Expected: " + expected + ", found: " + result);
46 }
47 }
48
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000049 /**
50 * Tiny programs exercising optimizations of arithmetic identities.
51 */
52
David Brazdila06d66a2015-05-28 11:14:54 +010053 /// CHECK-START: long Main.Add0(long) instruction_simplifier (before)
54 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
55 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
56 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const0>>,<<Arg>>]
57 /// CHECK-DAG: Return [<<Add>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000058
David Brazdila06d66a2015-05-28 11:14:54 +010059 /// CHECK-START: long Main.Add0(long) instruction_simplifier (after)
60 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
61 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +010062
David Brazdila06d66a2015-05-28 11:14:54 +010063 /// CHECK-START: long Main.Add0(long) instruction_simplifier (after)
64 /// CHECK-NOT: Add
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000065
66 public static long Add0(long arg) {
67 return 0 + arg;
68 }
69
David Brazdila06d66a2015-05-28 11:14:54 +010070 /// CHECK-START: int Main.AndAllOnes(int) instruction_simplifier (before)
71 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
72 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
73 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<ConstF>>]
74 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000075
David Brazdila06d66a2015-05-28 11:14:54 +010076 /// CHECK-START: int Main.AndAllOnes(int) instruction_simplifier (after)
77 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
78 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000079
David Brazdila06d66a2015-05-28 11:14:54 +010080 /// CHECK-START: int Main.AndAllOnes(int) instruction_simplifier (after)
81 /// CHECK-NOT: And
Alexandre Rames74417692015-04-09 15:21:41 +010082
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000083 public static int AndAllOnes(int arg) {
84 return arg & -1;
85 }
86
Vladimir Marko452c1b62015-09-25 14:44:17 +010087 /// CHECK-START: int Main.UShr28And15(int) instruction_simplifier (before)
88 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
89 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
90 /// CHECK-DAG: <<Const15:i\d+>> IntConstant 15
91 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
92 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const15>>]
93 /// CHECK-DAG: Return [<<And>>]
94
95 /// CHECK-START: int Main.UShr28And15(int) instruction_simplifier (after)
96 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
97 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
98 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
99 /// CHECK-DAG: Return [<<UShr>>]
100
101 /// CHECK-START: int Main.UShr28And15(int) instruction_simplifier (after)
102 /// CHECK-NOT: And
103
104 public static int UShr28And15(int arg) {
105 return (arg >>> 28) & 15;
106 }
107
108 /// CHECK-START: long Main.UShr60And15(long) instruction_simplifier (before)
109 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
110 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
111 /// CHECK-DAG: <<Const15:j\d+>> LongConstant 15
112 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
113 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const15>>]
114 /// CHECK-DAG: Return [<<And>>]
115
116 /// CHECK-START: long Main.UShr60And15(long) instruction_simplifier (after)
117 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
118 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
119 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
120 /// CHECK-DAG: Return [<<UShr>>]
121
122 /// CHECK-START: long Main.UShr60And15(long) instruction_simplifier (after)
123 /// CHECK-NOT: And
124
125 public static long UShr60And15(long arg) {
126 return (arg >>> 60) & 15;
127 }
128
129 /// CHECK-START: int Main.UShr28And7(int) instruction_simplifier (before)
130 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
131 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
132 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
133 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
134 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
135 /// CHECK-DAG: Return [<<And>>]
136
137 /// CHECK-START: int Main.UShr28And7(int) instruction_simplifier (after)
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 public static int UShr28And7(int arg) {
146 return (arg >>> 28) & 7;
147 }
148
149 /// CHECK-START: long Main.UShr60And7(long) instruction_simplifier (before)
150 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
151 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
152 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
153 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
154 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
155 /// CHECK-DAG: Return [<<And>>]
156
157 /// CHECK-START: long Main.UShr60And7(long) instruction_simplifier (after)
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 public static long UShr60And7(long arg) {
166 return (arg >>> 60) & 7;
167 }
168
169 /// CHECK-START: int Main.Shr24And255(int) instruction_simplifier (before)
170 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
171 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
172 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
173 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
174 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const255>>]
175 /// CHECK-DAG: Return [<<And>>]
176
177 /// CHECK-START: int Main.Shr24And255(int) instruction_simplifier (after)
178 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
179 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
180 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const24>>]
181 /// CHECK-DAG: Return [<<UShr>>]
182
183 /// CHECK-START: int Main.Shr24And255(int) instruction_simplifier (after)
184 /// CHECK-NOT: Shr
185 /// CHECK-NOT: And
186
187 public static int Shr24And255(int arg) {
188 return (arg >> 24) & 255;
189 }
190
191 /// CHECK-START: long Main.Shr56And255(long) instruction_simplifier (before)
192 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
193 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
194 /// CHECK-DAG: <<Const255:j\d+>> LongConstant 255
195 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
196 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const255>>]
197 /// CHECK-DAG: Return [<<And>>]
198
199 /// CHECK-START: long Main.Shr56And255(long) instruction_simplifier (after)
200 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
201 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
202 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const56>>]
203 /// CHECK-DAG: Return [<<UShr>>]
204
205 /// CHECK-START: long Main.Shr56And255(long) instruction_simplifier (after)
206 /// CHECK-NOT: Shr
207 /// CHECK-NOT: And
208
209 public static long Shr56And255(long arg) {
210 return (arg >> 56) & 255;
211 }
212
213 /// CHECK-START: int Main.Shr24And127(int) instruction_simplifier (before)
214 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
215 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
216 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
217 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
218 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
219 /// CHECK-DAG: Return [<<And>>]
220
221 /// CHECK-START: int Main.Shr24And127(int) instruction_simplifier (after)
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 public static int Shr24And127(int arg) {
230 return (arg >> 24) & 127;
231 }
232
233 /// CHECK-START: long Main.Shr56And127(long) instruction_simplifier (before)
234 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
235 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
236 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
237 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
238 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
239 /// CHECK-DAG: Return [<<And>>]
240
241 /// CHECK-START: long Main.Shr56And127(long) instruction_simplifier (after)
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 public static long Shr56And127(long arg) {
250 return (arg >> 56) & 127;
251 }
252
David Brazdila06d66a2015-05-28 11:14:54 +0100253 /// CHECK-START: long Main.Div1(long) instruction_simplifier (before)
254 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
255 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
256 /// CHECK-DAG: <<Div:j\d+>> Div [<<Arg>>,<<Const1>>]
257 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000258
David Brazdila06d66a2015-05-28 11:14:54 +0100259 /// CHECK-START: long Main.Div1(long) instruction_simplifier (after)
260 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
261 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000262
David Brazdila06d66a2015-05-28 11:14:54 +0100263 /// CHECK-START: long Main.Div1(long) instruction_simplifier (after)
264 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100265
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000266 public static long Div1(long arg) {
267 return arg / 1;
268 }
269
David Brazdila06d66a2015-05-28 11:14:54 +0100270 /// CHECK-START: int Main.DivN1(int) instruction_simplifier (before)
271 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
272 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
273 /// CHECK-DAG: <<Div:i\d+>> Div [<<Arg>>,<<ConstN1>>]
274 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000275
David Brazdila06d66a2015-05-28 11:14:54 +0100276 /// CHECK-START: int Main.DivN1(int) instruction_simplifier (after)
277 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
278 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
279 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000280
David Brazdila06d66a2015-05-28 11:14:54 +0100281 /// CHECK-START: int Main.DivN1(int) instruction_simplifier (after)
282 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100283
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000284 public static int DivN1(int arg) {
285 return arg / -1;
286 }
287
David Brazdila06d66a2015-05-28 11:14:54 +0100288 /// CHECK-START: long Main.Mul1(long) instruction_simplifier (before)
289 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
290 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
David Brazdil57e863c2016-01-11 10:27:13 +0000291 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const1>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100292 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000293
David Brazdila06d66a2015-05-28 11:14:54 +0100294 /// CHECK-START: long Main.Mul1(long) instruction_simplifier (after)
295 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
296 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000297
David Brazdila06d66a2015-05-28 11:14:54 +0100298 /// CHECK-START: long Main.Mul1(long) instruction_simplifier (after)
299 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100300
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000301 public static long Mul1(long arg) {
302 return arg * 1;
303 }
304
David Brazdila06d66a2015-05-28 11:14:54 +0100305 /// CHECK-START: int Main.MulN1(int) instruction_simplifier (before)
306 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
307 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
308 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Arg>>,<<ConstN1>>]
309 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000310
David Brazdila06d66a2015-05-28 11:14:54 +0100311 /// CHECK-START: int Main.MulN1(int) instruction_simplifier (after)
312 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
313 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
314 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000315
David Brazdila06d66a2015-05-28 11:14:54 +0100316 /// CHECK-START: int Main.MulN1(int) instruction_simplifier (after)
317 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100318
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000319 public static int MulN1(int arg) {
320 return arg * -1;
321 }
322
David Brazdila06d66a2015-05-28 11:14:54 +0100323 /// CHECK-START: long Main.MulPowerOfTwo128(long) instruction_simplifier (before)
324 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
325 /// CHECK-DAG: <<Const128:j\d+>> LongConstant 128
David Brazdil57e863c2016-01-11 10:27:13 +0000326 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const128>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100327 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000328
David Brazdila06d66a2015-05-28 11:14:54 +0100329 /// CHECK-START: long Main.MulPowerOfTwo128(long) instruction_simplifier (after)
330 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
331 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
332 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Arg>>,<<Const7>>]
333 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000334
David Brazdila06d66a2015-05-28 11:14:54 +0100335 /// CHECK-START: long Main.MulPowerOfTwo128(long) instruction_simplifier (after)
336 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100337
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000338 public static long MulPowerOfTwo128(long arg) {
339 return arg * 128;
340 }
341
David Brazdila06d66a2015-05-28 11:14:54 +0100342 /// CHECK-START: int Main.Or0(int) instruction_simplifier (before)
343 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
344 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
345 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<Const0>>]
346 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000347
David Brazdila06d66a2015-05-28 11:14:54 +0100348 /// CHECK-START: int Main.Or0(int) instruction_simplifier (after)
349 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
350 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000351
David Brazdila06d66a2015-05-28 11:14:54 +0100352 /// CHECK-START: int Main.Or0(int) instruction_simplifier (after)
353 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100354
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000355 public static int Or0(int arg) {
356 return arg | 0;
357 }
358
David Brazdila06d66a2015-05-28 11:14:54 +0100359 /// CHECK-START: long Main.OrSame(long) instruction_simplifier (before)
360 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
361 /// CHECK-DAG: <<Or:j\d+>> Or [<<Arg>>,<<Arg>>]
362 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000363
David Brazdila06d66a2015-05-28 11:14:54 +0100364 /// CHECK-START: long Main.OrSame(long) instruction_simplifier (after)
365 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
366 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000367
David Brazdila06d66a2015-05-28 11:14:54 +0100368 /// CHECK-START: long Main.OrSame(long) instruction_simplifier (after)
369 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100370
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000371 public static long OrSame(long arg) {
372 return arg | arg;
373 }
374
David Brazdila06d66a2015-05-28 11:14:54 +0100375 /// CHECK-START: int Main.Shl0(int) instruction_simplifier (before)
376 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
377 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
378 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Arg>>,<<Const0>>]
379 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000380
David Brazdila06d66a2015-05-28 11:14:54 +0100381 /// CHECK-START: int Main.Shl0(int) instruction_simplifier (after)
382 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
383 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000384
David Brazdila06d66a2015-05-28 11:14:54 +0100385 /// CHECK-START: int Main.Shl0(int) instruction_simplifier (after)
386 /// CHECK-NOT: Shl
Alexandre Rames74417692015-04-09 15:21:41 +0100387
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000388 public static int Shl0(int arg) {
389 return arg << 0;
390 }
391
David Brazdila06d66a2015-05-28 11:14:54 +0100392 /// CHECK-START: long Main.Shr0(long) instruction_simplifier (before)
393 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
394 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
395 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const0>>]
396 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000397
David Brazdila06d66a2015-05-28 11:14:54 +0100398 /// CHECK-START: long Main.Shr0(long) instruction_simplifier (after)
399 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
400 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000401
David Brazdila06d66a2015-05-28 11:14:54 +0100402 /// CHECK-START: long Main.Shr0(long) instruction_simplifier (after)
403 /// CHECK-NOT: Shr
Alexandre Rames74417692015-04-09 15:21:41 +0100404
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000405 public static long Shr0(long arg) {
406 return arg >> 0;
407 }
408
David Brazdila06d66a2015-05-28 11:14:54 +0100409 /// CHECK-START: long Main.Sub0(long) instruction_simplifier (before)
410 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
411 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
412 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Const0>>]
413 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000414
David Brazdila06d66a2015-05-28 11:14:54 +0100415 /// CHECK-START: long Main.Sub0(long) instruction_simplifier (after)
416 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
417 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000418
David Brazdila06d66a2015-05-28 11:14:54 +0100419 /// CHECK-START: long Main.Sub0(long) instruction_simplifier (after)
420 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100421
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000422 public static long Sub0(long arg) {
423 return arg - 0;
424 }
425
David Brazdila06d66a2015-05-28 11:14:54 +0100426 /// CHECK-START: int Main.SubAliasNeg(int) instruction_simplifier (before)
427 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
428 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
429 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const0>>,<<Arg>>]
430 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000431
David Brazdila06d66a2015-05-28 11:14:54 +0100432 /// CHECK-START: int Main.SubAliasNeg(int) instruction_simplifier (after)
433 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
434 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
435 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000436
David Brazdila06d66a2015-05-28 11:14:54 +0100437 /// CHECK-START: int Main.SubAliasNeg(int) instruction_simplifier (after)
438 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100439
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000440 public static int SubAliasNeg(int arg) {
441 return 0 - arg;
442 }
443
David Brazdila06d66a2015-05-28 11:14:54 +0100444 /// CHECK-START: long Main.UShr0(long) instruction_simplifier (before)
445 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
446 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
447 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const0>>]
448 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000449
David Brazdila06d66a2015-05-28 11:14:54 +0100450 /// CHECK-START: long Main.UShr0(long) instruction_simplifier (after)
451 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
452 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000453
David Brazdila06d66a2015-05-28 11:14:54 +0100454 /// CHECK-START: long Main.UShr0(long) instruction_simplifier (after)
455 /// CHECK-NOT: UShr
Alexandre Rames74417692015-04-09 15:21:41 +0100456
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000457 public static long UShr0(long arg) {
458 return arg >>> 0;
459 }
460
David Brazdila06d66a2015-05-28 11:14:54 +0100461 /// CHECK-START: int Main.Xor0(int) instruction_simplifier (before)
462 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
463 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
464 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Const0>>]
465 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000466
David Brazdila06d66a2015-05-28 11:14:54 +0100467 /// CHECK-START: int Main.Xor0(int) instruction_simplifier (after)
468 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
469 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000470
David Brazdila06d66a2015-05-28 11:14:54 +0100471 /// CHECK-START: int Main.Xor0(int) instruction_simplifier (after)
472 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100473
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000474 public static int Xor0(int arg) {
475 return arg ^ 0;
476 }
477
David Brazdila06d66a2015-05-28 11:14:54 +0100478 /// CHECK-START: int Main.XorAllOnes(int) instruction_simplifier (before)
479 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
480 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
481 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<ConstF>>]
482 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000483
David Brazdila06d66a2015-05-28 11:14:54 +0100484 /// CHECK-START: int Main.XorAllOnes(int) instruction_simplifier (after)
485 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
486 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
487 /// CHECK-DAG: Return [<<Not>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000488
David Brazdila06d66a2015-05-28 11:14:54 +0100489 /// CHECK-START: int Main.XorAllOnes(int) instruction_simplifier (after)
490 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100491
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000492 public static int XorAllOnes(int arg) {
493 return arg ^ -1;
494 }
495
Alexandre Rames188d4312015-04-09 18:30:21 +0100496 /**
497 * Test that addition or subtraction operation with both inputs negated are
498 * optimized to use a single negation after the operation.
499 * The transformation tested is implemented in
500 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
501 */
502
David Brazdila06d66a2015-05-28 11:14:54 +0100503 /// CHECK-START: int Main.AddNegs1(int, int) instruction_simplifier (before)
504 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
505 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
506 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
507 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
508 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
509 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100510
David Brazdila06d66a2015-05-28 11:14:54 +0100511 /// CHECK-START: int Main.AddNegs1(int, int) instruction_simplifier (after)
512 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
513 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
514 /// CHECK-NOT: Neg
515 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
516 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
517 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100518
519 public static int AddNegs1(int arg1, int arg2) {
520 return -arg1 + -arg2;
521 }
522
523 /**
524 * This is similar to the test-case AddNegs1, but the negations have
525 * multiple uses.
526 * The transformation tested is implemented in
527 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
528 * The current code won't perform the previous optimization. The
529 * transformations do not look at other uses of their inputs. As they don't
530 * know what will happen with other uses, they do not take the risk of
531 * increasing the register pressure by creating or extending live ranges.
532 */
533
David Brazdila06d66a2015-05-28 11:14:54 +0100534 /// CHECK-START: int Main.AddNegs2(int, int) instruction_simplifier (before)
535 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
536 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
537 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
538 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
539 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
540 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
541 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
542 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100543
David Brazdila06d66a2015-05-28 11:14:54 +0100544 /// CHECK-START: int Main.AddNegs2(int, int) instruction_simplifier (after)
545 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
546 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
547 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
548 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
549 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
550 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
551 /// CHECK-NOT: Neg
552 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
553 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100554
David Brazdila06d66a2015-05-28 11:14:54 +0100555 /// CHECK-START: int Main.AddNegs2(int, int) GVN (after)
556 /// 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: <<Or:i\d+>> Or [<<Add>>,<<Add>>]
562 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100563
Alexandre Rames188d4312015-04-09 18:30:21 +0100564 public static int AddNegs2(int arg1, int arg2) {
565 int temp1 = -arg1;
566 int temp2 = -arg2;
567 return (temp1 + temp2) | (temp1 + temp2);
568 }
569
570 /**
571 * This follows test-cases AddNegs1 and AddNegs2.
572 * The transformation tested is implemented in
573 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
574 * The optimization should not happen if it moves an additional instruction in
575 * the loop.
576 */
577
David Brazdila06d66a2015-05-28 11:14:54 +0100578 /// CHECK-START: long Main.AddNegs3(long, long) instruction_simplifier (before)
579 // -------------- Arguments and initial negation operations.
580 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
581 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
582 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
583 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
584 /// CHECK: Goto
585 // -------------- Loop
586 /// CHECK: SuspendCheck
587 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
588 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100589
David Brazdila06d66a2015-05-28 11:14:54 +0100590 /// CHECK-START: long Main.AddNegs3(long, long) instruction_simplifier (after)
591 // -------------- Arguments and initial negation operations.
592 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
593 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
594 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
595 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
596 /// CHECK: Goto
597 // -------------- Loop
598 /// CHECK: SuspendCheck
599 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
600 /// CHECK-NOT: Neg
601 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100602
603 public static long AddNegs3(long arg1, long arg2) {
604 long res = 0;
605 long n_arg1 = -arg1;
606 long n_arg2 = -arg2;
607 for (long i = 0; i < 1; i++) {
608 res += n_arg1 + n_arg2 + i;
609 }
610 return res;
611 }
612
613 /**
614 * Test the simplification of an addition with a negated argument into a
615 * subtraction.
616 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
617 */
618
David Brazdila06d66a2015-05-28 11:14:54 +0100619 /// CHECK-START: long Main.AddNeg1(long, long) instruction_simplifier (before)
620 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
621 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
622 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
623 /// CHECK-DAG: <<Add:j\d+>> Add [<<Neg>>,<<Arg2>>]
624 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100625
David Brazdila06d66a2015-05-28 11:14:54 +0100626 /// CHECK-START: long Main.AddNeg1(long, long) instruction_simplifier (after)
627 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
628 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
629 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg2>>,<<Arg1>>]
630 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100631
David Brazdila06d66a2015-05-28 11:14:54 +0100632 /// CHECK-START: long Main.AddNeg1(long, long) instruction_simplifier (after)
633 /// CHECK-NOT: Neg
634 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100635
636 public static long AddNeg1(long arg1, long arg2) {
637 return -arg1 + arg2;
638 }
639
640 /**
641 * This is similar to the test-case AddNeg1, but the negation has two uses.
642 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
643 * The current code won't perform the previous optimization. The
644 * transformations do not look at other uses of their inputs. As they don't
645 * know what will happen with other uses, they do not take the risk of
646 * increasing the register pressure by creating or extending live ranges.
647 */
648
David Brazdila06d66a2015-05-28 11:14:54 +0100649 /// CHECK-START: long Main.AddNeg2(long, long) instruction_simplifier (before)
650 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
651 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
652 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
653 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
654 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
655 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
656 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100657
David Brazdila06d66a2015-05-28 11:14:54 +0100658 /// CHECK-START: long Main.AddNeg2(long, long) instruction_simplifier (after)
659 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
660 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
661 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
662 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
663 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
664 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
665 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100666
David Brazdila06d66a2015-05-28 11:14:54 +0100667 /// CHECK-START: long Main.AddNeg2(long, long) instruction_simplifier (after)
668 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100669
670 public static long AddNeg2(long arg1, long arg2) {
671 long temp = -arg2;
672 return (arg1 + temp) | (arg1 + temp);
673 }
674
675 /**
676 * Test simplification of the `-(-var)` pattern.
677 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
678 */
679
David Brazdila06d66a2015-05-28 11:14:54 +0100680 /// CHECK-START: long Main.NegNeg1(long) instruction_simplifier (before)
681 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
682 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg>>]
683 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Neg1>>]
684 /// CHECK-DAG: Return [<<Neg2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100685
David Brazdila06d66a2015-05-28 11:14:54 +0100686 /// CHECK-START: long Main.NegNeg1(long) instruction_simplifier (after)
687 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
688 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100689
David Brazdila06d66a2015-05-28 11:14:54 +0100690 /// CHECK-START: long Main.NegNeg1(long) instruction_simplifier (after)
691 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100692
693 public static long NegNeg1(long arg) {
694 return -(-arg);
695 }
696
697 /**
698 * Test 'multi-step' simplification, where a first transformation yields a
699 * new simplification possibility for the current instruction.
700 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
701 * and in `InstructionSimplifierVisitor::VisitAdd`.
702 */
703
David Brazdila06d66a2015-05-28 11:14:54 +0100704 /// CHECK-START: int Main.NegNeg2(int) instruction_simplifier (before)
705 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
706 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg>>]
707 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Neg1>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000708 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg2>>,<<Neg1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100709 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100710
David Brazdila06d66a2015-05-28 11:14:54 +0100711 /// CHECK-START: int Main.NegNeg2(int) instruction_simplifier (after)
712 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
713 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg>>,<<Arg>>]
714 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100715
David Brazdila06d66a2015-05-28 11:14:54 +0100716 /// CHECK-START: int Main.NegNeg2(int) instruction_simplifier (after)
717 /// CHECK-NOT: Neg
718 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100719
David Brazdila06d66a2015-05-28 11:14:54 +0100720 /// CHECK-START: int Main.NegNeg2(int) constant_folding_after_inlining (after)
721 /// CHECK: <<Const0:i\d+>> IntConstant 0
722 /// CHECK-NOT: Neg
723 /// CHECK-NOT: Add
724 /// CHECK: Return [<<Const0>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100725
Alexandre Rames188d4312015-04-09 18:30:21 +0100726 public static int NegNeg2(int arg) {
727 int temp = -arg;
728 return temp + -temp;
729 }
730
731 /**
732 * Test another 'multi-step' simplification, where a first transformation
733 * yields a new simplification possibility for the current instruction.
734 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
735 * and in `InstructionSimplifierVisitor::VisitSub`.
736 */
737
David Brazdila06d66a2015-05-28 11:14:54 +0100738 /// CHECK-START: long Main.NegNeg3(long) instruction_simplifier (before)
739 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
740 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
741 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg>>]
742 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const0>>,<<Neg>>]
743 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100744
David Brazdila06d66a2015-05-28 11:14:54 +0100745 /// CHECK-START: long Main.NegNeg3(long) instruction_simplifier (after)
746 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
747 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100748
David Brazdila06d66a2015-05-28 11:14:54 +0100749 /// CHECK-START: long Main.NegNeg3(long) instruction_simplifier (after)
750 /// CHECK-NOT: Neg
751 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100752
753 public static long NegNeg3(long arg) {
754 return 0 - -arg;
755 }
756
757 /**
758 * Test that a negated subtraction is simplified to a subtraction with its
759 * arguments reversed.
760 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
761 */
762
David Brazdila06d66a2015-05-28 11:14:54 +0100763 /// CHECK-START: int Main.NegSub1(int, int) instruction_simplifier (before)
764 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
765 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
766 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
767 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Sub>>]
768 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100769
David Brazdila06d66a2015-05-28 11:14:54 +0100770 /// CHECK-START: int Main.NegSub1(int, int) instruction_simplifier (after)
771 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
772 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
773 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg2>>,<<Arg1>>]
774 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100775
David Brazdila06d66a2015-05-28 11:14:54 +0100776 /// CHECK-START: int Main.NegSub1(int, int) instruction_simplifier (after)
777 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100778
779 public static int NegSub1(int arg1, int arg2) {
780 return -(arg1 - arg2);
781 }
782
783 /**
784 * This is similar to the test-case NegSub1, but the subtraction has
785 * multiple uses.
786 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
787 * The current code won't perform the previous optimization. The
788 * transformations do not look at other uses of their inputs. As they don't
789 * know what will happen with other uses, they do not take the risk of
790 * increasing the register pressure by creating or extending live ranges.
791 */
792
David Brazdila06d66a2015-05-28 11:14:54 +0100793 /// CHECK-START: int Main.NegSub2(int, int) instruction_simplifier (before)
794 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
795 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
796 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
797 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
798 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
799 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
800 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100801
David Brazdila06d66a2015-05-28 11:14:54 +0100802 /// CHECK-START: int Main.NegSub2(int, int) instruction_simplifier (after)
803 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
804 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
805 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
806 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
807 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
808 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
809 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100810
811 public static int NegSub2(int arg1, int arg2) {
812 int temp = arg1 - arg2;
813 return -temp | -temp;
814 }
815
816 /**
817 * Test simplification of the `~~var` pattern.
818 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`.
819 */
820
David Brazdila06d66a2015-05-28 11:14:54 +0100821 /// CHECK-START: long Main.NotNot1(long) instruction_simplifier (before)
822 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
823 /// CHECK-DAG: <<ConstF1:j\d+>> LongConstant -1
824 /// CHECK-DAG: <<Xor1:j\d+>> Xor [<<Arg>>,<<ConstF1>>]
825 /// CHECK-DAG: <<Xor2:j\d+>> Xor [<<Xor1>>,<<ConstF1>>]
826 /// CHECK-DAG: Return [<<Xor2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100827
David Brazdila06d66a2015-05-28 11:14:54 +0100828 /// CHECK-START: long Main.NotNot1(long) instruction_simplifier (after)
829 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
830 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100831
David Brazdila06d66a2015-05-28 11:14:54 +0100832 /// CHECK-START: long Main.NotNot1(long) instruction_simplifier (after)
833 /// CHECK-NOT: Xor
Alexandre Rames188d4312015-04-09 18:30:21 +0100834
835 public static long NotNot1(long arg) {
836 return ~~arg;
837 }
838
David Brazdila06d66a2015-05-28 11:14:54 +0100839 /// CHECK-START: int Main.NotNot2(int) instruction_simplifier (before)
840 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
841 /// CHECK-DAG: <<ConstF1:i\d+>> IntConstant -1
842 /// CHECK-DAG: <<Xor1:i\d+>> Xor [<<Arg>>,<<ConstF1>>]
843 /// CHECK-DAG: <<Xor2:i\d+>> Xor [<<Xor1>>,<<ConstF1>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000844 /// CHECK-DAG: <<Add:i\d+>> Add [<<Xor2>>,<<Xor1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100845 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100846
David Brazdila06d66a2015-05-28 11:14:54 +0100847 /// CHECK-START: int Main.NotNot2(int) instruction_simplifier (after)
848 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
849 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000850 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg>>,<<Not>>]
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-NOT: Xor
Alexandre Rames188d4312015-04-09 18:30:21 +0100855
856 public static int NotNot2(int arg) {
857 int temp = ~arg;
858 return temp + ~temp;
859 }
860
861 /**
862 * Test the simplification of a subtraction with a negated argument.
863 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
864 */
865
David Brazdila06d66a2015-05-28 11:14:54 +0100866 /// CHECK-START: int Main.SubNeg1(int, int) instruction_simplifier (before)
867 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
868 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
869 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
870 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Neg>>,<<Arg2>>]
871 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100872
David Brazdila06d66a2015-05-28 11:14:54 +0100873 /// CHECK-START: int Main.SubNeg1(int, int) instruction_simplifier (after)
874 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
875 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
876 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
877 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
878 /// CHECK-DAG: Return [<<Neg>>]
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-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100882
883 public static int SubNeg1(int arg1, int arg2) {
884 return -arg1 - arg2;
885 }
886
887 /**
888 * This is similar to the test-case SubNeg1, but the negation has
889 * multiple uses.
890 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
891 * The current code won't perform the previous optimization. The
892 * transformations do not look at other uses of their inputs. As they don't
893 * know what will happen with other uses, they do not take the risk of
894 * increasing the register pressure by creating or extending live ranges.
895 */
896
David Brazdila06d66a2015-05-28 11:14:54 +0100897 /// CHECK-START: int Main.SubNeg2(int, int) instruction_simplifier (before)
898 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
899 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
900 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
901 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
902 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
903 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
904 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100905
David Brazdila06d66a2015-05-28 11:14:54 +0100906 /// CHECK-START: int Main.SubNeg2(int, int) instruction_simplifier (after)
907 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
908 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
909 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
910 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
911 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
912 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
913 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100914
David Brazdila06d66a2015-05-28 11:14:54 +0100915 /// CHECK-START: int Main.SubNeg2(int, int) instruction_simplifier (after)
916 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100917
918 public static int SubNeg2(int arg1, int arg2) {
919 int temp = -arg1;
920 return (temp - arg2) | (temp - arg2);
921 }
922
923 /**
924 * This follows test-cases SubNeg1 and SubNeg2.
925 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
926 * The optimization should not happen if it moves an additional instruction in
927 * the loop.
928 */
929
David Brazdila06d66a2015-05-28 11:14:54 +0100930 /// CHECK-START: long Main.SubNeg3(long, long) instruction_simplifier (before)
931 // -------------- Arguments and initial negation operation.
932 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
933 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
934 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
935 /// CHECK: Goto
936 // -------------- Loop
937 /// CHECK: SuspendCheck
938 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
939 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100940
David Brazdila06d66a2015-05-28 11:14:54 +0100941 /// CHECK-START: long Main.SubNeg3(long, long) instruction_simplifier (after)
942 // -------------- Arguments and initial negation operation.
943 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
944 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
945 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
946 /// CHECK-DAG: Goto
947 // -------------- Loop
948 /// CHECK: SuspendCheck
949 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
950 /// CHECK-NOT: Neg
951 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100952
953 public static long SubNeg3(long arg1, long arg2) {
954 long res = 0;
955 long temp = -arg1;
956 for (long i = 0; i < 1; i++) {
957 res += temp - arg2 - i;
958 }
959 return res;
960 }
961
David Brazdila06d66a2015-05-28 11:14:54 +0100962 /// CHECK-START: int Main.EqualTrueRhs(boolean) instruction_simplifier (before)
963 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
964 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
965 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Const1>>]
966 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +0100967
David Brazdila06d66a2015-05-28 11:14:54 +0100968 /// CHECK-START: int Main.EqualTrueRhs(boolean) instruction_simplifier (after)
969 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
970 /// CHECK-DAG: If [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +0100971
David Brazdil74eb1b22015-12-14 11:44:01 +0000972 /// CHECK-START: int Main.EqualTrueRhs(boolean) instruction_simplifier_before_codegen (after)
973 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
974 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
975 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
976 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const3>>,<<Const5>>,<<Arg>>]
977 /// CHECK-DAG: Return [<<Select>>]
978
David Brazdil0d13fee2015-04-17 14:52:19 +0100979 public static int EqualTrueRhs(boolean arg) {
980 return (arg != true) ? 3 : 5;
981 }
982
David Brazdila06d66a2015-05-28 11:14:54 +0100983 /// CHECK-START: int Main.EqualTrueLhs(boolean) instruction_simplifier (before)
984 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
985 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
986 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Const1>>,<<Arg>>]
987 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +0100988
David Brazdila06d66a2015-05-28 11:14:54 +0100989 /// CHECK-START: int Main.EqualTrueLhs(boolean) instruction_simplifier (after)
990 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
991 /// CHECK-DAG: If [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +0100992
David Brazdil74eb1b22015-12-14 11:44:01 +0000993 /// CHECK-START: int Main.EqualTrueLhs(boolean) instruction_simplifier_before_codegen (after)
994 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
995 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
996 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
997 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const3>>,<<Const5>>,<<Arg>>]
998 /// CHECK-DAG: Return [<<Select>>]
999
David Brazdil0d13fee2015-04-17 14:52:19 +01001000 public static int EqualTrueLhs(boolean arg) {
1001 return (true != arg) ? 3 : 5;
1002 }
1003
David Brazdila06d66a2015-05-28 11:14:54 +01001004 /// CHECK-START: int Main.EqualFalseRhs(boolean) instruction_simplifier (before)
1005 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1006 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1007 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Const0>>]
1008 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001009
David Brazdila06d66a2015-05-28 11:14:54 +01001010 /// CHECK-START: int Main.EqualFalseRhs(boolean) instruction_simplifier (after)
1011 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001012 /// CHECK-DAG: If [<<Arg>>]
1013
1014 /// CHECK-START: int Main.EqualFalseRhs(boolean) instruction_simplifier_before_codegen (after)
1015 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1016 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1017 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1018 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const5>>,<<Const3>>,<<Arg>>]
1019 /// CHECK-DAG: Return [<<Select>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001020
1021 public static int EqualFalseRhs(boolean arg) {
1022 return (arg != false) ? 3 : 5;
1023 }
1024
David Brazdila06d66a2015-05-28 11:14:54 +01001025 /// CHECK-START: int Main.EqualFalseLhs(boolean) instruction_simplifier (before)
1026 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1027 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil57e863c2016-01-11 10:27:13 +00001028 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Const0>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001029 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001030
David Brazdila06d66a2015-05-28 11:14:54 +01001031 /// CHECK-START: int Main.EqualFalseLhs(boolean) instruction_simplifier (after)
1032 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001033 /// CHECK-DAG: If [<<Arg>>]
1034
1035 /// CHECK-START: int Main.EqualFalseLhs(boolean) instruction_simplifier_before_codegen (after)
1036 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1037 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1038 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1039 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const5>>,<<Const3>>,<<Arg>>]
1040 /// CHECK-DAG: Return [<<Select>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001041
1042 public static int EqualFalseLhs(boolean arg) {
1043 return (false != arg) ? 3 : 5;
1044 }
1045
David Brazdila06d66a2015-05-28 11:14:54 +01001046 /// CHECK-START: int Main.NotEqualTrueRhs(boolean) instruction_simplifier (before)
1047 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1048 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1049 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Arg>>,<<Const1>>]
1050 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001051
David Brazdila06d66a2015-05-28 11:14:54 +01001052 /// CHECK-START: int Main.NotEqualTrueRhs(boolean) instruction_simplifier (after)
1053 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001054 /// CHECK-DAG: If [<<Arg>>]
1055
1056 /// CHECK-START: int Main.NotEqualTrueRhs(boolean) instruction_simplifier_before_codegen (after)
1057 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1058 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1059 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1060 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const5>>,<<Const3>>,<<Arg>>]
1061 /// CHECK-DAG: Return [<<Select>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001062
1063 public static int NotEqualTrueRhs(boolean arg) {
1064 return (arg == true) ? 3 : 5;
1065 }
1066
David Brazdila06d66a2015-05-28 11:14:54 +01001067 /// CHECK-START: int Main.NotEqualTrueLhs(boolean) instruction_simplifier (before)
1068 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1069 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1070 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Const1>>,<<Arg>>]
1071 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001072
David Brazdila06d66a2015-05-28 11:14:54 +01001073 /// CHECK-START: int Main.NotEqualTrueLhs(boolean) instruction_simplifier (after)
1074 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001075 /// CHECK-DAG: If [<<Arg>>]
1076
1077 /// CHECK-START: int Main.NotEqualTrueLhs(boolean) instruction_simplifier_before_codegen (after)
1078 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1079 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1080 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1081 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const5>>,<<Const3>>,<<Arg>>]
1082 /// CHECK-DAG: Return [<<Select>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001083
1084 public static int NotEqualTrueLhs(boolean arg) {
1085 return (true == arg) ? 3 : 5;
1086 }
1087
David Brazdila06d66a2015-05-28 11:14:54 +01001088 /// CHECK-START: int Main.NotEqualFalseRhs(boolean) instruction_simplifier (before)
1089 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1090 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1091 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Arg>>,<<Const0>>]
1092 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001093
David Brazdila06d66a2015-05-28 11:14:54 +01001094 /// CHECK-START: int Main.NotEqualFalseRhs(boolean) instruction_simplifier (after)
1095 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1096 /// CHECK-DAG: If [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001097
David Brazdil74eb1b22015-12-14 11:44:01 +00001098 /// CHECK-START: int Main.NotEqualFalseRhs(boolean) instruction_simplifier_before_codegen (after)
1099 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1100 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1101 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1102 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const3>>,<<Const5>>,<<Arg>>]
1103 /// CHECK-DAG: Return [<<Select>>]
1104
David Brazdil0d13fee2015-04-17 14:52:19 +01001105 public static int NotEqualFalseRhs(boolean arg) {
1106 return (arg == false) ? 3 : 5;
1107 }
1108
David Brazdila06d66a2015-05-28 11:14:54 +01001109 /// CHECK-START: int Main.NotEqualFalseLhs(boolean) instruction_simplifier (before)
1110 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1111 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil57e863c2016-01-11 10:27:13 +00001112 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Arg>>,<<Const0>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001113 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001114
David Brazdila06d66a2015-05-28 11:14:54 +01001115 /// CHECK-START: int Main.NotEqualFalseLhs(boolean) instruction_simplifier (after)
1116 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1117 /// CHECK-DAG: If [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001118
David Brazdil74eb1b22015-12-14 11:44:01 +00001119 /// CHECK-START: int Main.NotEqualFalseLhs(boolean) instruction_simplifier_before_codegen (after)
1120 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1121 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1122 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1123 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const3>>,<<Const5>>,<<Arg>>]
1124 /// CHECK-DAG: Return [<<Select>>]
1125
David Brazdil0d13fee2015-04-17 14:52:19 +01001126 public static int NotEqualFalseLhs(boolean arg) {
1127 return (false == arg) ? 3 : 5;
1128 }
1129
David Brazdil1e9ec052015-06-22 10:26:45 +01001130 /// CHECK-START: boolean Main.EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
1131 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001132 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1133 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001134 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001135 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1136 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<NotArg>>,<<Const2>>]
1137 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1138 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001139
1140 /// CHECK-START: boolean Main.EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001141 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
1142 /// CHECK-DAG: Return [<<True>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001143
1144 public static boolean EqualBoolVsIntConst(boolean arg) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001145 return (arg ? 0 : 1) != 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001146 }
1147
1148 /// CHECK-START: boolean Main.NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
1149 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001150 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1151 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001152 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001153 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1154 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<NotArg>>,<<Const2>>]
1155 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1156 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001157
1158 /// CHECK-START: boolean Main.NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001159 /// CHECK-DAG: <<False:i\d+>> IntConstant 0
1160 /// CHECK-DAG: Return [<<False>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001161
1162 public static boolean NotEqualBoolVsIntConst(boolean arg) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001163 return (arg ? 0 : 1) == 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001164 }
1165
David Brazdil0d13fee2015-04-17 14:52:19 +01001166 /*
1167 * Test simplification of double Boolean negation. Note that sometimes
1168 * both negations can be removed but we only expect the simplifier to
1169 * remove the second.
1170 */
1171
Nicolas Geoffrayb2bdfce2015-06-18 15:46:47 +01001172 /// CHECK-START: boolean Main.NotNotBool(boolean) instruction_simplifier_after_bce (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001173 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001174 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1175 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1176 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1177 /// CHECK-DAG: <<NotNotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<NotArg>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001178 /// CHECK-DAG: Return [<<NotNotArg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001179
Nicolas Geoffrayb2bdfce2015-06-18 15:46:47 +01001180 /// CHECK-START: boolean Main.NotNotBool(boolean) instruction_simplifier_after_bce (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001181 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdila06d66a2015-05-28 11:14:54 +01001182 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001183
David Brazdil769c9e52015-04-27 13:54:09 +01001184 public static boolean NegateValue(boolean arg) {
1185 return !arg;
1186 }
1187
David Brazdil0d13fee2015-04-17 14:52:19 +01001188 public static boolean NotNotBool(boolean arg) {
David Brazdil769c9e52015-04-27 13:54:09 +01001189 return !(NegateValue(arg));
David Brazdil0d13fee2015-04-17 14:52:19 +01001190 }
1191
David Brazdila06d66a2015-05-28 11:14:54 +01001192 /// CHECK-START: float Main.Div2(float) instruction_simplifier (before)
1193 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1194 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
1195 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>]
1196 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001197
David Brazdila06d66a2015-05-28 11:14:54 +01001198 /// CHECK-START: float Main.Div2(float) instruction_simplifier (after)
1199 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1200 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5
1201 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>]
1202 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001203
David Brazdila06d66a2015-05-28 11:14:54 +01001204 /// CHECK-START: float Main.Div2(float) instruction_simplifier (after)
1205 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001206
1207 public static float Div2(float arg) {
1208 return arg / 2.0f;
1209 }
1210
David Brazdila06d66a2015-05-28 11:14:54 +01001211 /// CHECK-START: double Main.Div2(double) instruction_simplifier (before)
1212 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1213 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
1214 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>]
1215 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001216
David Brazdila06d66a2015-05-28 11:14:54 +01001217 /// CHECK-START: double Main.Div2(double) instruction_simplifier (after)
1218 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1219 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5
1220 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>]
1221 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001222
David Brazdila06d66a2015-05-28 11:14:54 +01001223 /// CHECK-START: double Main.Div2(double) instruction_simplifier (after)
1224 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001225 public static double Div2(double arg) {
1226 return arg / 2.0;
1227 }
1228
David Brazdila06d66a2015-05-28 11:14:54 +01001229 /// CHECK-START: float Main.DivMP25(float) instruction_simplifier (before)
1230 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1231 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25
1232 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>]
1233 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001234
David Brazdila06d66a2015-05-28 11:14:54 +01001235 /// CHECK-START: float Main.DivMP25(float) instruction_simplifier (after)
1236 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1237 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4
1238 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>]
1239 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001240
David Brazdila06d66a2015-05-28 11:14:54 +01001241 /// CHECK-START: float Main.DivMP25(float) instruction_simplifier (after)
1242 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001243
1244 public static float DivMP25(float arg) {
1245 return arg / -0.25f;
1246 }
1247
David Brazdila06d66a2015-05-28 11:14:54 +01001248 /// CHECK-START: double Main.DivMP25(double) instruction_simplifier (before)
1249 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1250 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25
1251 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>]
1252 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001253
David Brazdila06d66a2015-05-28 11:14:54 +01001254 /// CHECK-START: double Main.DivMP25(double) instruction_simplifier (after)
1255 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1256 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4
1257 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>]
1258 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001259
David Brazdila06d66a2015-05-28 11:14:54 +01001260 /// CHECK-START: double Main.DivMP25(double) instruction_simplifier (after)
1261 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001262 public static double DivMP25(double arg) {
1263 return arg / -0.25f;
1264 }
1265
Alexandre Rames38db7852015-11-20 15:02:45 +00001266 /**
1267 * Test strength reduction of factors of the form (2^n + 1).
1268 */
1269
1270 /// CHECK-START: int Main.mulPow2Plus1(int) instruction_simplifier (before)
1271 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1272 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
1273 /// CHECK: Mul [<<Arg>>,<<Const9>>]
1274
1275 /// CHECK-START: int Main.mulPow2Plus1(int) instruction_simplifier (after)
1276 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1277 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1278 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>]
1279 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>]
1280
1281 public static int mulPow2Plus1(int arg) {
1282 return arg * 9;
1283 }
1284
Alexandre Rames38db7852015-11-20 15:02:45 +00001285 /**
1286 * Test strength reduction of factors of the form (2^n - 1).
1287 */
1288
1289 /// CHECK-START: long Main.mulPow2Minus1(long) instruction_simplifier (before)
1290 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1291 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31
David Brazdil57e863c2016-01-11 10:27:13 +00001292 /// CHECK: Mul [<<Const31>>,<<Arg>>]
Alexandre Rames38db7852015-11-20 15:02:45 +00001293
1294 /// CHECK-START: long Main.mulPow2Minus1(long) instruction_simplifier (after)
1295 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1296 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1297 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>]
1298 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>]
1299
1300 public static long mulPow2Minus1(long arg) {
1301 return arg * 31;
1302 }
1303
Mark Mendellf6529172015-11-17 11:16:56 -05001304 /// CHECK-START: int Main.booleanFieldNotEqualOne() instruction_simplifier (before)
1305 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1306 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1307 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>]
1308 /// CHECK-DAG: If [<<NE>>]
1309
1310 /// CHECK-START: int Main.booleanFieldNotEqualOne() instruction_simplifier (after)
1311 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001312 /// CHECK-DAG: If [<<Field>>]
1313
1314 /// CHECK-START: int Main.booleanFieldNotEqualOne() instruction_simplifier_before_codegen (after)
1315 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1316 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1317 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1318 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1319 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001320
1321 public static int booleanFieldNotEqualOne() {
1322 return (booleanField == true) ? 13 : 54;
1323 }
1324
1325 /// CHECK-START: int Main.booleanFieldEqualZero() instruction_simplifier (before)
1326 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1327 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1328 /// CHECK-DAG: <<EQ:z\d+>> Equal [<<Field>>,<<Const0>>]
1329 /// CHECK-DAG: If [<<EQ>>]
1330
1331 /// CHECK-START: int Main.booleanFieldEqualZero() instruction_simplifier (after)
1332 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001333 /// CHECK-DAG: If [<<Field>>]
1334
1335 /// CHECK-START: int Main.booleanFieldEqualZero() instruction_simplifier_before_codegen (after)
1336 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1337 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1338 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1339 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1340 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001341
1342 public static int booleanFieldEqualZero() {
1343 return (booleanField != false) ? 13 : 54;
1344 }
1345
1346 /// CHECK-START: int Main.intConditionNotEqualOne(int) instruction_simplifier_after_bce (before)
1347 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001348 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
Mark Mendellf6529172015-11-17 11:16:56 -05001349 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +00001350 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001351 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001352 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1353 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1354 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001355 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001356 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1357 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001358
1359 /// CHECK-START: int Main.intConditionNotEqualOne(int) instruction_simplifier_after_bce (after)
1360 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001361 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001362 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001363 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1364 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001365 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001366 /// CHECK-DAG: Return [<<Result>>]
1367 // Note that we match `LE` from Select because there are two identical
1368 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001369
1370 public static int intConditionNotEqualOne(int i) {
1371 return ((i > 42) == true) ? 13 : 54;
1372 }
1373
1374 /// CHECK-START: int Main.intConditionEqualZero(int) instruction_simplifier_after_bce (before)
1375 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1376 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001377 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1378 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001379 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001380 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1381 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1382 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
1383 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>]
1384 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1385 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001386
1387 /// CHECK-START: int Main.intConditionEqualZero(int) instruction_simplifier_after_bce (after)
1388 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001389 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001390 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001391 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1392 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001393 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001394 /// CHECK-DAG: Return [<<Result>>]
1395 // Note that we match `LE` from Select because there are two identical
1396 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001397
1398 public static int intConditionEqualZero(int i) {
1399 return ((i > 42) != false) ? 13 : 54;
1400 }
1401
1402 // Test that conditions on float/double are not flipped.
1403
David Brazdil74eb1b22015-12-14 11:44:01 +00001404 /// CHECK-START: int Main.floatConditionNotEqualOne(float) ssa_builder (after)
1405 /// CHECK: LessThanOrEqual
1406
Mark Mendellf6529172015-11-17 11:16:56 -05001407 /// CHECK-START: int Main.floatConditionNotEqualOne(float) register (before)
David Brazdil74eb1b22015-12-14 11:44:01 +00001408 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1409 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1410 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1411 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
1412 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1413 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1414 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001415
1416 public static int floatConditionNotEqualOne(float f) {
1417 return ((f > 42.0f) == true) ? 13 : 54;
1418 }
1419
David Brazdil74eb1b22015-12-14 11:44:01 +00001420 /// CHECK-START: int Main.doubleConditionEqualZero(double) ssa_builder (after)
1421 /// CHECK: LessThanOrEqual
1422
Mark Mendellf6529172015-11-17 11:16:56 -05001423 /// CHECK-START: int Main.doubleConditionEqualZero(double) register (before)
David Brazdil74eb1b22015-12-14 11:44:01 +00001424 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1425 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1426 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1427 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1428 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1429 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1430 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001431
1432 public static int doubleConditionEqualZero(double d) {
1433 return ((d > 42.0) != false) ? 13 : 54;
1434 }
Alexandre Rames38db7852015-11-20 15:02:45 +00001435
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001436 public static void main(String[] args) {
1437 int arg = 123456;
1438
1439 assertLongEquals(Add0(arg), arg);
1440 assertIntEquals(AndAllOnes(arg), arg);
1441 assertLongEquals(Div1(arg), arg);
1442 assertIntEquals(DivN1(arg), -arg);
1443 assertLongEquals(Mul1(arg), arg);
1444 assertIntEquals(MulN1(arg), -arg);
1445 assertLongEquals(MulPowerOfTwo128(arg), (128 * arg));
1446 assertIntEquals(Or0(arg), arg);
1447 assertLongEquals(OrSame(arg), arg);
1448 assertIntEquals(Shl0(arg), arg);
1449 assertLongEquals(Shr0(arg), arg);
1450 assertLongEquals(Sub0(arg), arg);
1451 assertIntEquals(SubAliasNeg(arg), -arg);
1452 assertLongEquals(UShr0(arg), arg);
1453 assertIntEquals(Xor0(arg), arg);
1454 assertIntEquals(XorAllOnes(arg), ~arg);
Alexandre Rames188d4312015-04-09 18:30:21 +01001455 assertIntEquals(AddNegs1(arg, arg + 1), -(arg + arg + 1));
1456 assertIntEquals(AddNegs2(arg, arg + 1), -(arg + arg + 1));
1457 assertLongEquals(AddNegs3(arg, arg + 1), -(2 * arg + 1));
1458 assertLongEquals(AddNeg1(arg, arg + 1), 1);
1459 assertLongEquals(AddNeg2(arg, arg + 1), -1);
1460 assertLongEquals(NegNeg1(arg), arg);
1461 assertIntEquals(NegNeg2(arg), 0);
1462 assertLongEquals(NegNeg3(arg), arg);
1463 assertIntEquals(NegSub1(arg, arg + 1), 1);
1464 assertIntEquals(NegSub2(arg, arg + 1), 1);
1465 assertLongEquals(NotNot1(arg), arg);
1466 assertIntEquals(NotNot2(arg), -1);
1467 assertIntEquals(SubNeg1(arg, arg + 1), -(arg + arg + 1));
1468 assertIntEquals(SubNeg2(arg, arg + 1), -(arg + arg + 1));
1469 assertLongEquals(SubNeg3(arg, arg + 1), -(2 * arg + 1));
David Brazdil0d13fee2015-04-17 14:52:19 +01001470 assertIntEquals(EqualTrueRhs(true), 5);
1471 assertIntEquals(EqualTrueLhs(true), 5);
1472 assertIntEquals(EqualFalseRhs(true), 3);
1473 assertIntEquals(EqualFalseLhs(true), 3);
1474 assertIntEquals(NotEqualTrueRhs(true), 3);
1475 assertIntEquals(NotEqualTrueLhs(true), 3);
1476 assertIntEquals(NotEqualFalseRhs(true), 5);
1477 assertIntEquals(NotEqualFalseLhs(true), 5);
David Brazdil74eb1b22015-12-14 11:44:01 +00001478 assertBooleanEquals(EqualBoolVsIntConst(true), true);
1479 assertBooleanEquals(EqualBoolVsIntConst(true), true);
1480 assertBooleanEquals(NotEqualBoolVsIntConst(false), false);
1481 assertBooleanEquals(NotEqualBoolVsIntConst(false), false);
David Brazdil0d13fee2015-04-17 14:52:19 +01001482 assertBooleanEquals(NotNotBool(true), true);
1483 assertBooleanEquals(NotNotBool(false), false);
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001484 assertFloatEquals(Div2(100.0f), 50.0f);
1485 assertDoubleEquals(Div2(150.0), 75.0);
1486 assertFloatEquals(DivMP25(100.0f), -400.0f);
1487 assertDoubleEquals(DivMP25(150.0), -600.0);
Vladimir Marko452c1b62015-09-25 14:44:17 +01001488 assertIntEquals(UShr28And15(0xc1234567), 0xc);
1489 assertLongEquals(UShr60And15(0xc123456787654321L), 0xcL);
1490 assertIntEquals(UShr28And7(0xc1234567), 0x4);
1491 assertLongEquals(UShr60And7(0xc123456787654321L), 0x4L);
1492 assertIntEquals(Shr24And255(0xc1234567), 0xc1);
1493 assertLongEquals(Shr56And255(0xc123456787654321L), 0xc1L);
1494 assertIntEquals(Shr24And127(0xc1234567), 0x41);
1495 assertLongEquals(Shr56And127(0xc123456787654321L), 0x41L);
Alexandre Rames38db7852015-11-20 15:02:45 +00001496 assertIntEquals(0, mulPow2Plus1(0));
1497 assertIntEquals(9, mulPow2Plus1(1));
1498 assertIntEquals(18, mulPow2Plus1(2));
1499 assertIntEquals(900, mulPow2Plus1(100));
1500 assertIntEquals(111105, mulPow2Plus1(12345));
1501 assertLongEquals(0, mulPow2Minus1(0));
1502 assertLongEquals(31, mulPow2Minus1(1));
1503 assertLongEquals(62, mulPow2Minus1(2));
1504 assertLongEquals(3100, mulPow2Minus1(100));
1505 assertLongEquals(382695, mulPow2Minus1(12345));
Mark Mendellf6529172015-11-17 11:16:56 -05001506
1507 booleanField = false;
1508 assertIntEquals(booleanFieldNotEqualOne(), 54);
1509 assertIntEquals(booleanFieldEqualZero(), 54);
1510 booleanField = true;
1511 assertIntEquals(booleanFieldNotEqualOne(), 13);
1512 assertIntEquals(booleanFieldEqualZero(), 13);
1513 assertIntEquals(intConditionNotEqualOne(6), 54);
1514 assertIntEquals(intConditionNotEqualOne(43), 13);
1515 assertIntEquals(intConditionEqualZero(6), 54);
1516 assertIntEquals(intConditionEqualZero(43), 13);
1517 assertIntEquals(floatConditionNotEqualOne(6.0f), 54);
1518 assertIntEquals(floatConditionNotEqualOne(43.0f), 13);
1519 assertIntEquals(doubleConditionEqualZero(6.0), 54);
1520 assertIntEquals(doubleConditionEqualZero(43.0), 13);
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001521 }
Mark Mendellf6529172015-11-17 11:16:56 -05001522
1523 public static boolean booleanField;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001524}