blob: 07478b2ac11af6eeb5f5ddf81858231dab1c2309 [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
Vladimir Markob52bbde2016-02-12 12:06:05 +000049 public static void assertStringEquals(String expected, String result) {
50 if (expected == null ? result != null : !expected.equals(result)) {
51 throw new Error("Expected: " + expected + ", found: " + result);
52 }
53 }
54
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000055 /**
56 * Tiny programs exercising optimizations of arithmetic identities.
57 */
58
David Brazdila06d66a2015-05-28 11:14:54 +010059 /// CHECK-START: long Main.Add0(long) instruction_simplifier (before)
60 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
61 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
62 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const0>>,<<Arg>>]
63 /// CHECK-DAG: Return [<<Add>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000064
David Brazdila06d66a2015-05-28 11:14:54 +010065 /// CHECK-START: long Main.Add0(long) instruction_simplifier (after)
66 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
67 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +010068
David Brazdila06d66a2015-05-28 11:14:54 +010069 /// CHECK-START: long Main.Add0(long) instruction_simplifier (after)
70 /// CHECK-NOT: Add
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000071
72 public static long Add0(long arg) {
73 return 0 + arg;
74 }
75
David Brazdila06d66a2015-05-28 11:14:54 +010076 /// CHECK-START: int Main.AndAllOnes(int) instruction_simplifier (before)
77 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
78 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
79 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<ConstF>>]
80 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000081
David Brazdila06d66a2015-05-28 11:14:54 +010082 /// CHECK-START: int Main.AndAllOnes(int) instruction_simplifier (after)
83 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
84 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000085
David Brazdila06d66a2015-05-28 11:14:54 +010086 /// CHECK-START: int Main.AndAllOnes(int) instruction_simplifier (after)
87 /// CHECK-NOT: And
Alexandre Rames74417692015-04-09 15:21:41 +010088
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000089 public static int AndAllOnes(int arg) {
90 return arg & -1;
91 }
92
Vladimir Marko452c1b62015-09-25 14:44:17 +010093 /// CHECK-START: int Main.UShr28And15(int) instruction_simplifier (before)
94 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
95 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
96 /// CHECK-DAG: <<Const15:i\d+>> IntConstant 15
97 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
98 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const15>>]
99 /// CHECK-DAG: Return [<<And>>]
100
101 /// CHECK-START: int Main.UShr28And15(int) instruction_simplifier (after)
102 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
103 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
104 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
105 /// CHECK-DAG: Return [<<UShr>>]
106
107 /// CHECK-START: int Main.UShr28And15(int) instruction_simplifier (after)
108 /// CHECK-NOT: And
109
110 public static int UShr28And15(int arg) {
111 return (arg >>> 28) & 15;
112 }
113
114 /// CHECK-START: long Main.UShr60And15(long) instruction_simplifier (before)
115 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
116 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
117 /// CHECK-DAG: <<Const15:j\d+>> LongConstant 15
118 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
119 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const15>>]
120 /// CHECK-DAG: Return [<<And>>]
121
122 /// CHECK-START: long Main.UShr60And15(long) instruction_simplifier (after)
123 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
124 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
125 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
126 /// CHECK-DAG: Return [<<UShr>>]
127
128 /// CHECK-START: long Main.UShr60And15(long) instruction_simplifier (after)
129 /// CHECK-NOT: And
130
131 public static long UShr60And15(long arg) {
132 return (arg >>> 60) & 15;
133 }
134
135 /// CHECK-START: int Main.UShr28And7(int) instruction_simplifier (before)
136 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
137 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
138 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
139 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
140 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
141 /// CHECK-DAG: Return [<<And>>]
142
143 /// CHECK-START: int Main.UShr28And7(int) instruction_simplifier (after)
144 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
145 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
146 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
147 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
148 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
149 /// CHECK-DAG: Return [<<And>>]
150
151 public static int UShr28And7(int arg) {
152 return (arg >>> 28) & 7;
153 }
154
155 /// CHECK-START: long Main.UShr60And7(long) instruction_simplifier (before)
156 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
157 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
158 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
159 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
160 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
161 /// CHECK-DAG: Return [<<And>>]
162
163 /// CHECK-START: long Main.UShr60And7(long) instruction_simplifier (after)
164 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
165 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
166 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
167 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
168 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
169 /// CHECK-DAG: Return [<<And>>]
170
171 public static long UShr60And7(long arg) {
172 return (arg >>> 60) & 7;
173 }
174
175 /// CHECK-START: int Main.Shr24And255(int) instruction_simplifier (before)
176 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
177 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
178 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
179 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
180 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const255>>]
181 /// CHECK-DAG: Return [<<And>>]
182
183 /// CHECK-START: int Main.Shr24And255(int) instruction_simplifier (after)
184 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
185 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
186 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const24>>]
187 /// CHECK-DAG: Return [<<UShr>>]
188
189 /// CHECK-START: int Main.Shr24And255(int) instruction_simplifier (after)
190 /// CHECK-NOT: Shr
191 /// CHECK-NOT: And
192
193 public static int Shr24And255(int arg) {
194 return (arg >> 24) & 255;
195 }
196
197 /// CHECK-START: long Main.Shr56And255(long) instruction_simplifier (before)
198 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
199 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
200 /// CHECK-DAG: <<Const255:j\d+>> LongConstant 255
201 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
202 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const255>>]
203 /// CHECK-DAG: Return [<<And>>]
204
205 /// CHECK-START: long Main.Shr56And255(long) instruction_simplifier (after)
206 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
207 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
208 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const56>>]
209 /// CHECK-DAG: Return [<<UShr>>]
210
211 /// CHECK-START: long Main.Shr56And255(long) instruction_simplifier (after)
212 /// CHECK-NOT: Shr
213 /// CHECK-NOT: And
214
215 public static long Shr56And255(long arg) {
216 return (arg >> 56) & 255;
217 }
218
219 /// CHECK-START: int Main.Shr24And127(int) instruction_simplifier (before)
220 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
221 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
222 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
223 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
224 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
225 /// CHECK-DAG: Return [<<And>>]
226
227 /// CHECK-START: int Main.Shr24And127(int) instruction_simplifier (after)
228 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
229 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
230 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
231 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
232 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
233 /// CHECK-DAG: Return [<<And>>]
234
235 public static int Shr24And127(int arg) {
236 return (arg >> 24) & 127;
237 }
238
239 /// CHECK-START: long Main.Shr56And127(long) instruction_simplifier (before)
240 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
241 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
242 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
243 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
244 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
245 /// CHECK-DAG: Return [<<And>>]
246
247 /// CHECK-START: long Main.Shr56And127(long) instruction_simplifier (after)
248 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
249 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
250 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
251 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
252 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
253 /// CHECK-DAG: Return [<<And>>]
254
255 public static long Shr56And127(long arg) {
256 return (arg >> 56) & 127;
257 }
258
David Brazdila06d66a2015-05-28 11:14:54 +0100259 /// CHECK-START: long Main.Div1(long) instruction_simplifier (before)
260 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
261 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
262 /// CHECK-DAG: <<Div:j\d+>> Div [<<Arg>>,<<Const1>>]
263 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000264
David Brazdila06d66a2015-05-28 11:14:54 +0100265 /// CHECK-START: long Main.Div1(long) instruction_simplifier (after)
266 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
267 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000268
David Brazdila06d66a2015-05-28 11:14:54 +0100269 /// CHECK-START: long Main.Div1(long) instruction_simplifier (after)
270 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100271
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000272 public static long Div1(long arg) {
273 return arg / 1;
274 }
275
David Brazdila06d66a2015-05-28 11:14:54 +0100276 /// CHECK-START: int Main.DivN1(int) instruction_simplifier (before)
277 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
278 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
279 /// CHECK-DAG: <<Div:i\d+>> Div [<<Arg>>,<<ConstN1>>]
280 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000281
David Brazdila06d66a2015-05-28 11:14:54 +0100282 /// CHECK-START: int Main.DivN1(int) instruction_simplifier (after)
283 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
284 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
285 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000286
David Brazdila06d66a2015-05-28 11:14:54 +0100287 /// CHECK-START: int Main.DivN1(int) instruction_simplifier (after)
288 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100289
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000290 public static int DivN1(int arg) {
291 return arg / -1;
292 }
293
David Brazdila06d66a2015-05-28 11:14:54 +0100294 /// CHECK-START: long Main.Mul1(long) instruction_simplifier (before)
295 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
296 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
David Brazdil57e863c2016-01-11 10:27:13 +0000297 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const1>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100298 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000299
David Brazdila06d66a2015-05-28 11:14:54 +0100300 /// CHECK-START: long Main.Mul1(long) instruction_simplifier (after)
301 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
302 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000303
David Brazdila06d66a2015-05-28 11:14:54 +0100304 /// CHECK-START: long Main.Mul1(long) instruction_simplifier (after)
305 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100306
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000307 public static long Mul1(long arg) {
308 return arg * 1;
309 }
310
David Brazdila06d66a2015-05-28 11:14:54 +0100311 /// CHECK-START: int Main.MulN1(int) instruction_simplifier (before)
312 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
313 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
314 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Arg>>,<<ConstN1>>]
315 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000316
David Brazdila06d66a2015-05-28 11:14:54 +0100317 /// CHECK-START: int Main.MulN1(int) instruction_simplifier (after)
318 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
319 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
320 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000321
David Brazdila06d66a2015-05-28 11:14:54 +0100322 /// CHECK-START: int Main.MulN1(int) instruction_simplifier (after)
323 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100324
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000325 public static int MulN1(int arg) {
326 return arg * -1;
327 }
328
David Brazdila06d66a2015-05-28 11:14:54 +0100329 /// CHECK-START: long Main.MulPowerOfTwo128(long) instruction_simplifier (before)
330 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
331 /// CHECK-DAG: <<Const128:j\d+>> LongConstant 128
David Brazdil57e863c2016-01-11 10:27:13 +0000332 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const128>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100333 /// CHECK-DAG: Return [<<Mul>>]
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-DAG: <<Arg:j\d+>> ParameterValue
337 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
338 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Arg>>,<<Const7>>]
339 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000340
David Brazdila06d66a2015-05-28 11:14:54 +0100341 /// CHECK-START: long Main.MulPowerOfTwo128(long) instruction_simplifier (after)
342 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100343
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000344 public static long MulPowerOfTwo128(long arg) {
345 return arg * 128;
346 }
347
David Brazdila06d66a2015-05-28 11:14:54 +0100348 /// CHECK-START: int Main.Or0(int) instruction_simplifier (before)
349 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
350 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
351 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<Const0>>]
352 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000353
David Brazdila06d66a2015-05-28 11:14:54 +0100354 /// CHECK-START: int Main.Or0(int) instruction_simplifier (after)
355 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
356 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000357
David Brazdila06d66a2015-05-28 11:14:54 +0100358 /// CHECK-START: int Main.Or0(int) instruction_simplifier (after)
359 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100360
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000361 public static int Or0(int arg) {
362 return arg | 0;
363 }
364
David Brazdila06d66a2015-05-28 11:14:54 +0100365 /// CHECK-START: long Main.OrSame(long) instruction_simplifier (before)
366 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
367 /// CHECK-DAG: <<Or:j\d+>> Or [<<Arg>>,<<Arg>>]
368 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000369
David Brazdila06d66a2015-05-28 11:14:54 +0100370 /// CHECK-START: long Main.OrSame(long) instruction_simplifier (after)
371 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
372 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000373
David Brazdila06d66a2015-05-28 11:14:54 +0100374 /// CHECK-START: long Main.OrSame(long) instruction_simplifier (after)
375 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100376
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000377 public static long OrSame(long arg) {
378 return arg | arg;
379 }
380
David Brazdila06d66a2015-05-28 11:14:54 +0100381 /// CHECK-START: int Main.Shl0(int) instruction_simplifier (before)
382 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
383 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
384 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Arg>>,<<Const0>>]
385 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000386
David Brazdila06d66a2015-05-28 11:14:54 +0100387 /// CHECK-START: int Main.Shl0(int) instruction_simplifier (after)
388 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
389 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000390
David Brazdila06d66a2015-05-28 11:14:54 +0100391 /// CHECK-START: int Main.Shl0(int) instruction_simplifier (after)
392 /// CHECK-NOT: Shl
Alexandre Rames74417692015-04-09 15:21:41 +0100393
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000394 public static int Shl0(int arg) {
395 return arg << 0;
396 }
397
David Brazdila06d66a2015-05-28 11:14:54 +0100398 /// CHECK-START: long Main.Shr0(long) instruction_simplifier (before)
399 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
400 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
401 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const0>>]
402 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000403
David Brazdila06d66a2015-05-28 11:14:54 +0100404 /// CHECK-START: long Main.Shr0(long) instruction_simplifier (after)
405 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
406 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000407
David Brazdila06d66a2015-05-28 11:14:54 +0100408 /// CHECK-START: long Main.Shr0(long) instruction_simplifier (after)
409 /// CHECK-NOT: Shr
Alexandre Rames74417692015-04-09 15:21:41 +0100410
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000411 public static long Shr0(long arg) {
412 return arg >> 0;
413 }
414
David Brazdila06d66a2015-05-28 11:14:54 +0100415 /// CHECK-START: long Main.Sub0(long) instruction_simplifier (before)
416 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
417 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
418 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Const0>>]
419 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000420
David Brazdila06d66a2015-05-28 11:14:54 +0100421 /// CHECK-START: long Main.Sub0(long) instruction_simplifier (after)
422 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
423 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000424
David Brazdila06d66a2015-05-28 11:14:54 +0100425 /// CHECK-START: long Main.Sub0(long) instruction_simplifier (after)
426 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100427
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000428 public static long Sub0(long arg) {
429 return arg - 0;
430 }
431
David Brazdila06d66a2015-05-28 11:14:54 +0100432 /// CHECK-START: int Main.SubAliasNeg(int) instruction_simplifier (before)
433 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
434 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
435 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const0>>,<<Arg>>]
436 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000437
David Brazdila06d66a2015-05-28 11:14:54 +0100438 /// CHECK-START: int Main.SubAliasNeg(int) instruction_simplifier (after)
439 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
440 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
441 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000442
David Brazdila06d66a2015-05-28 11:14:54 +0100443 /// CHECK-START: int Main.SubAliasNeg(int) instruction_simplifier (after)
444 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100445
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000446 public static int SubAliasNeg(int arg) {
447 return 0 - arg;
448 }
449
David Brazdila06d66a2015-05-28 11:14:54 +0100450 /// CHECK-START: long Main.UShr0(long) instruction_simplifier (before)
451 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
452 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
453 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const0>>]
454 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000455
David Brazdila06d66a2015-05-28 11:14:54 +0100456 /// CHECK-START: long Main.UShr0(long) instruction_simplifier (after)
457 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
458 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000459
David Brazdila06d66a2015-05-28 11:14:54 +0100460 /// CHECK-START: long Main.UShr0(long) instruction_simplifier (after)
461 /// CHECK-NOT: UShr
Alexandre Rames74417692015-04-09 15:21:41 +0100462
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000463 public static long UShr0(long arg) {
464 return arg >>> 0;
465 }
466
David Brazdila06d66a2015-05-28 11:14:54 +0100467 /// CHECK-START: int Main.Xor0(int) instruction_simplifier (before)
468 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
469 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
470 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Const0>>]
471 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000472
David Brazdila06d66a2015-05-28 11:14:54 +0100473 /// CHECK-START: int Main.Xor0(int) instruction_simplifier (after)
474 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
475 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000476
David Brazdila06d66a2015-05-28 11:14:54 +0100477 /// CHECK-START: int Main.Xor0(int) instruction_simplifier (after)
478 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100479
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000480 public static int Xor0(int arg) {
481 return arg ^ 0;
482 }
483
David Brazdila06d66a2015-05-28 11:14:54 +0100484 /// CHECK-START: int Main.XorAllOnes(int) instruction_simplifier (before)
485 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
486 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
487 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<ConstF>>]
488 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000489
David Brazdila06d66a2015-05-28 11:14:54 +0100490 /// CHECK-START: int Main.XorAllOnes(int) instruction_simplifier (after)
491 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
492 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
493 /// CHECK-DAG: Return [<<Not>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000494
David Brazdila06d66a2015-05-28 11:14:54 +0100495 /// CHECK-START: int Main.XorAllOnes(int) instruction_simplifier (after)
496 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100497
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000498 public static int XorAllOnes(int arg) {
499 return arg ^ -1;
500 }
501
Alexandre Rames188d4312015-04-09 18:30:21 +0100502 /**
503 * Test that addition or subtraction operation with both inputs negated are
504 * optimized to use a single negation after the operation.
505 * The transformation tested is implemented in
506 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
507 */
508
David Brazdila06d66a2015-05-28 11:14:54 +0100509 /// CHECK-START: int Main.AddNegs1(int, int) instruction_simplifier (before)
510 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
511 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
512 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
513 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
514 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
515 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100516
David Brazdila06d66a2015-05-28 11:14:54 +0100517 /// CHECK-START: int Main.AddNegs1(int, int) instruction_simplifier (after)
518 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
519 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
520 /// CHECK-NOT: Neg
521 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
522 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
523 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100524
525 public static int AddNegs1(int arg1, int arg2) {
526 return -arg1 + -arg2;
527 }
528
529 /**
530 * This is similar to the test-case AddNegs1, but the negations have
531 * multiple uses.
532 * The transformation tested is implemented in
533 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
534 * The current code won't perform the previous optimization. The
535 * transformations do not look at other uses of their inputs. As they don't
536 * know what will happen with other uses, they do not take the risk of
537 * increasing the register pressure by creating or extending live ranges.
538 */
539
David Brazdila06d66a2015-05-28 11:14:54 +0100540 /// CHECK-START: int Main.AddNegs2(int, int) instruction_simplifier (before)
541 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
542 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
543 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
544 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
545 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
546 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
547 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
548 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100549
David Brazdila06d66a2015-05-28 11:14:54 +0100550 /// CHECK-START: int Main.AddNegs2(int, int) instruction_simplifier (after)
551 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
552 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
553 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
554 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
555 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
556 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
557 /// CHECK-NOT: Neg
558 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
559 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100560
David Brazdila06d66a2015-05-28 11:14:54 +0100561 /// CHECK-START: int Main.AddNegs2(int, int) GVN (after)
562 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
563 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
564 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
565 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
566 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
567 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add>>,<<Add>>]
568 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100569
Alexandre Rames188d4312015-04-09 18:30:21 +0100570 public static int AddNegs2(int arg1, int arg2) {
571 int temp1 = -arg1;
572 int temp2 = -arg2;
573 return (temp1 + temp2) | (temp1 + temp2);
574 }
575
576 /**
577 * This follows test-cases AddNegs1 and AddNegs2.
578 * The transformation tested is implemented in
579 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
580 * The optimization should not happen if it moves an additional instruction in
581 * the loop.
582 */
583
David Brazdila06d66a2015-05-28 11:14:54 +0100584 /// CHECK-START: long Main.AddNegs3(long, long) instruction_simplifier (before)
585 // -------------- Arguments and initial negation operations.
586 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
587 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
588 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
589 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
590 /// CHECK: Goto
591 // -------------- Loop
592 /// CHECK: SuspendCheck
593 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
594 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100595
David Brazdila06d66a2015-05-28 11:14:54 +0100596 /// CHECK-START: long Main.AddNegs3(long, long) instruction_simplifier (after)
597 // -------------- Arguments and initial negation operations.
598 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
599 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
600 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
601 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
602 /// CHECK: Goto
603 // -------------- Loop
604 /// CHECK: SuspendCheck
605 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
606 /// CHECK-NOT: Neg
607 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100608
609 public static long AddNegs3(long arg1, long arg2) {
610 long res = 0;
611 long n_arg1 = -arg1;
612 long n_arg2 = -arg2;
613 for (long i = 0; i < 1; i++) {
614 res += n_arg1 + n_arg2 + i;
615 }
616 return res;
617 }
618
619 /**
620 * Test the simplification of an addition with a negated argument into a
621 * subtraction.
622 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
623 */
624
David Brazdila06d66a2015-05-28 11:14:54 +0100625 /// CHECK-START: long Main.AddNeg1(long, long) instruction_simplifier (before)
626 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
627 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
628 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
629 /// CHECK-DAG: <<Add:j\d+>> Add [<<Neg>>,<<Arg2>>]
630 /// CHECK-DAG: Return [<<Add>>]
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-DAG: <<Arg1:j\d+>> ParameterValue
634 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
635 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg2>>,<<Arg1>>]
636 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100637
David Brazdila06d66a2015-05-28 11:14:54 +0100638 /// CHECK-START: long Main.AddNeg1(long, long) instruction_simplifier (after)
639 /// CHECK-NOT: Neg
640 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100641
642 public static long AddNeg1(long arg1, long arg2) {
643 return -arg1 + arg2;
644 }
645
646 /**
647 * This is similar to the test-case AddNeg1, but the negation has two uses.
648 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
649 * The current code won't perform the previous optimization. The
650 * transformations do not look at other uses of their inputs. As they don't
651 * know what will happen with other uses, they do not take the risk of
652 * increasing the register pressure by creating or extending live ranges.
653 */
654
David Brazdila06d66a2015-05-28 11:14:54 +0100655 /// CHECK-START: long Main.AddNeg2(long, long) instruction_simplifier (before)
656 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
657 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
658 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
659 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
660 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
661 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
662 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100663
David Brazdila06d66a2015-05-28 11:14:54 +0100664 /// CHECK-START: long Main.AddNeg2(long, long) instruction_simplifier (after)
665 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
666 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
667 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
668 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
669 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
670 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
671 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100672
David Brazdila06d66a2015-05-28 11:14:54 +0100673 /// CHECK-START: long Main.AddNeg2(long, long) instruction_simplifier (after)
674 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100675
676 public static long AddNeg2(long arg1, long arg2) {
677 long temp = -arg2;
678 return (arg1 + temp) | (arg1 + temp);
679 }
680
681 /**
682 * Test simplification of the `-(-var)` pattern.
683 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
684 */
685
David Brazdila06d66a2015-05-28 11:14:54 +0100686 /// CHECK-START: long Main.NegNeg1(long) instruction_simplifier (before)
687 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
688 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg>>]
689 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Neg1>>]
690 /// CHECK-DAG: Return [<<Neg2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100691
David Brazdila06d66a2015-05-28 11:14:54 +0100692 /// CHECK-START: long Main.NegNeg1(long) instruction_simplifier (after)
693 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
694 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100695
David Brazdila06d66a2015-05-28 11:14:54 +0100696 /// CHECK-START: long Main.NegNeg1(long) instruction_simplifier (after)
697 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100698
699 public static long NegNeg1(long arg) {
700 return -(-arg);
701 }
702
703 /**
704 * Test 'multi-step' simplification, where a first transformation yields a
705 * new simplification possibility for the current instruction.
706 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
707 * and in `InstructionSimplifierVisitor::VisitAdd`.
708 */
709
David Brazdila06d66a2015-05-28 11:14:54 +0100710 /// CHECK-START: int Main.NegNeg2(int) instruction_simplifier (before)
711 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
712 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg>>]
713 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Neg1>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000714 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg2>>,<<Neg1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100715 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100716
David Brazdila06d66a2015-05-28 11:14:54 +0100717 /// CHECK-START: int Main.NegNeg2(int) instruction_simplifier (after)
718 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
719 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg>>,<<Arg>>]
720 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100721
David Brazdila06d66a2015-05-28 11:14:54 +0100722 /// CHECK-START: int Main.NegNeg2(int) instruction_simplifier (after)
723 /// CHECK-NOT: Neg
724 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100725
David Brazdila06d66a2015-05-28 11:14:54 +0100726 /// CHECK-START: int Main.NegNeg2(int) constant_folding_after_inlining (after)
727 /// CHECK: <<Const0:i\d+>> IntConstant 0
728 /// CHECK-NOT: Neg
729 /// CHECK-NOT: Add
730 /// CHECK: Return [<<Const0>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100731
Alexandre Rames188d4312015-04-09 18:30:21 +0100732 public static int NegNeg2(int arg) {
733 int temp = -arg;
734 return temp + -temp;
735 }
736
737 /**
738 * Test another 'multi-step' simplification, where a first transformation
739 * yields a new simplification possibility for the current instruction.
740 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
741 * and in `InstructionSimplifierVisitor::VisitSub`.
742 */
743
David Brazdila06d66a2015-05-28 11:14:54 +0100744 /// CHECK-START: long Main.NegNeg3(long) instruction_simplifier (before)
745 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
746 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
747 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg>>]
748 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const0>>,<<Neg>>]
749 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100750
David Brazdila06d66a2015-05-28 11:14:54 +0100751 /// CHECK-START: long Main.NegNeg3(long) instruction_simplifier (after)
752 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
753 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100754
David Brazdila06d66a2015-05-28 11:14:54 +0100755 /// CHECK-START: long Main.NegNeg3(long) instruction_simplifier (after)
756 /// CHECK-NOT: Neg
757 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100758
759 public static long NegNeg3(long arg) {
760 return 0 - -arg;
761 }
762
763 /**
764 * Test that a negated subtraction is simplified to a subtraction with its
765 * arguments reversed.
766 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
767 */
768
David Brazdila06d66a2015-05-28 11:14:54 +0100769 /// CHECK-START: int Main.NegSub1(int, int) instruction_simplifier (before)
770 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
771 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
772 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
773 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Sub>>]
774 /// CHECK-DAG: Return [<<Neg>>]
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-DAG: <<Arg1:i\d+>> ParameterValue
778 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
779 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg2>>,<<Arg1>>]
780 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100781
David Brazdila06d66a2015-05-28 11:14:54 +0100782 /// CHECK-START: int Main.NegSub1(int, int) instruction_simplifier (after)
783 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100784
785 public static int NegSub1(int arg1, int arg2) {
786 return -(arg1 - arg2);
787 }
788
789 /**
790 * This is similar to the test-case NegSub1, but the subtraction has
791 * multiple uses.
792 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
793 * The current code won't perform the previous optimization. The
794 * transformations do not look at other uses of their inputs. As they don't
795 * know what will happen with other uses, they do not take the risk of
796 * increasing the register pressure by creating or extending live ranges.
797 */
798
David Brazdila06d66a2015-05-28 11:14:54 +0100799 /// CHECK-START: int Main.NegSub2(int, int) instruction_simplifier (before)
800 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
801 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
802 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
803 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
804 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
805 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
806 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100807
David Brazdila06d66a2015-05-28 11:14:54 +0100808 /// CHECK-START: int Main.NegSub2(int, int) instruction_simplifier (after)
809 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
810 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
811 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
812 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
813 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
814 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
815 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100816
817 public static int NegSub2(int arg1, int arg2) {
818 int temp = arg1 - arg2;
819 return -temp | -temp;
820 }
821
822 /**
823 * Test simplification of the `~~var` pattern.
824 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`.
825 */
826
David Brazdila06d66a2015-05-28 11:14:54 +0100827 /// CHECK-START: long Main.NotNot1(long) instruction_simplifier (before)
828 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
829 /// CHECK-DAG: <<ConstF1:j\d+>> LongConstant -1
830 /// CHECK-DAG: <<Xor1:j\d+>> Xor [<<Arg>>,<<ConstF1>>]
831 /// CHECK-DAG: <<Xor2:j\d+>> Xor [<<Xor1>>,<<ConstF1>>]
832 /// CHECK-DAG: Return [<<Xor2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100833
David Brazdila06d66a2015-05-28 11:14:54 +0100834 /// CHECK-START: long Main.NotNot1(long) instruction_simplifier (after)
835 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
836 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100837
David Brazdila06d66a2015-05-28 11:14:54 +0100838 /// CHECK-START: long Main.NotNot1(long) instruction_simplifier (after)
839 /// CHECK-NOT: Xor
Alexandre Rames188d4312015-04-09 18:30:21 +0100840
841 public static long NotNot1(long arg) {
842 return ~~arg;
843 }
844
David Brazdila06d66a2015-05-28 11:14:54 +0100845 /// CHECK-START: int Main.NotNot2(int) instruction_simplifier (before)
846 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
847 /// CHECK-DAG: <<ConstF1:i\d+>> IntConstant -1
848 /// CHECK-DAG: <<Xor1:i\d+>> Xor [<<Arg>>,<<ConstF1>>]
849 /// CHECK-DAG: <<Xor2:i\d+>> Xor [<<Xor1>>,<<ConstF1>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000850 /// CHECK-DAG: <<Add:i\d+>> Add [<<Xor2>>,<<Xor1>>]
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)
860 /// CHECK-NOT: Xor
Alexandre Rames188d4312015-04-09 18:30:21 +0100861
862 public static int NotNot2(int arg) {
863 int temp = ~arg;
864 return temp + ~temp;
865 }
866
867 /**
868 * Test the simplification of a subtraction with a negated argument.
869 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
870 */
871
David Brazdila06d66a2015-05-28 11:14:54 +0100872 /// CHECK-START: int Main.SubNeg1(int, int) instruction_simplifier (before)
873 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
874 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
875 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
876 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Neg>>,<<Arg2>>]
877 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100878
David Brazdila06d66a2015-05-28 11:14:54 +0100879 /// CHECK-START: int Main.SubNeg1(int, int) instruction_simplifier (after)
880 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
881 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
882 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
883 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
884 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100885
David Brazdila06d66a2015-05-28 11:14:54 +0100886 /// CHECK-START: int Main.SubNeg1(int, int) instruction_simplifier (after)
887 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100888
889 public static int SubNeg1(int arg1, int arg2) {
890 return -arg1 - arg2;
891 }
892
893 /**
894 * This is similar to the test-case SubNeg1, but the negation has
895 * multiple uses.
896 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
897 * The current code won't perform the previous optimization. The
898 * transformations do not look at other uses of their inputs. As they don't
899 * know what will happen with other uses, they do not take the risk of
900 * increasing the register pressure by creating or extending live ranges.
901 */
902
David Brazdila06d66a2015-05-28 11:14:54 +0100903 /// CHECK-START: int Main.SubNeg2(int, int) instruction_simplifier (before)
904 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
905 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
906 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
907 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
908 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
909 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
910 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100911
David Brazdila06d66a2015-05-28 11:14:54 +0100912 /// CHECK-START: int Main.SubNeg2(int, int) instruction_simplifier (after)
913 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
914 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
915 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
916 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
917 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
918 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
919 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100920
David Brazdila06d66a2015-05-28 11:14:54 +0100921 /// CHECK-START: int Main.SubNeg2(int, int) instruction_simplifier (after)
922 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100923
924 public static int SubNeg2(int arg1, int arg2) {
925 int temp = -arg1;
926 return (temp - arg2) | (temp - arg2);
927 }
928
929 /**
930 * This follows test-cases SubNeg1 and SubNeg2.
931 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
932 * The optimization should not happen if it moves an additional instruction in
933 * the loop.
934 */
935
David Brazdila06d66a2015-05-28 11:14:54 +0100936 /// CHECK-START: long Main.SubNeg3(long, long) instruction_simplifier (before)
937 // -------------- Arguments and initial negation operation.
938 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
939 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
940 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
941 /// CHECK: Goto
942 // -------------- Loop
943 /// CHECK: SuspendCheck
944 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
945 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100946
David Brazdila06d66a2015-05-28 11:14:54 +0100947 /// CHECK-START: long Main.SubNeg3(long, long) instruction_simplifier (after)
948 // -------------- Arguments and initial negation operation.
949 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
950 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
951 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
952 /// CHECK-DAG: Goto
953 // -------------- Loop
954 /// CHECK: SuspendCheck
955 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
956 /// CHECK-NOT: Neg
957 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100958
959 public static long SubNeg3(long arg1, long arg2) {
960 long res = 0;
961 long temp = -arg1;
962 for (long i = 0; i < 1; i++) {
963 res += temp - arg2 - i;
964 }
965 return res;
966 }
967
David Brazdila06d66a2015-05-28 11:14:54 +0100968 /// CHECK-START: int Main.EqualTrueRhs(boolean) instruction_simplifier (before)
969 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
970 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
971 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Const1>>]
972 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +0100973
David Brazdila06d66a2015-05-28 11:14:54 +0100974 /// CHECK-START: int Main.EqualTrueRhs(boolean) instruction_simplifier (after)
975 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
976 /// CHECK-DAG: If [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +0100977
David Brazdil74eb1b22015-12-14 11:44:01 +0000978 /// CHECK-START: int Main.EqualTrueRhs(boolean) instruction_simplifier_before_codegen (after)
979 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
980 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
981 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
982 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const3>>,<<Const5>>,<<Arg>>]
983 /// CHECK-DAG: Return [<<Select>>]
984
David Brazdil0d13fee2015-04-17 14:52:19 +0100985 public static int EqualTrueRhs(boolean arg) {
986 return (arg != true) ? 3 : 5;
987 }
988
David Brazdila06d66a2015-05-28 11:14:54 +0100989 /// CHECK-START: int Main.EqualTrueLhs(boolean) instruction_simplifier (before)
990 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
991 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
992 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Const1>>,<<Arg>>]
993 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +0100994
David Brazdila06d66a2015-05-28 11:14:54 +0100995 /// CHECK-START: int Main.EqualTrueLhs(boolean) instruction_simplifier (after)
996 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
997 /// CHECK-DAG: If [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +0100998
David Brazdil74eb1b22015-12-14 11:44:01 +0000999 /// CHECK-START: int Main.EqualTrueLhs(boolean) instruction_simplifier_before_codegen (after)
1000 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1001 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1002 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1003 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const3>>,<<Const5>>,<<Arg>>]
1004 /// CHECK-DAG: Return [<<Select>>]
1005
David Brazdil0d13fee2015-04-17 14:52:19 +01001006 public static int EqualTrueLhs(boolean arg) {
1007 return (true != arg) ? 3 : 5;
1008 }
1009
David Brazdila06d66a2015-05-28 11:14:54 +01001010 /// CHECK-START: int Main.EqualFalseRhs(boolean) instruction_simplifier (before)
1011 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1012 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1013 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Const0>>]
1014 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001015
David Brazdila06d66a2015-05-28 11:14:54 +01001016 /// CHECK-START: int Main.EqualFalseRhs(boolean) instruction_simplifier (after)
1017 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001018 /// CHECK-DAG: If [<<Arg>>]
1019
1020 /// CHECK-START: int Main.EqualFalseRhs(boolean) instruction_simplifier_before_codegen (after)
1021 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1022 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1023 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1024 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const5>>,<<Const3>>,<<Arg>>]
1025 /// CHECK-DAG: Return [<<Select>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001026
1027 public static int EqualFalseRhs(boolean arg) {
1028 return (arg != false) ? 3 : 5;
1029 }
1030
David Brazdila06d66a2015-05-28 11:14:54 +01001031 /// CHECK-START: int Main.EqualFalseLhs(boolean) instruction_simplifier (before)
1032 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1033 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil57e863c2016-01-11 10:27:13 +00001034 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Const0>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001035 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001036
David Brazdila06d66a2015-05-28 11:14:54 +01001037 /// CHECK-START: int Main.EqualFalseLhs(boolean) instruction_simplifier (after)
1038 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001039 /// CHECK-DAG: If [<<Arg>>]
1040
1041 /// CHECK-START: int Main.EqualFalseLhs(boolean) instruction_simplifier_before_codegen (after)
1042 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1043 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1044 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1045 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const5>>,<<Const3>>,<<Arg>>]
1046 /// CHECK-DAG: Return [<<Select>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001047
1048 public static int EqualFalseLhs(boolean arg) {
1049 return (false != arg) ? 3 : 5;
1050 }
1051
David Brazdila06d66a2015-05-28 11:14:54 +01001052 /// CHECK-START: int Main.NotEqualTrueRhs(boolean) instruction_simplifier (before)
1053 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1054 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1055 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Arg>>,<<Const1>>]
1056 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001057
David Brazdila06d66a2015-05-28 11:14:54 +01001058 /// CHECK-START: int Main.NotEqualTrueRhs(boolean) instruction_simplifier (after)
1059 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001060 /// CHECK-DAG: If [<<Arg>>]
1061
1062 /// CHECK-START: int Main.NotEqualTrueRhs(boolean) instruction_simplifier_before_codegen (after)
1063 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1064 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1065 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1066 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const5>>,<<Const3>>,<<Arg>>]
1067 /// CHECK-DAG: Return [<<Select>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001068
1069 public static int NotEqualTrueRhs(boolean arg) {
1070 return (arg == true) ? 3 : 5;
1071 }
1072
David Brazdila06d66a2015-05-28 11:14:54 +01001073 /// CHECK-START: int Main.NotEqualTrueLhs(boolean) instruction_simplifier (before)
1074 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1075 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1076 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Const1>>,<<Arg>>]
1077 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001078
David Brazdila06d66a2015-05-28 11:14:54 +01001079 /// CHECK-START: int Main.NotEqualTrueLhs(boolean) instruction_simplifier (after)
1080 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001081 /// CHECK-DAG: If [<<Arg>>]
1082
1083 /// CHECK-START: int Main.NotEqualTrueLhs(boolean) instruction_simplifier_before_codegen (after)
1084 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1085 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1086 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1087 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const5>>,<<Const3>>,<<Arg>>]
1088 /// CHECK-DAG: Return [<<Select>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001089
1090 public static int NotEqualTrueLhs(boolean arg) {
1091 return (true == arg) ? 3 : 5;
1092 }
1093
David Brazdila06d66a2015-05-28 11:14:54 +01001094 /// CHECK-START: int Main.NotEqualFalseRhs(boolean) instruction_simplifier (before)
1095 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1096 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1097 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Arg>>,<<Const0>>]
1098 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001099
David Brazdila06d66a2015-05-28 11:14:54 +01001100 /// CHECK-START: int Main.NotEqualFalseRhs(boolean) instruction_simplifier (after)
1101 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1102 /// CHECK-DAG: If [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001103
David Brazdil74eb1b22015-12-14 11:44:01 +00001104 /// CHECK-START: int Main.NotEqualFalseRhs(boolean) instruction_simplifier_before_codegen (after)
1105 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1106 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1107 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1108 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const3>>,<<Const5>>,<<Arg>>]
1109 /// CHECK-DAG: Return [<<Select>>]
1110
David Brazdil0d13fee2015-04-17 14:52:19 +01001111 public static int NotEqualFalseRhs(boolean arg) {
1112 return (arg == false) ? 3 : 5;
1113 }
1114
David Brazdila06d66a2015-05-28 11:14:54 +01001115 /// CHECK-START: int Main.NotEqualFalseLhs(boolean) instruction_simplifier (before)
1116 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1117 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil57e863c2016-01-11 10:27:13 +00001118 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Arg>>,<<Const0>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001119 /// CHECK-DAG: If [<<Cond>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001120
David Brazdila06d66a2015-05-28 11:14:54 +01001121 /// CHECK-START: int Main.NotEqualFalseLhs(boolean) instruction_simplifier (after)
1122 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1123 /// CHECK-DAG: If [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001124
David Brazdil74eb1b22015-12-14 11:44:01 +00001125 /// CHECK-START: int Main.NotEqualFalseLhs(boolean) instruction_simplifier_before_codegen (after)
1126 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1127 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1128 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1129 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const3>>,<<Const5>>,<<Arg>>]
1130 /// CHECK-DAG: Return [<<Select>>]
1131
David Brazdil0d13fee2015-04-17 14:52:19 +01001132 public static int NotEqualFalseLhs(boolean arg) {
1133 return (false == arg) ? 3 : 5;
1134 }
1135
David Brazdil1e9ec052015-06-22 10:26:45 +01001136 /// CHECK-START: boolean Main.EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
1137 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001138 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1139 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001140 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001141 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1142 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<NotArg>>,<<Const2>>]
1143 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1144 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001145
1146 /// CHECK-START: boolean Main.EqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001147 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
1148 /// CHECK-DAG: Return [<<True>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001149
1150 public static boolean EqualBoolVsIntConst(boolean arg) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001151 return (arg ? 0 : 1) != 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001152 }
1153
1154 /// CHECK-START: boolean Main.NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (before)
1155 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001156 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1157 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001158 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001159 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1160 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<NotArg>>,<<Const2>>]
1161 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1162 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001163
1164 /// CHECK-START: boolean Main.NotEqualBoolVsIntConst(boolean) instruction_simplifier_after_bce (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001165 /// CHECK-DAG: <<False:i\d+>> IntConstant 0
1166 /// CHECK-DAG: Return [<<False>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001167
1168 public static boolean NotEqualBoolVsIntConst(boolean arg) {
David Brazdil74eb1b22015-12-14 11:44:01 +00001169 return (arg ? 0 : 1) == 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001170 }
1171
David Brazdil0d13fee2015-04-17 14:52:19 +01001172 /*
1173 * Test simplification of double Boolean negation. Note that sometimes
1174 * both negations can be removed but we only expect the simplifier to
1175 * remove the second.
1176 */
1177
Nicolas Geoffrayb2bdfce2015-06-18 15:46:47 +01001178 /// CHECK-START: boolean Main.NotNotBool(boolean) instruction_simplifier_after_bce (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001179 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001180 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1181 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1182 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1183 /// CHECK-DAG: <<NotNotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<NotArg>>]
David Brazdila06d66a2015-05-28 11:14:54 +01001184 /// CHECK-DAG: Return [<<NotNotArg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001185
Nicolas Geoffrayb2bdfce2015-06-18 15:46:47 +01001186 /// CHECK-START: boolean Main.NotNotBool(boolean) instruction_simplifier_after_bce (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001187 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdila06d66a2015-05-28 11:14:54 +01001188 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001189
David Brazdil769c9e52015-04-27 13:54:09 +01001190 public static boolean NegateValue(boolean arg) {
1191 return !arg;
1192 }
1193
David Brazdil0d13fee2015-04-17 14:52:19 +01001194 public static boolean NotNotBool(boolean arg) {
David Brazdil769c9e52015-04-27 13:54:09 +01001195 return !(NegateValue(arg));
David Brazdil0d13fee2015-04-17 14:52:19 +01001196 }
1197
David Brazdila06d66a2015-05-28 11:14:54 +01001198 /// CHECK-START: float Main.Div2(float) instruction_simplifier (before)
1199 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1200 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
1201 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>]
1202 /// CHECK-DAG: Return [<<Div>>]
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-DAG: <<Arg:f\d+>> ParameterValue
1206 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5
1207 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>]
1208 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001209
David Brazdila06d66a2015-05-28 11:14:54 +01001210 /// CHECK-START: float Main.Div2(float) instruction_simplifier (after)
1211 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001212
1213 public static float Div2(float arg) {
1214 return arg / 2.0f;
1215 }
1216
David Brazdila06d66a2015-05-28 11:14:54 +01001217 /// CHECK-START: double Main.Div2(double) instruction_simplifier (before)
1218 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1219 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
1220 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>]
1221 /// CHECK-DAG: Return [<<Div>>]
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-DAG: <<Arg:d\d+>> ParameterValue
1225 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5
1226 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>]
1227 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001228
David Brazdila06d66a2015-05-28 11:14:54 +01001229 /// CHECK-START: double Main.Div2(double) instruction_simplifier (after)
1230 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001231 public static double Div2(double arg) {
1232 return arg / 2.0;
1233 }
1234
David Brazdila06d66a2015-05-28 11:14:54 +01001235 /// CHECK-START: float Main.DivMP25(float) instruction_simplifier (before)
1236 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1237 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25
1238 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>]
1239 /// CHECK-DAG: Return [<<Div>>]
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-DAG: <<Arg:f\d+>> ParameterValue
1243 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4
1244 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>]
1245 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001246
David Brazdila06d66a2015-05-28 11:14:54 +01001247 /// CHECK-START: float Main.DivMP25(float) instruction_simplifier (after)
1248 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001249
1250 public static float DivMP25(float arg) {
1251 return arg / -0.25f;
1252 }
1253
David Brazdila06d66a2015-05-28 11:14:54 +01001254 /// CHECK-START: double Main.DivMP25(double) instruction_simplifier (before)
1255 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1256 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25
1257 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>]
1258 /// CHECK-DAG: Return [<<Div>>]
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-DAG: <<Arg:d\d+>> ParameterValue
1262 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4
1263 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>]
1264 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001265
David Brazdila06d66a2015-05-28 11:14:54 +01001266 /// CHECK-START: double Main.DivMP25(double) instruction_simplifier (after)
1267 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001268 public static double DivMP25(double arg) {
1269 return arg / -0.25f;
1270 }
1271
Alexandre Rames38db7852015-11-20 15:02:45 +00001272 /**
1273 * Test strength reduction of factors of the form (2^n + 1).
1274 */
1275
1276 /// CHECK-START: int Main.mulPow2Plus1(int) instruction_simplifier (before)
1277 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1278 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
1279 /// CHECK: Mul [<<Arg>>,<<Const9>>]
1280
1281 /// CHECK-START: int Main.mulPow2Plus1(int) instruction_simplifier (after)
1282 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1283 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1284 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>]
1285 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>]
1286
1287 public static int mulPow2Plus1(int arg) {
1288 return arg * 9;
1289 }
1290
Alexandre Rames38db7852015-11-20 15:02:45 +00001291 /**
1292 * Test strength reduction of factors of the form (2^n - 1).
1293 */
1294
1295 /// CHECK-START: long Main.mulPow2Minus1(long) instruction_simplifier (before)
1296 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1297 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31
David Brazdil57e863c2016-01-11 10:27:13 +00001298 /// CHECK: Mul [<<Const31>>,<<Arg>>]
Alexandre Rames38db7852015-11-20 15:02:45 +00001299
1300 /// CHECK-START: long Main.mulPow2Minus1(long) instruction_simplifier (after)
1301 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1302 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1303 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>]
1304 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>]
1305
1306 public static long mulPow2Minus1(long arg) {
1307 return arg * 31;
1308 }
1309
Mark Mendellf6529172015-11-17 11:16:56 -05001310 /// CHECK-START: int Main.booleanFieldNotEqualOne() instruction_simplifier (before)
1311 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1312 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1313 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>]
1314 /// CHECK-DAG: If [<<NE>>]
1315
1316 /// CHECK-START: int Main.booleanFieldNotEqualOne() instruction_simplifier (after)
1317 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001318 /// CHECK-DAG: If [<<Field>>]
1319
1320 /// CHECK-START: int Main.booleanFieldNotEqualOne() instruction_simplifier_before_codegen (after)
1321 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1322 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1323 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1324 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1325 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001326
1327 public static int booleanFieldNotEqualOne() {
1328 return (booleanField == true) ? 13 : 54;
1329 }
1330
1331 /// CHECK-START: int Main.booleanFieldEqualZero() instruction_simplifier (before)
1332 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1333 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1334 /// CHECK-DAG: <<EQ:z\d+>> Equal [<<Field>>,<<Const0>>]
1335 /// CHECK-DAG: If [<<EQ>>]
1336
1337 /// CHECK-START: int Main.booleanFieldEqualZero() instruction_simplifier (after)
1338 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdil74eb1b22015-12-14 11:44:01 +00001339 /// CHECK-DAG: If [<<Field>>]
1340
1341 /// CHECK-START: int Main.booleanFieldEqualZero() instruction_simplifier_before_codegen (after)
1342 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1343 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1344 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1345 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1346 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001347
1348 public static int booleanFieldEqualZero() {
1349 return (booleanField != false) ? 13 : 54;
1350 }
1351
1352 /// CHECK-START: int Main.intConditionNotEqualOne(int) instruction_simplifier_after_bce (before)
1353 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001354 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
Mark Mendellf6529172015-11-17 11:16:56 -05001355 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +00001356 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001357 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001358 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1359 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1360 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001361 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001362 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1363 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001364
1365 /// CHECK-START: int Main.intConditionNotEqualOne(int) instruction_simplifier_after_bce (after)
1366 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001367 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001368 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001369 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1370 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001371 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001372 /// CHECK-DAG: Return [<<Result>>]
1373 // Note that we match `LE` from Select because there are two identical
1374 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001375
1376 public static int intConditionNotEqualOne(int i) {
1377 return ((i > 42) == true) ? 13 : 54;
1378 }
1379
1380 /// CHECK-START: int Main.intConditionEqualZero(int) instruction_simplifier_after_bce (before)
1381 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1382 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001383 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1384 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001385 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001386 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1387 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1388 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
1389 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>]
1390 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1391 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001392
1393 /// CHECK-START: int Main.intConditionEqualZero(int) instruction_simplifier_after_bce (after)
1394 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001395 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001396 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001397 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1398 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001399 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001400 /// CHECK-DAG: Return [<<Result>>]
1401 // Note that we match `LE` from Select because there are two identical
1402 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001403
1404 public static int intConditionEqualZero(int i) {
1405 return ((i > 42) != false) ? 13 : 54;
1406 }
1407
1408 // Test that conditions on float/double are not flipped.
1409
David Brazdil74eb1b22015-12-14 11:44:01 +00001410 /// CHECK-START: int Main.floatConditionNotEqualOne(float) ssa_builder (after)
1411 /// CHECK: LessThanOrEqual
1412
Mark P Mendell2f10a5f2016-01-25 14:47:50 +00001413 /// CHECK-START: int Main.floatConditionNotEqualOne(float) instruction_simplifier_before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001414 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1415 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1416 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1417 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
1418 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1419 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1420 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001421
1422 public static int floatConditionNotEqualOne(float f) {
1423 return ((f > 42.0f) == true) ? 13 : 54;
1424 }
1425
David Brazdil74eb1b22015-12-14 11:44:01 +00001426 /// CHECK-START: int Main.doubleConditionEqualZero(double) ssa_builder (after)
1427 /// CHECK: LessThanOrEqual
1428
Mark P Mendell2f10a5f2016-01-25 14:47:50 +00001429 /// CHECK-START: int Main.doubleConditionEqualZero(double) instruction_simplifier_before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001430 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1431 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1432 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1433 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1434 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1435 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1436 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001437
1438 public static int doubleConditionEqualZero(double d) {
1439 return ((d > 42.0) != false) ? 13 : 54;
1440 }
Alexandre Rames38db7852015-11-20 15:02:45 +00001441
Vladimir Markob52bbde2016-02-12 12:06:05 +00001442 /// CHECK-START: int Main.intToDoubleToInt(int) instruction_simplifier (before)
1443 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1444 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1445 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1446 /// CHECK-DAG: Return [<<Int>>]
1447
1448 /// CHECK-START: int Main.intToDoubleToInt(int) instruction_simplifier (after)
1449 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1450 /// CHECK-DAG: Return [<<Arg>>]
1451
1452 /// CHECK-START: int Main.intToDoubleToInt(int) instruction_simplifier (after)
1453 /// CHECK-NOT: TypeConversion
1454
1455 public static int intToDoubleToInt(int value) {
1456 // Lossless conversion followed by a conversion back.
1457 return (int) (double) value;
1458 }
1459
1460 /// CHECK-START: java.lang.String Main.intToDoubleToIntPrint(int) instruction_simplifier (before)
1461 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1462 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1463 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1464
1465 /// CHECK-START: java.lang.String Main.intToDoubleToIntPrint(int) instruction_simplifier (after)
1466 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1467 /// CHECK-DAG: {{d\d+}} TypeConversion [<<Arg>>]
1468
1469 /// CHECK-START: java.lang.String Main.intToDoubleToIntPrint(int) instruction_simplifier (after)
1470 /// CHECK-DAG: TypeConversion
1471 /// CHECK-NOT: TypeConversion
1472
1473 public static String intToDoubleToIntPrint(int value) {
1474 // Lossless conversion followed by a conversion back
1475 // with another use of the intermediate result.
1476 double d = (double) value;
1477 int i = (int) d;
1478 return "d=" + d + ", i=" + i;
1479 }
1480
1481 /// CHECK-START: int Main.byteToDoubleToInt(byte) instruction_simplifier (before)
1482 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1483 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1484 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1485 /// CHECK-DAG: Return [<<Int>>]
1486
1487 /// CHECK-START: int Main.byteToDoubleToInt(byte) instruction_simplifier (after)
1488 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1489 /// CHECK-DAG: Return [<<Arg>>]
1490
1491 /// CHECK-START: int Main.byteToDoubleToInt(byte) instruction_simplifier (after)
1492 /// CHECK-NOT: TypeConversion
1493
1494 public static int byteToDoubleToInt(byte value) {
1495 // Lossless conversion followed by another conversion, use implicit conversion.
1496 return (int) (double) value;
1497 }
1498
1499 /// CHECK-START: int Main.floatToDoubleToInt(float) instruction_simplifier (before)
1500 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1501 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1502 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1503 /// CHECK-DAG: Return [<<Int>>]
1504
1505 /// CHECK-START: int Main.floatToDoubleToInt(float) instruction_simplifier (after)
1506 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1507 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1508 /// CHECK-DAG: Return [<<Int>>]
1509
1510 /// CHECK-START: int Main.floatToDoubleToInt(float) instruction_simplifier (after)
1511 /// CHECK-DAG: TypeConversion
1512 /// CHECK-NOT: TypeConversion
1513
1514 public static int floatToDoubleToInt(float value) {
1515 // Lossless conversion followed by another conversion.
1516 return (int) (double) value;
1517 }
1518
1519 /// CHECK-START: java.lang.String Main.floatToDoubleToIntPrint(float) instruction_simplifier (before)
1520 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1521 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1522 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1523
1524 /// CHECK-START: java.lang.String Main.floatToDoubleToIntPrint(float) instruction_simplifier (after)
1525 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1526 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1527 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1528
1529 public static String floatToDoubleToIntPrint(float value) {
1530 // Lossless conversion followed by another conversion with
1531 // an extra use of the intermediate result.
1532 double d = (double) value;
1533 int i = (int) d;
1534 return "d=" + d + ", i=" + i;
1535 }
1536
1537 /// CHECK-START: short Main.byteToDoubleToShort(byte) instruction_simplifier (before)
1538 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1539 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1540 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1541 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1542 /// CHECK-DAG: Return [<<Short>>]
1543
1544 /// CHECK-START: short Main.byteToDoubleToShort(byte) instruction_simplifier (after)
1545 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1546 /// CHECK-DAG: Return [<<Arg>>]
1547
1548 /// CHECK-START: short Main.byteToDoubleToShort(byte) instruction_simplifier (after)
1549 /// CHECK-NOT: TypeConversion
1550
1551 public static short byteToDoubleToShort(byte value) {
1552 // Originally, this is byte->double->int->short. The first conversion is lossless,
1553 // so we merge this with the second one to byte->int which we omit as it's an implicit
1554 // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1555 return (short) (double) value;
1556 }
1557
1558 /// CHECK-START: short Main.charToDoubleToShort(char) instruction_simplifier (before)
1559 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1560 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1561 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1562 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1563 /// CHECK-DAG: Return [<<Short>>]
1564
1565 /// CHECK-START: short Main.charToDoubleToShort(char) instruction_simplifier (after)
1566 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1567 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Arg>>]
1568 /// CHECK-DAG: Return [<<Short>>]
1569
1570 /// CHECK-START: short Main.charToDoubleToShort(char) instruction_simplifier (after)
1571 /// CHECK-DAG: TypeConversion
1572 /// CHECK-NOT: TypeConversion
1573
1574 public static short charToDoubleToShort(char value) {
1575 // Originally, this is char->double->int->short. The first conversion is lossless,
1576 // so we merge this with the second one to char->int which we omit as it's an implicit
1577 // conversion. Then we are left with the resulting char->short conversion.
1578 return (short) (double) value;
1579 }
1580
1581 /// CHECK-START: short Main.floatToIntToShort(float) instruction_simplifier (before)
1582 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1583 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1584 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1585 /// CHECK-DAG: Return [<<Short>>]
1586
1587 /// CHECK-START: short Main.floatToIntToShort(float) instruction_simplifier (after)
1588 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1589 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1590 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1591 /// CHECK-DAG: Return [<<Short>>]
1592
1593 public static short floatToIntToShort(float value) {
1594 // Lossy FP to integral conversion followed by another conversion: no simplification.
1595 return (short) value;
1596 }
1597
1598 /// CHECK-START: int Main.intToFloatToInt(int) instruction_simplifier (before)
1599 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1600 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1601 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1602 /// CHECK-DAG: Return [<<Int>>]
1603
1604 /// CHECK-START: int Main.intToFloatToInt(int) instruction_simplifier (after)
1605 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1606 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1607 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1608 /// CHECK-DAG: Return [<<Int>>]
1609
1610 public static int intToFloatToInt(int value) {
1611 // Lossy integral to FP conversion followed another conversion: no simplification.
1612 return (int) (float) value;
1613 }
1614
1615 /// CHECK-START: double Main.longToIntToDouble(long) instruction_simplifier (before)
1616 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1617 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1618 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1619 /// CHECK-DAG: Return [<<Double>>]
1620
1621 /// CHECK-START: double Main.longToIntToDouble(long) instruction_simplifier (after)
1622 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1623 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1624 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1625 /// CHECK-DAG: Return [<<Double>>]
1626
1627 public static double longToIntToDouble(long value) {
1628 // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1629 return (double) (int) value;
1630 }
1631
1632 /// CHECK-START: long Main.longToIntToLong(long) instruction_simplifier (before)
1633 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1634 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1635 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1636 /// CHECK-DAG: Return [<<Long>>]
1637
1638 /// CHECK-START: long Main.longToIntToLong(long) instruction_simplifier (after)
1639 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1640 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1641 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1642 /// CHECK-DAG: Return [<<Long>>]
1643
1644 public static long longToIntToLong(long value) {
1645 // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1646 return (long) (int) value;
1647 }
1648
1649 /// CHECK-START: short Main.shortToCharToShort(short) instruction_simplifier (before)
1650 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1651 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1652 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Char>>]
1653 /// CHECK-DAG: Return [<<Short>>]
1654
1655 /// CHECK-START: short Main.shortToCharToShort(short) instruction_simplifier (after)
1656 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1657 /// CHECK-DAG: Return [<<Arg>>]
1658
1659 public static short shortToCharToShort(short value) {
1660 // Integral conversion followed by non-widening integral conversion to original type.
1661 return (short) (char) value;
1662 }
1663
1664 /// CHECK-START: int Main.shortToLongToInt(short) instruction_simplifier (before)
1665 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1666 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1667 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Long>>]
1668 /// CHECK-DAG: Return [<<Int>>]
1669
1670 /// CHECK-START: int Main.shortToLongToInt(short) instruction_simplifier (after)
1671 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1672 /// CHECK-DAG: Return [<<Arg>>]
1673
1674 public static int shortToLongToInt(short value) {
1675 // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1676 return (int) (long) value;
1677 }
1678
1679 /// CHECK-START: byte Main.shortToCharToByte(short) instruction_simplifier (before)
1680 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1681 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1682 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Char>>]
1683 /// CHECK-DAG: Return [<<Byte>>]
1684
1685 /// CHECK-START: byte Main.shortToCharToByte(short) instruction_simplifier (after)
1686 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1687 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1688 /// CHECK-DAG: Return [<<Byte>>]
1689
1690 public static byte shortToCharToByte(short value) {
1691 // Integral conversion followed by non-widening integral conversion losing bits
1692 // from the original type. Simplify to use only one conversion.
1693 return (byte) (char) value;
1694 }
1695
1696 /// CHECK-START: java.lang.String Main.shortToCharToBytePrint(short) instruction_simplifier (before)
1697 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1698 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1699 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1700
1701 /// CHECK-START: java.lang.String Main.shortToCharToBytePrint(short) instruction_simplifier (after)
1702 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1703 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1704 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1705
1706 public static String shortToCharToBytePrint(short value) {
1707 // Integral conversion followed by non-widening integral conversion losing bits
1708 // from the original type with an extra use of the intermediate result.
1709 char c = (char) value;
1710 byte b = (byte) c;
1711 return "c=" + ((int) c) + ", b=" + ((int) b); // implicit conversions.
1712 }
1713
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001714 public static void main(String[] args) {
1715 int arg = 123456;
1716
1717 assertLongEquals(Add0(arg), arg);
1718 assertIntEquals(AndAllOnes(arg), arg);
1719 assertLongEquals(Div1(arg), arg);
1720 assertIntEquals(DivN1(arg), -arg);
1721 assertLongEquals(Mul1(arg), arg);
1722 assertIntEquals(MulN1(arg), -arg);
1723 assertLongEquals(MulPowerOfTwo128(arg), (128 * arg));
1724 assertIntEquals(Or0(arg), arg);
1725 assertLongEquals(OrSame(arg), arg);
1726 assertIntEquals(Shl0(arg), arg);
1727 assertLongEquals(Shr0(arg), arg);
1728 assertLongEquals(Sub0(arg), arg);
1729 assertIntEquals(SubAliasNeg(arg), -arg);
1730 assertLongEquals(UShr0(arg), arg);
1731 assertIntEquals(Xor0(arg), arg);
1732 assertIntEquals(XorAllOnes(arg), ~arg);
Alexandre Rames188d4312015-04-09 18:30:21 +01001733 assertIntEquals(AddNegs1(arg, arg + 1), -(arg + arg + 1));
1734 assertIntEquals(AddNegs2(arg, arg + 1), -(arg + arg + 1));
1735 assertLongEquals(AddNegs3(arg, arg + 1), -(2 * arg + 1));
1736 assertLongEquals(AddNeg1(arg, arg + 1), 1);
1737 assertLongEquals(AddNeg2(arg, arg + 1), -1);
1738 assertLongEquals(NegNeg1(arg), arg);
1739 assertIntEquals(NegNeg2(arg), 0);
1740 assertLongEquals(NegNeg3(arg), arg);
1741 assertIntEquals(NegSub1(arg, arg + 1), 1);
1742 assertIntEquals(NegSub2(arg, arg + 1), 1);
1743 assertLongEquals(NotNot1(arg), arg);
1744 assertIntEquals(NotNot2(arg), -1);
1745 assertIntEquals(SubNeg1(arg, arg + 1), -(arg + arg + 1));
1746 assertIntEquals(SubNeg2(arg, arg + 1), -(arg + arg + 1));
1747 assertLongEquals(SubNeg3(arg, arg + 1), -(2 * arg + 1));
David Brazdil0d13fee2015-04-17 14:52:19 +01001748 assertIntEquals(EqualTrueRhs(true), 5);
1749 assertIntEquals(EqualTrueLhs(true), 5);
1750 assertIntEquals(EqualFalseRhs(true), 3);
1751 assertIntEquals(EqualFalseLhs(true), 3);
1752 assertIntEquals(NotEqualTrueRhs(true), 3);
1753 assertIntEquals(NotEqualTrueLhs(true), 3);
1754 assertIntEquals(NotEqualFalseRhs(true), 5);
1755 assertIntEquals(NotEqualFalseLhs(true), 5);
David Brazdil74eb1b22015-12-14 11:44:01 +00001756 assertBooleanEquals(EqualBoolVsIntConst(true), true);
1757 assertBooleanEquals(EqualBoolVsIntConst(true), true);
1758 assertBooleanEquals(NotEqualBoolVsIntConst(false), false);
1759 assertBooleanEquals(NotEqualBoolVsIntConst(false), false);
David Brazdil0d13fee2015-04-17 14:52:19 +01001760 assertBooleanEquals(NotNotBool(true), true);
1761 assertBooleanEquals(NotNotBool(false), false);
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001762 assertFloatEquals(Div2(100.0f), 50.0f);
1763 assertDoubleEquals(Div2(150.0), 75.0);
1764 assertFloatEquals(DivMP25(100.0f), -400.0f);
1765 assertDoubleEquals(DivMP25(150.0), -600.0);
Vladimir Marko452c1b62015-09-25 14:44:17 +01001766 assertIntEquals(UShr28And15(0xc1234567), 0xc);
1767 assertLongEquals(UShr60And15(0xc123456787654321L), 0xcL);
1768 assertIntEquals(UShr28And7(0xc1234567), 0x4);
1769 assertLongEquals(UShr60And7(0xc123456787654321L), 0x4L);
1770 assertIntEquals(Shr24And255(0xc1234567), 0xc1);
1771 assertLongEquals(Shr56And255(0xc123456787654321L), 0xc1L);
1772 assertIntEquals(Shr24And127(0xc1234567), 0x41);
1773 assertLongEquals(Shr56And127(0xc123456787654321L), 0x41L);
Alexandre Rames38db7852015-11-20 15:02:45 +00001774 assertIntEquals(0, mulPow2Plus1(0));
1775 assertIntEquals(9, mulPow2Plus1(1));
1776 assertIntEquals(18, mulPow2Plus1(2));
1777 assertIntEquals(900, mulPow2Plus1(100));
1778 assertIntEquals(111105, mulPow2Plus1(12345));
1779 assertLongEquals(0, mulPow2Minus1(0));
1780 assertLongEquals(31, mulPow2Minus1(1));
1781 assertLongEquals(62, mulPow2Minus1(2));
1782 assertLongEquals(3100, mulPow2Minus1(100));
1783 assertLongEquals(382695, mulPow2Minus1(12345));
Mark Mendellf6529172015-11-17 11:16:56 -05001784
1785 booleanField = false;
1786 assertIntEquals(booleanFieldNotEqualOne(), 54);
1787 assertIntEquals(booleanFieldEqualZero(), 54);
1788 booleanField = true;
1789 assertIntEquals(booleanFieldNotEqualOne(), 13);
1790 assertIntEquals(booleanFieldEqualZero(), 13);
1791 assertIntEquals(intConditionNotEqualOne(6), 54);
1792 assertIntEquals(intConditionNotEqualOne(43), 13);
1793 assertIntEquals(intConditionEqualZero(6), 54);
1794 assertIntEquals(intConditionEqualZero(43), 13);
1795 assertIntEquals(floatConditionNotEqualOne(6.0f), 54);
1796 assertIntEquals(floatConditionNotEqualOne(43.0f), 13);
1797 assertIntEquals(doubleConditionEqualZero(6.0), 54);
1798 assertIntEquals(doubleConditionEqualZero(43.0), 13);
Vladimir Markob52bbde2016-02-12 12:06:05 +00001799
1800 assertIntEquals(intToDoubleToInt(1234567), 1234567);
1801 assertIntEquals(intToDoubleToInt(Integer.MIN_VALUE), Integer.MIN_VALUE);
1802 assertIntEquals(intToDoubleToInt(Integer.MAX_VALUE), Integer.MAX_VALUE);
1803 assertStringEquals(intToDoubleToIntPrint(7654321), "d=7654321.0, i=7654321");
1804 assertIntEquals(byteToDoubleToInt((byte) 12), 12);
1805 assertIntEquals(byteToDoubleToInt(Byte.MIN_VALUE), Byte.MIN_VALUE);
1806 assertIntEquals(byteToDoubleToInt(Byte.MAX_VALUE), Byte.MAX_VALUE);
1807 assertIntEquals(floatToDoubleToInt(11.3f), 11);
1808 assertStringEquals(floatToDoubleToIntPrint(12.25f), "d=12.25, i=12");
1809 assertIntEquals(byteToDoubleToShort((byte) 123), 123);
1810 assertIntEquals(byteToDoubleToShort(Byte.MIN_VALUE), Byte.MIN_VALUE);
1811 assertIntEquals(byteToDoubleToShort(Byte.MAX_VALUE), Byte.MAX_VALUE);
1812 assertIntEquals(charToDoubleToShort((char) 1234), 1234);
1813 assertIntEquals(charToDoubleToShort(Character.MIN_VALUE), Character.MIN_VALUE);
1814 assertIntEquals(charToDoubleToShort(Character.MAX_VALUE), /* sign-extended */ -1);
1815 assertIntEquals(floatToIntToShort(12345.75f), 12345);
1816 assertIntEquals(floatToIntToShort((float)(Short.MIN_VALUE - 1)), Short.MAX_VALUE);
1817 assertIntEquals(floatToIntToShort((float)(Short.MAX_VALUE + 1)), Short.MIN_VALUE);
1818 assertIntEquals(intToFloatToInt(-54321), -54321);
1819 assertDoubleEquals(longToIntToDouble(0x1234567812345678L), (double) 0x12345678);
1820 assertDoubleEquals(longToIntToDouble(Long.MIN_VALUE), 0.0);
1821 assertDoubleEquals(longToIntToDouble(Long.MAX_VALUE), -1.0);
1822 assertLongEquals(longToIntToLong(0x1234567812345678L), 0x0000000012345678L);
1823 assertLongEquals(longToIntToLong(0x1234567887654321L), 0xffffffff87654321L);
1824 assertLongEquals(longToIntToLong(Long.MIN_VALUE), 0L);
1825 assertLongEquals(longToIntToLong(Long.MAX_VALUE), -1L);
1826 assertIntEquals(shortToCharToShort((short) -5678), (short) -5678);
1827 assertIntEquals(shortToCharToShort(Short.MIN_VALUE), Short.MIN_VALUE);
1828 assertIntEquals(shortToCharToShort(Short.MAX_VALUE), Short.MAX_VALUE);
1829 assertIntEquals(shortToLongToInt((short) 5678), 5678);
1830 assertIntEquals(shortToLongToInt(Short.MIN_VALUE), Short.MIN_VALUE);
1831 assertIntEquals(shortToLongToInt(Short.MAX_VALUE), Short.MAX_VALUE);
1832 assertIntEquals(shortToCharToByte((short) 0x1234), 0x34);
1833 assertIntEquals(shortToCharToByte((short) 0x12f0), -0x10);
1834 assertIntEquals(shortToCharToByte(Short.MIN_VALUE), 0);
1835 assertIntEquals(shortToCharToByte(Short.MAX_VALUE), -1);
1836 assertStringEquals(shortToCharToBytePrint((short) 1025), "c=1025, b=1");
1837 assertStringEquals(shortToCharToBytePrint((short) 1023), "c=1023, b=-1");
1838 assertStringEquals(shortToCharToBytePrint((short) -1), "c=65535, b=-1");
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001839 }
Mark Mendellf6529172015-11-17 11:16:56 -05001840
1841 public static boolean booleanField;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001842}