blob: 20858f560f8f365e616397364f6152b8351f5a9c [file] [log] [blame]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000016
David Brazdilf02c3cf2016-02-29 09:14:51 +000017import java.lang.reflect.Method;
18
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000019public class Main {
20
David Brazdil0d13fee2015-04-17 14:52:19 +010021 public static void assertBooleanEquals(boolean expected, boolean result) {
22 if (expected != result) {
23 throw new Error("Expected: " + expected + ", found: " + result);
24 }
25 }
26
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000027 public static void assertIntEquals(int expected, int result) {
28 if (expected != result) {
29 throw new Error("Expected: " + expected + ", found: " + result);
30 }
31 }
32
33 public static void assertLongEquals(long expected, long result) {
34 if (expected != result) {
35 throw new Error("Expected: " + expected + ", found: " + result);
36 }
37 }
38
Nicolas Geoffray0d221842015-04-27 08:53:46 +000039 public static void assertFloatEquals(float expected, float result) {
40 if (expected != result) {
41 throw new Error("Expected: " + expected + ", found: " + result);
42 }
43 }
44
45 public static void assertDoubleEquals(double expected, double result) {
46 if (expected != result) {
47 throw new Error("Expected: " + expected + ", found: " + result);
48 }
49 }
50
Vladimir Markob52bbde2016-02-12 12:06:05 +000051 public static void assertStringEquals(String expected, String result) {
52 if (expected == null ? result != null : !expected.equals(result)) {
53 throw new Error("Expected: " + expected + ", found: " + result);
54 }
55 }
56
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000057 /**
58 * Tiny programs exercising optimizations of arithmetic identities.
59 */
60
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010061 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +010062 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
63 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
64 /// CHECK-DAG: <<Add:j\d+>> Add [<<Const0>>,<<Arg>>]
65 /// CHECK-DAG: Return [<<Add>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000066
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010067 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +010068 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
69 /// CHECK-DAG: Return [<<Arg>>]
David Brazdil0d13fee2015-04-17 14:52:19 +010070
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010071 /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +010072 /// CHECK-NOT: Add
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000073
Alexandre Ramesa975dcc2016-06-27 11:13:34 +010074 public static long $noinline$Add0(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +000075 return 0 + arg;
76 }
77
Anton Kirilove14dc862016-05-13 17:56:15 +010078 /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (before)
79 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
80 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
81 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
82 /// CHECK-DAG: <<ConstM3:i\d+>> IntConstant -3
83 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
84 /// CHECK-DAG: <<Add1:i\d+>> Add [<<ArgValue>>,<<Const1>>]
85 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Add1>>,<<Const2>>]
86 /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add2>>,<<ConstM3>>]
87 /// CHECK-DAG: <<Add4:i\d+>> Add [<<Add3>>,<<Const4>>]
88 /// CHECK-DAG: Return [<<Add4>>]
89
90 /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (after)
91 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
92 /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4
93 /// CHECK-DAG: <<Add:i\d+>> Add [<<ArgValue>>,<<Const4>>]
94 /// CHECK-DAG: Return [<<Add>>]
95
96 public static int $noinline$AddAddSubAddConst(int arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +010097 return arg + 1 + 2 - 3 + 4;
98 }
99
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100100 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100101 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
102 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
103 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<ConstF>>]
104 /// CHECK-DAG: Return [<<And>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000105
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100106 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100107 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
108 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000109
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100110 /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100111 /// CHECK-NOT: And
Alexandre Rames74417692015-04-09 15:21:41 +0100112
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100113 public static int $noinline$AndAllOnes(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000114 return arg & -1;
115 }
116
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100117 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100118 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
119 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
120 /// CHECK-DAG: <<Const15:i\d+>> IntConstant 15
121 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
122 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const15>>]
123 /// CHECK-DAG: Return [<<And>>]
124
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100125 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100126 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
127 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
128 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
129 /// CHECK-DAG: Return [<<UShr>>]
130
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100131 /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100132 /// CHECK-NOT: And
133
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100134 public static int $noinline$UShr28And15(int arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100135 return (arg >>> 28) & 15;
136 }
137
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100138 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100139 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
140 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
141 /// CHECK-DAG: <<Const15:j\d+>> LongConstant 15
142 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
143 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const15>>]
144 /// CHECK-DAG: Return [<<And>>]
145
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100146 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100147 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
148 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
149 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
150 /// CHECK-DAG: Return [<<UShr>>]
151
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100152 /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100153 /// CHECK-NOT: And
154
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100155 public static long $noinline$UShr60And15(long arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100156 return (arg >>> 60) & 15;
157 }
158
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100159 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100160 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
161 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
162 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
163 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
164 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
165 /// CHECK-DAG: Return [<<And>>]
166
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100167 /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100168 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
169 /// CHECK-DAG: <<Const28:i\d+>> IntConstant 28
170 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
171 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const28>>]
172 /// CHECK-DAG: <<And:i\d+>> And [<<UShr>>,<<Const7>>]
173 /// CHECK-DAG: Return [<<And>>]
174
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100175 public static int $noinline$UShr28And7(int arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100176 return (arg >>> 28) & 7;
177 }
178
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100179 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100180 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
181 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
182 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
183 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
184 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
185 /// CHECK-DAG: Return [<<And>>]
186
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100187 /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100188 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
189 /// CHECK-DAG: <<Const60:i\d+>> IntConstant 60
190 /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7
191 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const60>>]
192 /// CHECK-DAG: <<And:j\d+>> And [<<UShr>>,<<Const7>>]
193 /// CHECK-DAG: Return [<<And>>]
194
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100195 public static long $noinline$UShr60And7(long arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100196 return (arg >>> 60) & 7;
197 }
198
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100199 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100200 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
201 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
202 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
203 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
204 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const255>>]
205 /// CHECK-DAG: Return [<<And>>]
206
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100207 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100208 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
209 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
210 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Arg>>,<<Const24>>]
211 /// CHECK-DAG: Return [<<UShr>>]
212
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100213 /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100214 /// CHECK-NOT: Shr
215 /// CHECK-NOT: And
216
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100217 public static int $noinline$Shr24And255(int arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100218 return (arg >> 24) & 255;
219 }
220
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100221 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100222 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
223 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
224 /// CHECK-DAG: <<Const255:j\d+>> LongConstant 255
225 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
226 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const255>>]
227 /// CHECK-DAG: Return [<<And>>]
228
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100229 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100230 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
231 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
232 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const56>>]
233 /// CHECK-DAG: Return [<<UShr>>]
234
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100235 /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100236 /// CHECK-NOT: Shr
237 /// CHECK-NOT: And
238
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100239 public static long $noinline$Shr56And255(long arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100240 return (arg >> 56) & 255;
241 }
242
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100243 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100244 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
245 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
246 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
247 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
248 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
249 /// CHECK-DAG: Return [<<And>>]
250
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100251 /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100252 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
253 /// CHECK-DAG: <<Const24:i\d+>> IntConstant 24
254 /// CHECK-DAG: <<Const127:i\d+>> IntConstant 127
255 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Arg>>,<<Const24>>]
256 /// CHECK-DAG: <<And:i\d+>> And [<<Shr>>,<<Const127>>]
257 /// CHECK-DAG: Return [<<And>>]
258
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100259 public static int $noinline$Shr24And127(int arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100260 return (arg >> 24) & 127;
261 }
262
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100263 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (before)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100264 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
265 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
266 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
267 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
268 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
269 /// CHECK-DAG: Return [<<And>>]
270
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100271 /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (after)
Vladimir Marko452c1b62015-09-25 14:44:17 +0100272 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
273 /// CHECK-DAG: <<Const56:i\d+>> IntConstant 56
274 /// CHECK-DAG: <<Const127:j\d+>> LongConstant 127
275 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const56>>]
276 /// CHECK-DAG: <<And:j\d+>> And [<<Shr>>,<<Const127>>]
277 /// CHECK-DAG: Return [<<And>>]
278
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100279 public static long $noinline$Shr56And127(long arg) {
Vladimir Marko452c1b62015-09-25 14:44:17 +0100280 return (arg >> 56) & 127;
281 }
282
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100283 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100284 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
285 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
286 /// CHECK-DAG: <<Div:j\d+>> Div [<<Arg>>,<<Const1>>]
287 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000288
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100289 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100290 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
291 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000292
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100293 /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100294 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100295
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100296 public static long $noinline$Div1(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000297 return arg / 1;
298 }
299
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100300 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100301 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
302 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
303 /// CHECK-DAG: <<Div:i\d+>> Div [<<Arg>>,<<ConstN1>>]
304 /// CHECK-DAG: Return [<<Div>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000305
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100306 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100307 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
308 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
309 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000310
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100311 /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100312 /// CHECK-NOT: Div
Alexandre Rames74417692015-04-09 15:21:41 +0100313
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100314 public static int $noinline$DivN1(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000315 return arg / -1;
316 }
317
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100318 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100319 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
320 /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1
David Brazdil57e863c2016-01-11 10:27:13 +0000321 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const1>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100322 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000323
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100324 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100325 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
326 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000327
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100328 /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100329 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100330
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100331 public static long $noinline$Mul1(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000332 return arg * 1;
333 }
334
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100335 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100336 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
337 /// CHECK-DAG: <<ConstN1:i\d+>> IntConstant -1
338 /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Arg>>,<<ConstN1>>]
339 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000340
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100341 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100342 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
343 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
344 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000345
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100346 /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100347 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100348
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100349 public static int $noinline$MulN1(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000350 return arg * -1;
351 }
352
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100353 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100354 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
355 /// CHECK-DAG: <<Const128:j\d+>> LongConstant 128
David Brazdil57e863c2016-01-11 10:27:13 +0000356 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const128>>,<<Arg>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100357 /// CHECK-DAG: Return [<<Mul>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000358
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100359 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100360 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
361 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
362 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Arg>>,<<Const7>>]
363 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000364
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100365 /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100366 /// CHECK-NOT: Mul
Alexandre Rames74417692015-04-09 15:21:41 +0100367
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100368 public static long $noinline$MulPowerOfTwo128(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000369 return arg * 128;
370 }
371
Anton Kirilove14dc862016-05-13 17:56:15 +0100372 /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (before)
373 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
374 /// CHECK-DAG: <<Const10:j\d+>> LongConstant 10
375 /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11
376 /// CHECK-DAG: <<Const12:j\d+>> LongConstant 12
377 /// CHECK-DAG: <<Mul1:j\d+>> Mul [<<Const10>>,<<ArgValue>>]
378 /// CHECK-DAG: <<Mul2:j\d+>> Mul [<<Mul1>>,<<Const11>>]
379 /// CHECK-DAG: <<Mul3:j\d+>> Mul [<<Mul2>>,<<Const12>>]
380 /// CHECK-DAG: Return [<<Mul3>>]
381
382 /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (after)
383 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
384 /// CHECK-DAG: <<Const1320:j\d+>> LongConstant 1320
385 /// CHECK-DAG: <<Mul:j\d+>> Mul [<<ArgValue>>,<<Const1320>>]
386 /// CHECK-DAG: Return [<<Mul>>]
387
388 public static long $noinline$MulMulMulConst(long arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +0100389 return 10 * arg * 11 * 12;
390 }
391
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100392 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100393 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
394 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
395 /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<Const0>>]
396 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000397
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100398 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100399 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
400 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000401
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100402 /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100403 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100404
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100405 public static int $noinline$Or0(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000406 return arg | 0;
407 }
408
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100409 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100410 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
411 /// CHECK-DAG: <<Or:j\d+>> Or [<<Arg>>,<<Arg>>]
412 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000413
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100414 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100415 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
416 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000417
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100418 /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100419 /// CHECK-NOT: Or
Alexandre Rames74417692015-04-09 15:21:41 +0100420
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100421 public static long $noinline$OrSame(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000422 return arg | arg;
423 }
424
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100425 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100426 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
427 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
428 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Arg>>,<<Const0>>]
429 /// CHECK-DAG: Return [<<Shl>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000430
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100431 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100432 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
433 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000434
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100435 /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100436 /// CHECK-NOT: Shl
Alexandre Rames74417692015-04-09 15:21:41 +0100437
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100438 public static int $noinline$Shl0(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000439 return arg << 0;
440 }
441
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100442 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100443 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
444 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
445 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const0>>]
446 /// CHECK-DAG: Return [<<Shr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000447
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100448 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100449 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
450 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000451
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100452 /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100453 /// CHECK-NOT: Shr
Alexandre Rames74417692015-04-09 15:21:41 +0100454
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100455 public static long $noinline$Shr0(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000456 return arg >> 0;
457 }
458
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100459 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (before)
Vladimir Marko164306e2016-03-15 14:57:32 +0000460 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
461 /// CHECK-DAG: <<Const64:i\d+>> IntConstant 64
462 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Arg>>,<<Const64>>]
463 /// CHECK-DAG: Return [<<Shr>>]
464
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100465 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
Vladimir Marko164306e2016-03-15 14:57:32 +0000466 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
467 /// CHECK-DAG: Return [<<Arg>>]
468
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100469 /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
Vladimir Marko164306e2016-03-15 14:57:32 +0000470 /// CHECK-NOT: Shr
471
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100472 public static long $noinline$Shr64(long arg) {
Vladimir Marko164306e2016-03-15 14:57:32 +0000473 return arg >> 64;
474 }
475
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100476 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100477 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
478 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
479 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Const0>>]
480 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000481
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100482 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100483 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
484 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000485
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100486 /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100487 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100488
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100489 public static long $noinline$Sub0(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000490 return arg - 0;
491 }
492
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100493 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100494 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
495 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
496 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const0>>,<<Arg>>]
497 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000498
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100499 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100500 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
501 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg>>]
502 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000503
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100504 /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100505 /// CHECK-NOT: Sub
Alexandre Rames74417692015-04-09 15:21:41 +0100506
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100507 public static int $noinline$SubAliasNeg(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000508 return 0 - arg;
509 }
510
Anton Kirilove14dc862016-05-13 17:56:15 +0100511 /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (before)
512 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
513 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
514 /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6
515 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<ArgValue>>]
516 /// CHECK-DAG: <<Add:i\d+>> Add [<<Sub>>,<<Const6>>]
517 /// CHECK-DAG: Return [<<Add>>]
518
519 /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (after)
520 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
521 /// CHECK-DAG: <<Const11:i\d+>> IntConstant 11
522 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const11>>,<<ArgValue>>]
523 /// CHECK-DAG: Return [<<Sub>>]
524
525 public static int $noinline$SubAddConst1(int arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +0100526 return 5 - arg + 6;
527 }
528
529 /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (before)
530 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
531 /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14
532 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
533 /// CHECK-DAG: <<Add:i\d+>> Add [<<ArgValue>>,<<Const13>>]
534 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const14>>,<<Add>>]
535 /// CHECK-DAG: Return [<<Sub>>]
536
537 /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (after)
538 /// CHECK-DAG: <<ArgValue:i\d+>> ParameterValue
539 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
540 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const1>>,<<ArgValue>>]
541 /// CHECK-DAG: Return [<<Sub>>]
542
543 public static int $noinline$SubAddConst2(int arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +0100544 return 14 - (arg + 13);
545 }
546
547 /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (before)
548 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
549 /// CHECK-DAG: <<Const17:j\d+>> LongConstant 17
550 /// CHECK-DAG: <<Const18:j\d+>> LongConstant 18
551 /// CHECK-DAG: <<Sub1:j\d+>> Sub [<<Const18>>,<<ArgValue>>]
552 /// CHECK-DAG: <<Sub2:j\d+>> Sub [<<Const17>>,<<Sub1>>]
553 /// CHECK-DAG: Return [<<Sub2>>]
554
555 /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (after)
556 /// CHECK-DAG: <<ArgValue:j\d+>> ParameterValue
557 /// CHECK-DAG: <<ConstM1:j\d+>> LongConstant -1
558 /// CHECK-DAG: <<Add:j\d+>> Add [<<ArgValue>>,<<ConstM1>>]
559 /// CHECK-DAG: Return [<<Add>>]
560
561 public static long $noinline$SubSubConst(long arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +0100562 return 17 - (18 - arg);
563 }
564
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100565 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100566 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
567 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
568 /// CHECK-DAG: <<UShr:j\d+>> UShr [<<Arg>>,<<Const0>>]
569 /// CHECK-DAG: Return [<<UShr>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000570
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100571 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100572 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
573 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000574
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100575 /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100576 /// CHECK-NOT: UShr
Alexandre Rames74417692015-04-09 15:21:41 +0100577
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100578 public static long $noinline$UShr0(long arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000579 return arg >>> 0;
580 }
581
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100582 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100583 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
584 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
585 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Const0>>]
586 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000587
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100588 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100589 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
590 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000591
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100592 /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100593 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100594
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100595 public static int $noinline$Xor0(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000596 return arg ^ 0;
597 }
598
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100599 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100600 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
601 /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1
602 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<ConstF>>]
603 /// CHECK-DAG: Return [<<Xor>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000604
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100605 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100606 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
607 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
608 /// CHECK-DAG: Return [<<Not>>]
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000609
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100610 /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100611 /// CHECK-NOT: Xor
Alexandre Rames74417692015-04-09 15:21:41 +0100612
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100613 public static int $noinline$XorAllOnes(int arg) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +0000614 return arg ^ -1;
615 }
616
Alexandre Rames188d4312015-04-09 18:30:21 +0100617 /**
618 * Test that addition or subtraction operation with both inputs negated are
619 * optimized to use a single negation after the operation.
620 * The transformation tested is implemented in
621 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
622 */
623
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100624 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100625 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
626 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
627 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
628 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
629 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
630 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100631
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100632 /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100633 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
634 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
635 /// CHECK-NOT: Neg
636 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
637 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
638 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100639
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100640 public static int $noinline$AddNegs1(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100641 return -arg1 + -arg2;
642 }
643
644 /**
645 * This is similar to the test-case AddNegs1, but the negations have
646 * multiple uses.
647 * The transformation tested is implemented in
648 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
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
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100655 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100656 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
657 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
658 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
659 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
660 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
661 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
662 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
663 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100664
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100665 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100666 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
667 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
668 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
669 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
670 /// CHECK-DAG: <<Add1:i\d+>> Add [<<Neg1>>,<<Neg2>>]
671 /// CHECK-DAG: <<Add2:i\d+>> Add [<<Neg1>>,<<Neg2>>]
672 /// CHECK-NOT: Neg
673 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add1>>,<<Add2>>]
674 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100675
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100676 /// CHECK-START: int Main.$noinline$AddNegs2(int, int) GVN (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100677 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
678 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
679 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg1>>]
680 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Arg2>>]
681 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg1>>,<<Neg2>>]
682 /// CHECK-DAG: <<Or:i\d+>> Or [<<Add>>,<<Add>>]
683 /// CHECK-DAG: Return [<<Or>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100684
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100685 public static int $noinline$AddNegs2(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100686 int temp1 = -arg1;
687 int temp2 = -arg2;
688 return (temp1 + temp2) | (temp1 + temp2);
689 }
690
691 /**
692 * This follows test-cases AddNegs1 and AddNegs2.
693 * The transformation tested is implemented in
694 * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
695 * The optimization should not happen if it moves an additional instruction in
696 * the loop.
697 */
698
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100699 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100700 // -------------- Arguments and initial negation operations.
701 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
702 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
703 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
704 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
705 /// CHECK: Goto
706 // -------------- Loop
707 /// CHECK: SuspendCheck
708 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
709 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100710
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100711 /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100712 // -------------- Arguments and initial negation operations.
713 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
714 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
715 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg1>>]
716 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Arg2>>]
717 /// CHECK: Goto
718 // -------------- Loop
719 /// CHECK: SuspendCheck
720 /// CHECK: <<Add:j\d+>> Add [<<Neg1>>,<<Neg2>>]
721 /// CHECK-NOT: Neg
722 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +0100723
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100724 public static long $noinline$AddNegs3(long arg1, long arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100725 long res = 0;
726 long n_arg1 = -arg1;
727 long n_arg2 = -arg2;
728 for (long i = 0; i < 1; i++) {
729 res += n_arg1 + n_arg2 + i;
730 }
731 return res;
732 }
733
734 /**
735 * Test the simplification of an addition with a negated argument into a
736 * subtraction.
737 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
738 */
739
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100740 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100741 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
742 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
743 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
744 /// CHECK-DAG: <<Add:j\d+>> Add [<<Neg>>,<<Arg2>>]
745 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100746
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100747 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100748 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
749 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
750 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg2>>,<<Arg1>>]
751 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100752
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100753 /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100754 /// CHECK-NOT: Neg
755 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100756
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100757 public static long $noinline$AddNeg1(long arg1, long arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100758 return -arg1 + arg2;
759 }
760
761 /**
762 * This is similar to the test-case AddNeg1, but the negation has two uses.
763 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
764 * The current code won't perform the previous optimization. The
765 * transformations do not look at other uses of their inputs. As they don't
766 * know what will happen with other uses, they do not take the risk of
767 * increasing the register pressure by creating or extending live ranges.
768 */
769
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100770 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100771 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
772 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
773 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
774 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
775 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
776 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
777 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100778
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100779 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100780 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
781 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
782 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg2>>]
783 /// CHECK-DAG: <<Add1:j\d+>> Add [<<Arg1>>,<<Neg>>]
784 /// CHECK-DAG: <<Add2:j\d+>> Add [<<Arg1>>,<<Neg>>]
785 /// CHECK-DAG: <<Res:j\d+>> Or [<<Add1>>,<<Add2>>]
786 /// CHECK-DAG: Return [<<Res>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100787
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100788 /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100789 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100790
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100791 public static long $noinline$AddNeg2(long arg1, long arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100792 long temp = -arg2;
793 return (arg1 + temp) | (arg1 + temp);
794 }
795
796 /**
797 * Test simplification of the `-(-var)` pattern.
798 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
799 */
800
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100801 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100802 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
803 /// CHECK-DAG: <<Neg1:j\d+>> Neg [<<Arg>>]
804 /// CHECK-DAG: <<Neg2:j\d+>> Neg [<<Neg1>>]
805 /// CHECK-DAG: Return [<<Neg2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100806
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100807 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100808 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
809 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100810
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100811 /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100812 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100813
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100814 public static long $noinline$NegNeg1(long arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100815 return -(-arg);
816 }
817
818 /**
819 * Test 'multi-step' simplification, where a first transformation yields a
820 * new simplification possibility for the current instruction.
821 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
822 * and in `InstructionSimplifierVisitor::VisitAdd`.
823 */
824
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100825 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100826 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
827 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Arg>>]
828 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Neg1>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000829 /// CHECK-DAG: <<Add:i\d+>> Add [<<Neg2>>,<<Neg1>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100830 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100831
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100832 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100833 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
834 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg>>,<<Arg>>]
835 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100836
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100837 /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100838 /// CHECK-NOT: Neg
839 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +0100840
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -0700841 /// CHECK-START: int Main.$noinline$NegNeg2(int) constant_folding$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100842 /// CHECK: <<Const0:i\d+>> IntConstant 0
843 /// CHECK-NOT: Neg
844 /// CHECK-NOT: Add
845 /// CHECK: Return [<<Const0>>]
Alexandre Ramesb2a58472015-04-17 14:35:18 +0100846
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100847 public static int $noinline$NegNeg2(int arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100848 int temp = -arg;
849 return temp + -temp;
850 }
851
852 /**
853 * Test another 'multi-step' simplification, where a first transformation
854 * yields a new simplification possibility for the current instruction.
855 * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
856 * and in `InstructionSimplifierVisitor::VisitSub`.
857 */
858
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100859 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100860 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
861 /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0
862 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg>>]
863 /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const0>>,<<Neg>>]
864 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100865
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100866 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100867 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
868 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100869
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100870 /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100871 /// CHECK-NOT: Neg
872 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +0100873
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100874 public static long $noinline$NegNeg3(long arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100875 return 0 - -arg;
876 }
877
878 /**
879 * Test that a negated subtraction is simplified to a subtraction with its
880 * arguments reversed.
881 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
882 */
883
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100884 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100885 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
886 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
887 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
888 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Sub>>]
889 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100890
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100891 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100892 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
893 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
894 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg2>>,<<Arg1>>]
895 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100896
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100897 /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100898 /// CHECK-NOT: Neg
Alexandre Rames188d4312015-04-09 18:30:21 +0100899
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100900 public static int $noinline$NegSub1(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100901 return -(arg1 - arg2);
902 }
903
904 /**
905 * This is similar to the test-case NegSub1, but the subtraction has
906 * multiple uses.
907 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
908 * The current code won't perform the previous optimization. The
909 * transformations do not look at other uses of their inputs. As they don't
910 * know what will happen with other uses, they do not take the risk of
911 * increasing the register pressure by creating or extending live ranges.
912 */
913
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100914 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100915 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
916 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
917 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
918 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
919 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
920 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
921 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100922
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100923 /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100924 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
925 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
926 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Arg1>>,<<Arg2>>]
927 /// CHECK-DAG: <<Neg1:i\d+>> Neg [<<Sub>>]
928 /// CHECK-DAG: <<Neg2:i\d+>> Neg [<<Sub>>]
929 /// CHECK-DAG: <<Or:i\d+>> Or [<<Neg1>>,<<Neg2>>]
930 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100931
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100932 public static int $noinline$NegSub2(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100933 int temp = arg1 - arg2;
934 return -temp | -temp;
935 }
936
937 /**
938 * Test simplification of the `~~var` pattern.
939 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`.
940 */
941
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100942 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (before)
Igor Murashkin42691732017-06-26 15:57:31 -0700943 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
944 /// CHECK-DAG: <<ConstNeg1:j\d+>> LongConstant -1
945 /// CHECK-DAG: <<Not1:j\d+>> Xor [<<Arg>>,<<ConstNeg1>>]
946 /// CHECK-DAG: <<Not2:j\d+>> Xor [<<Not1>>,<<ConstNeg1>>]
947 /// CHECK-DAG: Return [<<Not2>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100948
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100949 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100950 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
951 /// CHECK-DAG: Return [<<Arg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100952
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100953 /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
Igor Murashkin42691732017-06-26 15:57:31 -0700954 /// CHECK-NOT: Xor
Alexandre Rames188d4312015-04-09 18:30:21 +0100955
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100956 public static long $noinline$NotNot1(long arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100957 return ~~arg;
958 }
959
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100960 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (before)
Igor Murashkin42691732017-06-26 15:57:31 -0700961 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
962 /// CHECK-DAG: <<ConstNeg1:i\d+>> IntConstant -1
963 /// CHECK-DAG: <<Not1:i\d+>> Xor [<<Arg>>,<<ConstNeg1>>]
964 /// CHECK-DAG: <<Not2:i\d+>> Xor [<<Not1>>,<<ConstNeg1>>]
965 /// CHECK-DAG: <<Add:i\d+>> Add [<<Not2>>,<<Not1>>]
966 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100967
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100968 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100969 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
970 /// CHECK-DAG: <<Not:i\d+>> Not [<<Arg>>]
David Brazdil57e863c2016-01-11 10:27:13 +0000971 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg>>,<<Not>>]
David Brazdila06d66a2015-05-28 11:14:54 +0100972 /// CHECK-DAG: Return [<<Add>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100973
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100974 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
David Brazdilf02c3cf2016-02-29 09:14:51 +0000975 /// CHECK: Not
976 /// CHECK-NOT: Not
Alexandre Rames188d4312015-04-09 18:30:21 +0100977
Igor Murashkin42691732017-06-26 15:57:31 -0700978 /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
979 /// CHECK-NOT: Xor
980
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100981 public static int $noinline$NotNot2(int arg) {
Alexandre Rames188d4312015-04-09 18:30:21 +0100982 int temp = ~arg;
983 return temp + ~temp;
984 }
985
986 /**
987 * Test the simplification of a subtraction with a negated argument.
988 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
989 */
990
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100991 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100992 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
993 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
994 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
995 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Neg>>,<<Arg2>>]
996 /// CHECK-DAG: Return [<<Sub>>]
Alexandre Rames188d4312015-04-09 18:30:21 +0100997
Alexandre Ramesa975dcc2016-06-27 11:13:34 +0100998 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100999 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1000 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1001 /// CHECK-DAG: <<Add:i\d+>> Add [<<Arg1>>,<<Arg2>>]
1002 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Add>>]
1003 /// CHECK-DAG: Return [<<Neg>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001004
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001005 /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001006 /// CHECK-NOT: Sub
Alexandre Rames188d4312015-04-09 18:30:21 +01001007
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001008 public static int $noinline$SubNeg1(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +01001009 return -arg1 - arg2;
1010 }
1011
1012 /**
1013 * This is similar to the test-case SubNeg1, but the negation has
1014 * multiple uses.
1015 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1016 * The current code won't perform the previous optimization. The
1017 * transformations do not look at other uses of their inputs. As they don't
1018 * know what will happen with other uses, they do not take the risk of
1019 * increasing the register pressure by creating or extending live ranges.
1020 */
1021
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001022 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001023 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1024 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1025 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1026 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1027 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1028 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
1029 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001030
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001031 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001032 /// CHECK-DAG: <<Arg1:i\d+>> ParameterValue
1033 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
1034 /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Arg1>>]
1035 /// CHECK-DAG: <<Sub1:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1036 /// CHECK-DAG: <<Sub2:i\d+>> Sub [<<Neg>>,<<Arg2>>]
1037 /// CHECK-DAG: <<Or:i\d+>> Or [<<Sub1>>,<<Sub2>>]
1038 /// CHECK-DAG: Return [<<Or>>]
Alexandre Rames188d4312015-04-09 18:30:21 +01001039
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001040 /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001041 /// CHECK-NOT: Add
Alexandre Rames188d4312015-04-09 18:30:21 +01001042
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001043 public static int $noinline$SubNeg2(int arg1, int arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +01001044 int temp = -arg1;
1045 return (temp - arg2) | (temp - arg2);
1046 }
1047
1048 /**
1049 * This follows test-cases SubNeg1 and SubNeg2.
1050 * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1051 * The optimization should not happen if it moves an additional instruction in
1052 * the loop.
1053 */
1054
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001055 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001056 // -------------- Arguments and initial negation operation.
1057 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
1058 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
1059 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1060 /// CHECK: Goto
1061 // -------------- Loop
1062 /// CHECK: SuspendCheck
1063 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1064 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001065
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001066 /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001067 // -------------- Arguments and initial negation operation.
1068 /// CHECK-DAG: <<Arg1:j\d+>> ParameterValue
1069 /// CHECK-DAG: <<Arg2:j\d+>> ParameterValue
1070 /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Arg1>>]
1071 /// CHECK-DAG: Goto
1072 // -------------- Loop
1073 /// CHECK: SuspendCheck
1074 /// CHECK: <<Sub:j\d+>> Sub [<<Neg>>,<<Arg2>>]
1075 /// CHECK-NOT: Neg
1076 /// CHECK: Goto
Alexandre Rames188d4312015-04-09 18:30:21 +01001077
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001078 public static long $noinline$SubNeg3(long arg1, long arg2) {
Alexandre Rames188d4312015-04-09 18:30:21 +01001079 long res = 0;
1080 long temp = -arg1;
1081 for (long i = 0; i < 1; i++) {
1082 res += temp - arg2 - i;
1083 }
1084 return res;
1085 }
1086
Aart Bik639cc8c2016-10-18 13:03:31 -07001087 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001088 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001089 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1090 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001091 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001092 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1093 /// CHECK-DAG: <<Cond:z\d+>> Equal [<<NotArg>>,<<Const2>>]
1094 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1095 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001096
Aart Bik639cc8c2016-10-18 13:03:31 -07001097 /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001098 /// CHECK-DAG: <<True:i\d+>> IntConstant 1
1099 /// CHECK-DAG: Return [<<True>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001100
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001101 public static boolean $noinline$EqualBoolVsIntConst(boolean arg) {
Nicolas Geoffraydac9b192016-07-15 10:46:17 +01001102 // Make calls that will be inlined to make sure the instruction simplifier
1103 // sees the simplification (dead code elimination will also try to simplify it).
1104 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) != 2;
1105 }
1106
1107 public static int $inline$ReturnArg(int arg) {
1108 return arg;
David Brazdil1e9ec052015-06-22 10:26:45 +01001109 }
1110
Aart Bik639cc8c2016-10-18 13:03:31 -07001111 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before)
David Brazdil1e9ec052015-06-22 10:26:45 +01001112 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001113 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1114 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil1e9ec052015-06-22 10:26:45 +01001115 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
David Brazdil74eb1b22015-12-14 11:44:01 +00001116 /// CHECK-DAG: <<NotArg:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1117 /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<NotArg>>,<<Const2>>]
1118 /// CHECK-DAG: <<NotCond:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
1119 /// CHECK-DAG: Return [<<NotCond>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001120
Aart Bik639cc8c2016-10-18 13:03:31 -07001121 /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001122 /// CHECK-DAG: <<False:i\d+>> IntConstant 0
1123 /// CHECK-DAG: Return [<<False>>]
David Brazdil1e9ec052015-06-22 10:26:45 +01001124
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001125 public static boolean $noinline$NotEqualBoolVsIntConst(boolean arg) {
Nicolas Geoffraydac9b192016-07-15 10:46:17 +01001126 // Make calls that will be inlined to make sure the instruction simplifier
1127 // sees the simplification (dead code elimination will also try to simplify it).
1128 return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) == 2;
David Brazdil1e9ec052015-06-22 10:26:45 +01001129 }
1130
David Brazdil0d13fee2015-04-17 14:52:19 +01001131 /*
1132 * Test simplification of double Boolean negation. Note that sometimes
1133 * both negations can be removed but we only expect the simplifier to
1134 * remove the second.
1135 */
1136
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001137 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (before)
1138 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001139 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 0
1140 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect method_name:Main.NegateValue
1141 /// CHECK-DAG: <<NotResult:z\d+>> NotEqual [<<Result>>,<<Const1>>]
1142 /// CHECK-DAG: If [<<NotResult>>]
1143
1144 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after)
1145 /// CHECK-NOT: NotEqual
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001146
1147 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after)
1148 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001149 /// CHECK-DAG: <<Result:z\d+>> InvokeStaticOrDirect method_name:Main.NegateValue
1150 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1151 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1152 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>]
1153 /// CHECK-DAG: Return [<<Phi>>]
Sebastien Hertz9837caf2016-08-01 11:09:50 +02001154
Aart Bik639cc8c2016-10-18 13:03:31 -07001155 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001156 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001157 /// CHECK-NOT: BooleanNot [<<Arg>>]
1158 /// CHECK-NOT: Phi
1159
1160 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before)
1161 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
1162 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
1163 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1164 /// CHECK-DAG: <<Sel:i\d+>> Select [<<Const1>>,<<Const0>>,<<Arg>>]
1165 /// CHECK-DAG: <<Sel2:i\d+>> Select [<<Const1>>,<<Const0>>,<<Sel>>]
1166 /// CHECK-DAG: Return [<<Sel2>>]
David Brazdil0d13fee2015-04-17 14:52:19 +01001167
Aart Bik639cc8c2016-10-18 13:03:31 -07001168 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001169 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001170 /// CHECK: BooleanNot [<<Arg>>]
1171 /// CHECK-NEXT: Goto
1172
1173 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after)
1174 /// CHECK-NOT: Select
David Brazdil0d13fee2015-04-17 14:52:19 +01001175
Sebastien Hertz55418e12016-09-23 16:51:42 +02001176 /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) dead_code_elimination$final (after)
1177 /// CHECK-DAG: <<Arg:z\d+>> ParameterValue
Igor Murashkin42691732017-06-26 15:57:31 -07001178 /// CHECK-NOT: BooleanNot [<<Arg>>]
Sebastien Hertz55418e12016-09-23 16:51:42 +02001179 /// CHECK-DAG: Return [<<Arg>>]
1180
David Brazdil769c9e52015-04-27 13:54:09 +01001181 public static boolean NegateValue(boolean arg) {
1182 return !arg;
1183 }
1184
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001185 public static boolean $noinline$NotNotBool(boolean arg) {
David Brazdil769c9e52015-04-27 13:54:09 +01001186 return !(NegateValue(arg));
David Brazdil0d13fee2015-04-17 14:52:19 +01001187 }
1188
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001189 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001190 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1191 /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2
1192 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<Const2>>]
1193 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001194
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001195 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001196 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1197 /// CHECK-DAG: <<ConstP5:f\d+>> FloatConstant 0.5
1198 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstP5>>]
1199 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001200
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001201 /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001202 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001203
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001204 public static float $noinline$Div2(float arg) {
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001205 return arg / 2.0f;
1206 }
1207
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001208 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001209 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1210 /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2
1211 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<Const2>>]
1212 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001213
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001214 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001215 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1216 /// CHECK-DAG: <<ConstP5:d\d+>> DoubleConstant 0.5
1217 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstP5>>]
1218 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001219
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001220 /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001221 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001222 public static double $noinline$Div2(double arg) {
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001223 return arg / 2.0;
1224 }
1225
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001226 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001227 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1228 /// CHECK-DAG: <<ConstMP25:f\d+>> FloatConstant -0.25
1229 /// CHECK-DAG: <<Div:f\d+>> Div [<<Arg>>,<<ConstMP25>>]
1230 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001231
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001232 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001233 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1234 /// CHECK-DAG: <<ConstM4:f\d+>> FloatConstant -4
1235 /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Arg>>,<<ConstM4>>]
1236 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001237
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001238 /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001239 /// CHECK-NOT: Div
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001240
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001241 public static float $noinline$DivMP25(float arg) {
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001242 return arg / -0.25f;
1243 }
1244
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001245 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (before)
David Brazdila06d66a2015-05-28 11:14:54 +01001246 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1247 /// CHECK-DAG: <<ConstMP25:d\d+>> DoubleConstant -0.25
1248 /// CHECK-DAG: <<Div:d\d+>> Div [<<Arg>>,<<ConstMP25>>]
1249 /// CHECK-DAG: Return [<<Div>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001250
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001251 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001252 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1253 /// CHECK-DAG: <<ConstM4:d\d+>> DoubleConstant -4
1254 /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Arg>>,<<ConstM4>>]
1255 /// CHECK-DAG: Return [<<Mul>>]
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001256
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001257 /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
David Brazdila06d66a2015-05-28 11:14:54 +01001258 /// CHECK-NOT: Div
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001259 public static double $noinline$DivMP25(double arg) {
Nicolas Geoffray0d221842015-04-27 08:53:46 +00001260 return arg / -0.25f;
1261 }
1262
Alexandre Rames38db7852015-11-20 15:02:45 +00001263 /**
1264 * Test strength reduction of factors of the form (2^n + 1).
1265 */
1266
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001267 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001268 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1269 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
1270 /// CHECK: Mul [<<Arg>>,<<Const9>>]
1271
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001272 /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001273 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1274 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1275 /// CHECK: <<Shift:i\d+>> Shl [<<Arg>>,<<Const3>>]
1276 /// CHECK-NEXT: Add [<<Arg>>,<<Shift>>]
1277
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001278 public static int $noinline$mulPow2Plus1(int arg) {
Alexandre Rames38db7852015-11-20 15:02:45 +00001279 return arg * 9;
1280 }
1281
Alexandre Rames38db7852015-11-20 15:02:45 +00001282 /**
1283 * Test strength reduction of factors of the form (2^n - 1).
1284 */
1285
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001286 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (before)
Alexandre Rames38db7852015-11-20 15:02:45 +00001287 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1288 /// CHECK-DAG: <<Const31:j\d+>> LongConstant 31
David Brazdil57e863c2016-01-11 10:27:13 +00001289 /// CHECK: Mul [<<Const31>>,<<Arg>>]
Alexandre Rames38db7852015-11-20 15:02:45 +00001290
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001291 /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (after)
Alexandre Rames38db7852015-11-20 15:02:45 +00001292 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1293 /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5
1294 /// CHECK: <<Shift:j\d+>> Shl [<<Arg>>,<<Const5>>]
1295 /// CHECK-NEXT: Sub [<<Shift>>,<<Arg>>]
1296
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001297 public static long $noinline$mulPow2Minus1(long arg) {
Alexandre Rames38db7852015-11-20 15:02:45 +00001298 return arg * 31;
1299 }
1300
Aart Bik639cc8c2016-10-18 13:03:31 -07001301 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001302 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdilf02c3cf2016-02-29 09:14:51 +00001303 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1304 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Mark Mendellf6529172015-11-17 11:16:56 -05001305 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1306 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<Field>>,<<Const1>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +00001307 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1308 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001309
Aart Bik639cc8c2016-10-18 13:03:31 -07001310 /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001311 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1312 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1313 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1314 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1315 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001316
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001317 public static int $noinline$booleanFieldNotEqualOne() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001318 return (booleanField == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001319 }
1320
Aart Bik639cc8c2016-10-18 13:03:31 -07001321 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001322 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdilf02c3cf2016-02-29 09:14:51 +00001323 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1324 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
Mark Mendellf6529172015-11-17 11:16:56 -05001325 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
David Brazdilf02c3cf2016-02-29 09:14:51 +00001326 /// CHECK-DAG: <<NE:z\d+>> Equal [<<Field>>,<<Const0>>]
1327 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1328 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001329
Aart Bik639cc8c2016-10-18 13:03:31 -07001330 /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001331 /// CHECK-DAG: <<Field:z\d+>> StaticFieldGet
1332 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1333 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1334 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const54>>,<<Const13>>,<<Field>>]
1335 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001336
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001337 public static int $noinline$booleanFieldEqualZero() {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001338 return (booleanField != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001339 }
1340
Aart Bik639cc8c2016-10-18 13:03:31 -07001341 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001342 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001343 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
Mark Mendellf6529172015-11-17 11:16:56 -05001344 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +00001345 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001346 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001347 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1348 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1349 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001350 /// CHECK-DAG: <<NE:z\d+>> NotEqual [<<GT>>,<<Const1>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001351 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1352 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001353
Aart Bik639cc8c2016-10-18 13:03:31 -07001354 /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001355 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
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: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001360 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001361 /// CHECK-DAG: Return [<<Result>>]
1362 // Note that we match `LE` from Select because there are two identical
1363 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001364
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001365 public static int $noinline$intConditionNotEqualOne(int i) {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001366 return ((i > 42) == $inline$true()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001367 }
1368
Aart Bik639cc8c2016-10-18 13:03:31 -07001369 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (before)
Mark Mendellf6529172015-11-17 11:16:56 -05001370 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1371 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +00001372 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
1373 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
Mark Mendellf6529172015-11-17 11:16:56 -05001374 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
David Brazdil74eb1b22015-12-14 11:44:01 +00001375 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1376 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1377 /// CHECK-DAG: <<GT:i\d+>> Select [<<Const1>>,<<Const0>>,<<LE>>]
1378 /// CHECK-DAG: <<NE:z\d+>> Equal [<<GT>>,<<Const0>>]
1379 /// CHECK-DAG: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<NE>>]
1380 /// CHECK-DAG: Return [<<Result>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001381
Aart Bik639cc8c2016-10-18 13:03:31 -07001382 /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (after)
Mark Mendellf6529172015-11-17 11:16:56 -05001383 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +00001384 /// 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: <<Result:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001388 /// CHECK-DAG: <<LE>> LessThanOrEqual [<<Arg>>,<<Const42>>]
David Brazdil74eb1b22015-12-14 11:44:01 +00001389 /// CHECK-DAG: Return [<<Result>>]
1390 // Note that we match `LE` from Select because there are two identical
1391 // LessThanOrEqual instructions.
Mark Mendellf6529172015-11-17 11:16:56 -05001392
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001393 public static int $noinline$intConditionEqualZero(int i) {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001394 return ((i > 42) != $inline$false()) ? 13 : 54;
Mark Mendellf6529172015-11-17 11:16:56 -05001395 }
1396
1397 // Test that conditions on float/double are not flipped.
1398
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001399 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001400 /// CHECK: LessThanOrEqual
1401
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001402 /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001403 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1404 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1405 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1406 /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42
1407 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1408 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1409 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001410
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001411 public static int $noinline$floatConditionNotEqualOne(float f) {
Mark Mendellf6529172015-11-17 11:16:56 -05001412 return ((f > 42.0f) == true) ? 13 : 54;
1413 }
1414
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001415 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) builder (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001416 /// CHECK: LessThanOrEqual
1417
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -07001418 /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) instruction_simplifier$before_codegen (after)
David Brazdil74eb1b22015-12-14 11:44:01 +00001419 /// CHECK-DAG: <<Arg:d\d+>> ParameterValue
1420 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
1421 /// CHECK-DAG: <<Const54:i\d+>> IntConstant 54
1422 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1423 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Arg>>,<<Const42>>]
1424 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const13>>,<<Const54>>,<<LE>>]
1425 /// CHECK-DAG: Return [<<Select>>]
Mark Mendellf6529172015-11-17 11:16:56 -05001426
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001427 public static int $noinline$doubleConditionEqualZero(double d) {
Mark Mendellf6529172015-11-17 11:16:56 -05001428 return ((d > 42.0) != false) ? 13 : 54;
1429 }
Alexandre Rames38db7852015-11-20 15:02:45 +00001430
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001431 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001432 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1433 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1434 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1435 /// CHECK-DAG: Return [<<Int>>]
1436
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001437 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001438 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1439 /// CHECK-DAG: Return [<<Arg>>]
1440
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001441 /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001442 /// CHECK-NOT: TypeConversion
1443
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001444 public static int $noinline$intToDoubleToInt(int value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001445 // Lossless conversion followed by a conversion back.
1446 return (int) (double) value;
1447 }
1448
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001449 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001450 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1451 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1452 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1453
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001454 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001455 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1456 /// CHECK-DAG: {{d\d+}} TypeConversion [<<Arg>>]
1457
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001458 /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001459 /// CHECK-DAG: TypeConversion
1460 /// CHECK-NOT: TypeConversion
1461
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001462 public static String $noinline$intToDoubleToIntPrint(int value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001463 // Lossless conversion followed by a conversion back
1464 // with another use of the intermediate result.
1465 double d = (double) value;
1466 int i = (int) d;
1467 return "d=" + d + ", i=" + i;
1468 }
1469
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001470 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001471 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1472 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1473 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1474 /// CHECK-DAG: Return [<<Int>>]
1475
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001476 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001477 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1478 /// CHECK-DAG: Return [<<Arg>>]
1479
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001480 /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001481 /// CHECK-NOT: TypeConversion
1482
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001483 public static int $noinline$byteToDoubleToInt(byte value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001484 // Lossless conversion followed by another conversion, use implicit conversion.
1485 return (int) (double) value;
1486 }
1487
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001488 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001489 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1490 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1491 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1492 /// CHECK-DAG: Return [<<Int>>]
1493
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001494 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001495 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1496 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1497 /// CHECK-DAG: Return [<<Int>>]
1498
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001499 /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001500 /// CHECK-DAG: TypeConversion
1501 /// CHECK-NOT: TypeConversion
1502
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001503 public static int $noinline$floatToDoubleToInt(float value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001504 // Lossless conversion followed by another conversion.
1505 return (int) (double) value;
1506 }
1507
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001508 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001509 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1510 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1511 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1512
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001513 /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001514 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1515 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1516 /// CHECK-DAG: {{i\d+}} TypeConversion [<<Double>>]
1517
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001518 public static String $noinline$floatToDoubleToIntPrint(float value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001519 // Lossless conversion followed by another conversion with
1520 // an extra use of the intermediate result.
1521 double d = (double) value;
1522 int i = (int) d;
1523 return "d=" + d + ", i=" + i;
1524 }
1525
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001526 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001527 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1528 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1529 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1530 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1531 /// CHECK-DAG: Return [<<Short>>]
1532
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001533 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001534 /// CHECK-DAG: <<Arg:b\d+>> ParameterValue
1535 /// CHECK-DAG: Return [<<Arg>>]
1536
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001537 /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001538 /// CHECK-NOT: TypeConversion
1539
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001540 public static short $noinline$byteToDoubleToShort(byte value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001541 // Originally, this is byte->double->int->short. The first conversion is lossless,
1542 // so we merge this with the second one to byte->int which we omit as it's an implicit
1543 // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1544 return (short) (double) value;
1545 }
1546
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001547 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001548 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1549 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1550 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Double>>]
1551 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1552 /// CHECK-DAG: Return [<<Short>>]
1553
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001554 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001555 /// CHECK-DAG: <<Arg:c\d+>> ParameterValue
1556 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Arg>>]
1557 /// CHECK-DAG: Return [<<Short>>]
1558
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001559 /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001560 /// CHECK-DAG: TypeConversion
1561 /// CHECK-NOT: TypeConversion
1562
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001563 public static short $noinline$charToDoubleToShort(char value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001564 // Originally, this is char->double->int->short. The first conversion is lossless,
1565 // so we merge this with the second one to char->int which we omit as it's an implicit
1566 // conversion. Then we are left with the resulting char->short conversion.
1567 return (short) (double) value;
1568 }
1569
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001570 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001571 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1572 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1573 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1574 /// CHECK-DAG: Return [<<Short>>]
1575
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001576 /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001577 /// CHECK-DAG: <<Arg:f\d+>> ParameterValue
1578 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1579 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Int>>]
1580 /// CHECK-DAG: Return [<<Short>>]
1581
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001582 public static short $noinline$floatToIntToShort(float value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001583 // Lossy FP to integral conversion followed by another conversion: no simplification.
1584 return (short) value;
1585 }
1586
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001587 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001588 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1589 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1590 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1591 /// CHECK-DAG: Return [<<Int>>]
1592
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001593 /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001594 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1595 /// CHECK-DAG: <<Float:f\d+>> TypeConversion [<<Arg>>]
1596 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Float>>]
1597 /// CHECK-DAG: Return [<<Int>>]
1598
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001599 public static int $noinline$intToFloatToInt(int value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001600 // Lossy integral to FP conversion followed another conversion: no simplification.
1601 return (int) (float) value;
1602 }
1603
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001604 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001605 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1606 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1607 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1608 /// CHECK-DAG: Return [<<Double>>]
1609
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001610 /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001611 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1612 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1613 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Int>>]
1614 /// CHECK-DAG: Return [<<Double>>]
1615
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001616 public static double $noinline$longToIntToDouble(long value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001617 // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1618 return (double) (int) value;
1619 }
1620
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001621 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001622 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1623 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1624 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1625 /// CHECK-DAG: Return [<<Long>>]
1626
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001627 /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001628 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1629 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Arg>>]
1630 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Int>>]
1631 /// CHECK-DAG: Return [<<Long>>]
1632
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001633 public static long $noinline$longToIntToLong(long value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001634 // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1635 return (long) (int) value;
1636 }
1637
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001638 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001639 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1640 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1641 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<Char>>]
1642 /// CHECK-DAG: Return [<<Short>>]
1643
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001644 /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001645 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1646 /// CHECK-DAG: Return [<<Arg>>]
1647
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001648 public static short $noinline$shortToCharToShort(short value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001649 // Integral conversion followed by non-widening integral conversion to original type.
1650 return (short) (char) value;
1651 }
1652
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001653 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001654 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1655 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1656 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<Long>>]
1657 /// CHECK-DAG: Return [<<Int>>]
1658
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001659 /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001660 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1661 /// CHECK-DAG: Return [<<Arg>>]
1662
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001663 public static int $noinline$shortToLongToInt(short value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001664 // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1665 return (int) (long) value;
1666 }
1667
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001668 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001669 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1670 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1671 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Char>>]
1672 /// CHECK-DAG: Return [<<Byte>>]
1673
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001674 /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001675 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1676 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1677 /// CHECK-DAG: Return [<<Byte>>]
1678
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001679 public static byte $noinline$shortToCharToByte(short value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001680 // Integral conversion followed by non-widening integral conversion losing bits
1681 // from the original type. Simplify to use only one conversion.
1682 return (byte) (char) value;
1683 }
1684
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001685 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (before)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001686 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1687 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1688 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1689
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001690 /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (after)
Vladimir Markob52bbde2016-02-12 12:06:05 +00001691 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1692 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1693 /// CHECK-DAG: {{b\d+}} TypeConversion [<<Char>>]
1694
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001695 public static String $noinline$shortToCharToBytePrint(short value) {
Vladimir Markob52bbde2016-02-12 12:06:05 +00001696 // Integral conversion followed by non-widening integral conversion losing bits
1697 // from the original type with an extra use of the intermediate result.
1698 char c = (char) value;
1699 byte b = (byte) c;
1700 return "c=" + ((int) c) + ", b=" + ((int) b); // implicit conversions.
1701 }
1702
Vladimir Markoc8fb2112017-10-03 11:37:52 +01001703 /// CHECK-START: long Main.$noinline$intAndSmallLongConstant(int) instruction_simplifier (before)
1704 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1705 /// CHECK-DAG: <<Mask:j\d+>> LongConstant -12345678
1706 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1707 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>]
1708 /// CHECK-DAG: Return [<<And>>]
1709
1710 /// CHECK-START: long Main.$noinline$intAndSmallLongConstant(int) instruction_simplifier (after)
1711 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1712 /// CHECK-DAG: <<Mask:i\d+>> IntConstant -12345678
1713 /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Mask>>]
1714 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<And>>]
1715 /// CHECK-DAG: Return [<<Long>>]
1716
1717 public static long $noinline$intAndSmallLongConstant(int value) {
1718 return value & -12345678L; // Shall be simplified (constant is 32-bit).
1719 }
1720
1721 /// CHECK-START: long Main.$noinline$intAndLargeLongConstant(int) instruction_simplifier (before)
1722 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1723 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 9876543210
1724 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1725 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>]
1726 /// CHECK-DAG: Return [<<And>>]
1727
1728 /// CHECK-START: long Main.$noinline$intAndLargeLongConstant(int) instruction_simplifier (after)
1729 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1730 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 9876543210
1731 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Arg>>]
1732 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>]
1733 /// CHECK-DAG: Return [<<And>>]
1734
1735 public static long $noinline$intAndLargeLongConstant(int value) {
1736 return value & 9876543210L; // Shall not be simplified (constant is not 32-bit).
1737 }
1738
1739 /// CHECK-START: long Main.$noinline$intShr28And15L(int) instruction_simplifier (before)
1740 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1741 /// CHECK-DAG: <<Shift:i\d+>> IntConstant 28
1742 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 15
1743 /// CHECK-DAG: <<Shifted:i\d+>> Shr [<<Arg>>,<<Shift>>]
1744 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Shifted>>]
1745 /// CHECK-DAG: <<And:j\d+>> And [<<Long>>,<<Mask>>]
1746 /// CHECK-DAG: Return [<<And>>]
1747
1748 /// CHECK-START: long Main.$noinline$intShr28And15L(int) instruction_simplifier (after)
1749 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1750 /// CHECK-DAG: <<Shift:i\d+>> IntConstant 28
1751 /// CHECK-DAG: <<Shifted:i\d+>> UShr [<<Arg>>,<<Shift>>]
1752 /// CHECK-DAG: <<Long:j\d+>> TypeConversion [<<Shifted>>]
1753 /// CHECK-DAG: Return [<<Long>>]
1754
1755 public static long $noinline$intShr28And15L(int value) {
1756 return (value >> 28) & 15L;
1757 }
1758
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001759 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001760 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1761 /// CHECK-DAG: <<Mask:j\d+>> LongConstant 255
1762 /// CHECK-DAG: <<And:j\d+>> And [<<Mask>>,<<Arg>>]
1763 /// CHECK-DAG: <<Int:i\d+>> TypeConversion [<<And>>]
1764 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Int>>]
1765 /// CHECK-DAG: Return [<<Byte>>]
1766
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001767 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001768 /// CHECK-DAG: <<Arg:j\d+>> ParameterValue
1769 /// CHECK-DAG: <<Byte:b\d+>> TypeConversion [<<Arg>>]
1770 /// CHECK-DAG: Return [<<Byte>>]
1771
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001772 /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001773 /// CHECK-NOT: And
1774
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001775 public static byte $noinline$longAnd0xffToByte(long value) {
Vladimir Marko8428bd32016-02-12 16:53:57 +00001776 return (byte) (value & 0xff);
1777 }
1778
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001779 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001780 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1781 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 131071
1782 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1783 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<And>>]
1784 /// CHECK-DAG: Return [<<Char>>]
1785
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001786 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001787 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1788 /// CHECK-DAG: <<Char:c\d+>> TypeConversion [<<Arg>>]
1789 /// CHECK-DAG: Return [<<Char>>]
1790
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001791 /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001792 /// CHECK-NOT: And
1793
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001794 public static char $noinline$intAnd0x1ffffToChar(int value) {
Vladimir Marko8428bd32016-02-12 16:53:57 +00001795 // Keeping all significant bits and one more.
1796 return (char) (value & 0x1ffff);
1797 }
1798
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001799 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (before)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001800 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1801 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1802 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1803 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1804 /// CHECK-DAG: Return [<<Short>>]
1805
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001806 /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (after)
Vladimir Marko8428bd32016-02-12 16:53:57 +00001807 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1808 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 98303
1809 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1810 /// CHECK-DAG: <<Short:s\d+>> TypeConversion [<<And>>]
1811 /// CHECK-DAG: Return [<<Short>>]
1812
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001813 public static short $noinline$intAnd0x17fffToShort(int value) {
Vladimir Marko8428bd32016-02-12 16:53:57 +00001814 // No simplification: clearing a significant bit.
1815 return (short) (value & 0x17fff);
1816 }
1817
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001818 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (before)
Vladimir Marko625090f2016-03-14 18:00:05 +00001819 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1820 /// CHECK-DAG: <<Mask:i\d+>> IntConstant 65535
1821 /// CHECK-DAG: <<And:i\d+>> And [<<Mask>>,<<Arg>>]
1822 /// CHECK-DAG: <<Same:s\d+>> TypeConversion [<<And>>]
1823 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Same>>]
1824 /// CHECK-DAG: Return [<<Double>>]
1825
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001826 /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (after)
Vladimir Marko625090f2016-03-14 18:00:05 +00001827 /// CHECK-DAG: <<Arg:s\d+>> ParameterValue
1828 /// CHECK-DAG: <<Double:d\d+>> TypeConversion [<<Arg>>]
1829 /// CHECK-DAG: Return [<<Double>>]
1830
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001831 public static double $noinline$shortAnd0xffffToShortToDouble(short value) {
Vladimir Marko625090f2016-03-14 18:00:05 +00001832 short same = (short) (value & 0xffff);
1833 return (double) same;
1834 }
1835
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001836 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001837 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1838 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1839 /// CHECK-DAG: <<LE:z\d+>> LessThanOrEqual [<<Const42>>,<<Arg>>]
1840
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001841 /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001842 /// CHECK-DAG: <<Arg:i\d+>> ParameterValue
1843 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
1844 /// CHECK-DAG: <<GE:z\d+>> GreaterThanOrEqual [<<Arg>>,<<Const42>>]
1845
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001846 public static int $noinline$intReverseCondition(int i) {
Anton Shaminbdd79352016-02-15 12:48:36 +06001847 return (42 > i) ? 13 : 54;
1848 }
1849
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001850 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (before)
Anton Shaminbdd79352016-02-15 12:48:36 +06001851 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1852 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1853 /// CHECK-DAG: <<CMP:i\d+>> Compare [<<Const42>>,<<Result>>]
1854
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001855 /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (after)
Anton Shaminbdd79352016-02-15 12:48:36 +06001856 /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42
1857 /// CHECK-DAG: <<Result:d\d+>> InvokeStaticOrDirect
1858 /// CHECK-DAG: <<EQ:z\d+>> Equal [<<Result>>,<<Const42>>]
1859
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001860 public static int $noinline$intReverseConditionNaN(int i) {
Anton Shaminbdd79352016-02-15 12:48:36 +06001861 return (42 != Math.sqrt(i)) ? 13 : 54;
1862 }
1863
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01001864 public static int $noinline$runSmaliTest(String name, boolean input) {
David Brazdilf02c3cf2016-02-29 09:14:51 +00001865 try {
1866 Class<?> c = Class.forName("SmaliTests");
Andreas Gampe166aaee2016-07-18 08:27:23 -07001867 Method m = c.getMethod(name, boolean.class);
David Brazdilf02c3cf2016-02-29 09:14:51 +00001868 return (Integer) m.invoke(null, input);
1869 } catch (Exception ex) {
1870 throw new Error(ex);
1871 }
1872 }
1873
Igor Murashkin42691732017-06-26 15:57:31 -07001874 public static boolean $noinline$runSmaliTestBoolean(String name, boolean input) {
Igor Murashkin42691732017-06-26 15:57:31 -07001875 try {
1876 Class<?> c = Class.forName("SmaliTests");
1877 Method m = c.getMethod(name, boolean.class);
1878 return (Boolean) m.invoke(null, input);
1879 } catch (Exception ex) {
1880 throw new Error(ex);
1881 }
1882 }
1883
1884 public static int $noinline$runSmaliTestInt(String name, int arg) {
Anton Kirilove14dc862016-05-13 17:56:15 +01001885 try {
1886 Class<?> c = Class.forName("SmaliTests");
1887 Method m = c.getMethod(name, int.class);
1888 return (Integer) m.invoke(null, arg);
1889 } catch (Exception ex) {
1890 throw new Error(ex);
1891 }
1892 }
1893
Igor Murashkin42691732017-06-26 15:57:31 -07001894 public static long $noinline$runSmaliTestLong(String name, long arg) {
Igor Murashkin42691732017-06-26 15:57:31 -07001895 try {
1896 Class<?> c = Class.forName("SmaliTests");
1897 Method m = c.getMethod(name, long.class);
1898 return (Long) m.invoke(null, arg);
1899 } catch (Exception ex) {
1900 throw new Error(ex);
1901 }
1902 }
1903
Alexandre Rames50518442016-06-27 11:39:19 +01001904 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1905 /// CHECK: <<Value:i\d+>> ParameterValue
1906 /// CHECK: <<Shift:i\d+>> ParameterValue
1907 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1908 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1909 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<And>>]
1910 /// CHECK-DAG: Return [<<Shl>>]
1911
1912 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1913 /// CHECK: <<Value:i\d+>> ParameterValue
1914 /// CHECK: <<Shift:i\d+>> ParameterValue
1915 /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Value>>,<<Shift>>]
1916 /// CHECK-DAG: Return [<<Shl>>]
1917
1918 public static int $noinline$intUnnecessaryShiftMasking(int value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01001919 return value << (shift & 31);
1920 }
1921
1922 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (before)
1923 /// CHECK: <<Value:j\d+>> ParameterValue
1924 /// CHECK: <<Shift:i\d+>> ParameterValue
1925 /// CHECK-DAG: <<Const63:i\d+>> IntConstant 63
1926 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const63>>]
1927 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<And>>]
1928 /// CHECK-DAG: Return [<<Shr>>]
1929
1930 /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (after)
1931 /// CHECK: <<Value:j\d+>> ParameterValue
1932 /// CHECK: <<Shift:i\d+>> ParameterValue
1933 /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Value>>,<<Shift>>]
1934 /// CHECK-DAG: Return [<<Shr>>]
1935
1936 public static long $noinline$longUnnecessaryShiftMasking(long value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01001937 return value >> (shift & 63);
1938 }
1939
1940 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (before)
1941 /// CHECK: <<Value:i\d+>> ParameterValue
1942 /// CHECK: <<Shift:i\d+>> ParameterValue
1943 /// CHECK-DAG: <<Const255:i\d+>> IntConstant 255
1944 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const255>>]
1945 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<And>>]
1946 /// CHECK-DAG: Return [<<UShr>>]
1947
1948 /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (after)
1949 /// CHECK: <<Value:i\d+>> ParameterValue
1950 /// CHECK: <<Shift:i\d+>> ParameterValue
1951 /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Value>>,<<Shift>>]
1952 /// CHECK-DAG: Return [<<UShr>>]
1953
1954 public static int $noinline$intUnnecessaryWiderShiftMasking(int value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01001955 return value >>> (shift & 0xff);
1956 }
1957
1958 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (before)
1959 /// CHECK: <<Value:j\d+>> ParameterValue
1960 /// CHECK: <<Shift:i\d+>> ParameterValue
1961 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1962 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
1963 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
1964 /// CHECK-DAG: Return [<<Shl>>]
1965
1966 /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (after)
1967 /// CHECK: <<Value:j\d+>> ParameterValue
1968 /// CHECK: <<Shift:i\d+>> ParameterValue
1969 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
1970 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const3>>]
1971 /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Value>>,<<And>>]
1972 /// CHECK-DAG: Return [<<Shl>>]
1973
1974 public static long $noinline$longSmallerShiftMasking(long value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01001975 return value << (shift & 3);
1976 }
1977
1978 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1979 /// CHECK: <<Value:i\d+>> ParameterValue
1980 /// CHECK: <<Shift:i\d+>> ParameterValue
1981 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1982 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1983 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<And>>]
1984 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
1985 /// CHECK-DAG: Return [<<Add>>]
1986
1987 /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1988 /// CHECK: <<Value:i\d+>> ParameterValue
1989 /// CHECK: <<Shift:i\d+>> ParameterValue
1990 /// CHECK-DAG: <<Const31:i\d+>> IntConstant 31
1991 /// CHECK-DAG: <<And:i\d+>> And [<<Shift>>,<<Const31>>]
1992 /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Value>>,<<Shift>>]
1993 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shr>>,<<And>>]
1994 /// CHECK-DAG: Return [<<Add>>]
1995
1996 public static int $noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift) {
Alexandre Rames50518442016-06-27 11:39:19 +01001997 int temp = shift & 31;
1998 return (value >> temp) + temp;
1999 }
2000
Vladimir Marko7033d492017-09-28 16:32:24 +01002001 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (before)
2002 /// CHECK: <<Value:i\d+>> ParameterValue
2003 /// CHECK: <<Shift:i\d+>> ParameterValue
2004 /// CHECK-DAG: <<Const32:i\d+>> IntConstant 32
2005 /// CHECK-DAG: <<Const64:i\d+>> IntConstant 64
2006 /// CHECK-DAG: <<Const96:i\d+>> IntConstant 96
2007 /// CHECK-DAG: <<Const128:i\d+>> IntConstant 128
2008 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const32>>]
2009 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const64>>]
2010 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const96>>]
2011 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const128>>]
2012 /// CHECK-DAG: <<Conv:b\d+>> TypeConversion [<<Shift>>]
2013 /// CHECK-DAG: Shl [<<Value>>,<<Or>>]
2014 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>]
2015 /// CHECK-DAG: UShr [<<Value>>,<<Add>>]
2016 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>]
2017 /// CHECK-DAG: Shr [<<Value>>,<<Conv>>]
2018
2019 /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (after)
2020 /// CHECK: <<Value:i\d+>> ParameterValue
2021 /// CHECK: <<Shift:i\d+>> ParameterValue
2022 /// CHECK-DAG: Shl [<<Value>>,<<Shift>>]
2023 /// CHECK-DAG: Shr [<<Value>>,<<Shift>>]
2024 /// CHECK-DAG: UShr [<<Value>>,<<Shift>>]
2025 /// CHECK-DAG: Shl [<<Value>>,<<Shift>>]
2026 /// CHECK-DAG: Shr [<<Value>>,<<Shift>>]
2027
2028 public static int $noinline$intUnnecessaryShiftModifications(int value, int shift) {
Vladimir Marko7033d492017-09-28 16:32:24 +01002029 int c128 = 128;
2030 return (value << (shift | 32)) +
2031 (value >> (shift ^ 64)) +
2032 (value >>> (shift + 96)) +
2033 (value << (shift - c128)) + // Needs a named constant to generate Sub.
2034 (value >> ((byte) shift));
2035 }
2036
2037 /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (before)
2038 /// CHECK: <<Value:i\d+>> ParameterValue
2039 /// CHECK: <<Shift:i\d+>> ParameterValue
2040 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
2041 /// CHECK-DAG: <<Const65:i\d+>> IntConstant 65
2042 /// CHECK-DAG: <<Const97:i\d+>> IntConstant 97
2043 /// CHECK-DAG: <<Const129:i\d+>> IntConstant 129
2044 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const33>>]
2045 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const65>>]
2046 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const97>>]
2047 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const129>>]
2048 /// CHECK-DAG: Shl [<<Value>>,<<Or>>]
2049 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>]
2050 /// CHECK-DAG: UShr [<<Value>>,<<Add>>]
2051 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>]
2052
2053 /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (after)
2054 /// CHECK: <<Value:i\d+>> ParameterValue
2055 /// CHECK: <<Shift:i\d+>> ParameterValue
2056 /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33
2057 /// CHECK-DAG: <<Const65:i\d+>> IntConstant 65
2058 /// CHECK-DAG: <<Const97:i\d+>> IntConstant 97
2059 /// CHECK-DAG: <<Const129:i\d+>> IntConstant 129
2060 /// CHECK-DAG: <<Or:i\d+>> Or [<<Shift>>,<<Const33>>]
2061 /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Shift>>,<<Const65>>]
2062 /// CHECK-DAG: <<Add:i\d+>> Add [<<Shift>>,<<Const97>>]
2063 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Shift>>,<<Const129>>]
2064 /// CHECK-DAG: Shl [<<Value>>,<<Or>>]
2065 /// CHECK-DAG: Shr [<<Value>>,<<Xor>>]
2066 /// CHECK-DAG: UShr [<<Value>>,<<Add>>]
2067 /// CHECK-DAG: Shl [<<Value>>,<<Sub>>]
2068
2069 public static int $noinline$intNecessaryShiftModifications(int value, int shift) {
Vladimir Marko7033d492017-09-28 16:32:24 +01002070 int c129 = 129;
2071 return (value << (shift | 33)) +
2072 (value >> (shift ^ 65)) +
2073 (value >>> (shift + 97)) +
2074 (value << (shift - c129)); // Needs a named constant to generate Sub.
2075 }
2076
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002077 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (before)
2078 /// CHECK: <<X:i\d+>> ParameterValue
2079 /// CHECK: <<Y:i\d+>> ParameterValue
2080 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2081 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<X>>]
2082 /// CHECK-DAG: Return [<<Res>>]
2083
2084 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (after)
2085 /// CHECK: <<X:i\d+>> ParameterValue
2086 /// CHECK: <<Y:i\d+>> ParameterValue
2087 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2088 /// CHECK-DAG: Return [<<Y>>]
2089
2090 public static int $noinline$intAddSubSimplifyArg1(int x, int y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002091 int sum = x + y;
2092 return sum - x;
2093 }
2094
2095 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (before)
2096 /// CHECK: <<X:i\d+>> ParameterValue
2097 /// CHECK: <<Y:i\d+>> ParameterValue
2098 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2099 /// CHECK-DAG: <<Res:i\d+>> Sub [<<Sum>>,<<Y>>]
2100 /// CHECK-DAG: Return [<<Res>>]
2101
2102 /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (after)
2103 /// CHECK: <<X:i\d+>> ParameterValue
2104 /// CHECK: <<Y:i\d+>> ParameterValue
2105 /// CHECK-DAG: <<Sum:i\d+>> Add [<<X>>,<<Y>>]
2106 /// CHECK-DAG: Return [<<X>>]
2107
2108 public static int $noinline$intAddSubSimplifyArg2(int x, int y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002109 int sum = x + y;
2110 return sum - y;
2111 }
2112
2113 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (before)
2114 /// CHECK: <<X:i\d+>> ParameterValue
2115 /// CHECK: <<Y:i\d+>> ParameterValue
2116 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2117 /// CHECK-DAG: <<Res:i\d+>> Add [<<Sub>>,<<Y>>]
2118 /// CHECK-DAG: Return [<<Res>>]
2119
2120 /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (after)
2121 /// CHECK: <<X:i\d+>> ParameterValue
2122 /// CHECK: <<Y:i\d+>> ParameterValue
2123 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2124 /// CHECK-DAG: Return [<<X>>]
2125
2126 public static int $noinline$intSubAddSimplifyLeft(int x, int y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002127 int sub = x - y;
2128 return sub + y;
2129 }
2130
2131 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (before)
2132 /// CHECK: <<X:i\d+>> ParameterValue
2133 /// CHECK: <<Y:i\d+>> ParameterValue
2134 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2135 /// CHECK-DAG: <<Res:i\d+>> Add [<<Y>>,<<Sub>>]
2136 /// CHECK-DAG: Return [<<Res>>]
2137
2138 /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (after)
2139 /// CHECK: <<X:i\d+>> ParameterValue
2140 /// CHECK: <<Y:i\d+>> ParameterValue
2141 /// CHECK-DAG: <<Sub:i\d+>> Sub [<<X>>,<<Y>>]
2142 /// CHECK-DAG: Return [<<X>>]
2143
2144 public static int $noinline$intSubAddSimplifyRight(int x, int y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002145 int sub = x - y;
2146 return y + sub;
2147 }
2148
2149 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (before)
2150 /// CHECK: <<X:f\d+>> ParameterValue
2151 /// CHECK: <<Y:f\d+>> ParameterValue
2152 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2153 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2154 /// CHECK-DAG: Return [<<Res>>]
2155
2156 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (after)
2157 /// CHECK: <<X:f\d+>> ParameterValue
2158 /// CHECK: <<Y:f\d+>> ParameterValue
2159 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2160 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<X>>]
2161 /// CHECK-DAG: Return [<<Res>>]
2162
2163 public static float $noinline$floatAddSubSimplifyArg1(float x, float y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002164 float sum = x + y;
2165 return sum - x;
2166 }
2167
2168 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (before)
2169 /// CHECK: <<X:f\d+>> ParameterValue
2170 /// CHECK: <<Y:f\d+>> ParameterValue
2171 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2172 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2173 /// CHECK-DAG: Return [<<Res>>]
2174
2175 /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (after)
2176 /// CHECK: <<X:f\d+>> ParameterValue
2177 /// CHECK: <<Y:f\d+>> ParameterValue
2178 /// CHECK-DAG: <<Sum:f\d+>> Add [<<X>>,<<Y>>]
2179 /// CHECK-DAG: <<Res:f\d+>> Sub [<<Sum>>,<<Y>>]
2180 /// CHECK-DAG: Return [<<Res>>]
2181
2182 public static float $noinline$floatAddSubSimplifyArg2(float x, float y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002183 float sum = x + y;
2184 return sum - y;
2185 }
2186
2187 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (before)
2188 /// CHECK: <<X:f\d+>> ParameterValue
2189 /// CHECK: <<Y:f\d+>> ParameterValue
2190 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2191 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2192 /// CHECK-DAG: Return [<<Res>>]
2193
2194 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (after)
2195 /// CHECK: <<X:f\d+>> ParameterValue
2196 /// CHECK: <<Y:f\d+>> ParameterValue
2197 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2198 /// CHECK-DAG: <<Res:f\d+>> Add [<<Sub>>,<<Y>>]
2199 /// CHECK-DAG: Return [<<Res>>]
2200
2201 public static float $noinline$floatSubAddSimplifyLeft(float x, float y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002202 float sub = x - y;
2203 return sub + y;
2204 }
2205
2206 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (before)
2207 /// CHECK: <<X:f\d+>> ParameterValue
2208 /// CHECK: <<Y:f\d+>> ParameterValue
2209 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2210 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2211 /// CHECK-DAG: Return [<<Res>>]
2212
2213 /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (after)
2214 /// CHECK: <<X:f\d+>> ParameterValue
2215 /// CHECK: <<Y:f\d+>> ParameterValue
2216 /// CHECK-DAG: <<Sub:f\d+>> Sub [<<X>>,<<Y>>]
2217 /// CHECK-DAG: <<Res:f\d+>> Add [<<Y>>,<<Sub>>]
2218 /// CHECK-DAG: Return [<<Res>>]
2219
2220 public static float $noinline$floatSubAddSimplifyRight(float x, float y) {
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002221 float sub = x - y;
2222 return y + sub;
2223 }
2224
2225 public static void main(String[] args) {
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002226 int arg = 123456;
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002227 float floatArg = 123456.125f;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002228
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002229 assertLongEquals(arg, $noinline$Add0(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002230 assertIntEquals(5, $noinline$AddAddSubAddConst(1));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002231 assertIntEquals(arg, $noinline$AndAllOnes(arg));
2232 assertLongEquals(arg, $noinline$Div1(arg));
2233 assertIntEquals(-arg, $noinline$DivN1(arg));
2234 assertLongEquals(arg, $noinline$Mul1(arg));
2235 assertIntEquals(-arg, $noinline$MulN1(arg));
2236 assertLongEquals((128 * arg), $noinline$MulPowerOfTwo128(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002237 assertLongEquals(2640, $noinline$MulMulMulConst(2));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002238 assertIntEquals(arg, $noinline$Or0(arg));
2239 assertLongEquals(arg, $noinline$OrSame(arg));
2240 assertIntEquals(arg, $noinline$Shl0(arg));
2241 assertLongEquals(arg, $noinline$Shr0(arg));
2242 assertLongEquals(arg, $noinline$Shr64(arg));
2243 assertLongEquals(arg, $noinline$Sub0(arg));
2244 assertIntEquals(-arg, $noinline$SubAliasNeg(arg));
Anton Kirilove14dc862016-05-13 17:56:15 +01002245 assertIntEquals(9, $noinline$SubAddConst1(2));
2246 assertIntEquals(-2, $noinline$SubAddConst2(3));
2247 assertLongEquals(3, $noinline$SubSubConst(4));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002248 assertLongEquals(arg, $noinline$UShr0(arg));
2249 assertIntEquals(arg, $noinline$Xor0(arg));
2250 assertIntEquals(~arg, $noinline$XorAllOnes(arg));
2251 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs1(arg, arg + 1));
2252 assertIntEquals(-(arg + arg + 1), $noinline$AddNegs2(arg, arg + 1));
2253 assertLongEquals(-(2 * arg + 1), $noinline$AddNegs3(arg, arg + 1));
2254 assertLongEquals(1, $noinline$AddNeg1(arg, arg + 1));
2255 assertLongEquals(-1, $noinline$AddNeg2(arg, arg + 1));
2256 assertLongEquals(arg, $noinline$NegNeg1(arg));
2257 assertIntEquals(0, $noinline$NegNeg2(arg));
2258 assertLongEquals(arg, $noinline$NegNeg3(arg));
2259 assertIntEquals(1, $noinline$NegSub1(arg, arg + 1));
2260 assertIntEquals(1, $noinline$NegSub2(arg, arg + 1));
2261 assertLongEquals(arg, $noinline$NotNot1(arg));
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002262 assertLongEquals(arg, $noinline$runSmaliTestLong("$noinline$NotNot1", arg));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002263 assertIntEquals(-1, $noinline$NotNot2(arg));
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002264 assertIntEquals(-1, $noinline$runSmaliTestInt("$noinline$NotNot2", arg));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002265 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg1(arg, arg + 1));
2266 assertIntEquals(-(arg + arg + 1), $noinline$SubNeg2(arg, arg + 1));
2267 assertLongEquals(-(2 * arg + 1), $noinline$SubNeg3(arg, arg + 1));
2268 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2269 assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2270 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2271 assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2272 assertBooleanEquals(true, $noinline$NotNotBool(true));
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002273 assertBooleanEquals(true, $noinline$runSmaliTestBoolean("$noinline$NotNotBool", true));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002274 assertBooleanEquals(false, $noinline$NotNotBool(false));
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002275 assertBooleanEquals(false, $noinline$runSmaliTestBoolean("$noinline$NotNotBool", false));
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002276 assertFloatEquals(50.0f, $noinline$Div2(100.0f));
2277 assertDoubleEquals(75.0, $noinline$Div2(150.0));
2278 assertFloatEquals(-400.0f, $noinline$DivMP25(100.0f));
2279 assertDoubleEquals(-600.0, $noinline$DivMP25(150.0));
2280 assertIntEquals(0xc, $noinline$UShr28And15(0xc1234567));
2281 assertLongEquals(0xcL, $noinline$UShr60And15(0xc123456787654321L));
2282 assertIntEquals(0x4, $noinline$UShr28And7(0xc1234567));
2283 assertLongEquals(0x4L, $noinline$UShr60And7(0xc123456787654321L));
2284 assertIntEquals(0xc1, $noinline$Shr24And255(0xc1234567));
2285 assertLongEquals(0xc1L, $noinline$Shr56And255(0xc123456787654321L));
2286 assertIntEquals(0x41, $noinline$Shr24And127(0xc1234567));
2287 assertLongEquals(0x41L, $noinline$Shr56And127(0xc123456787654321L));
2288 assertIntEquals(0, $noinline$mulPow2Plus1(0));
2289 assertIntEquals(9, $noinline$mulPow2Plus1(1));
2290 assertIntEquals(18, $noinline$mulPow2Plus1(2));
2291 assertIntEquals(900, $noinline$mulPow2Plus1(100));
2292 assertIntEquals(111105, $noinline$mulPow2Plus1(12345));
2293 assertLongEquals(0, $noinline$mulPow2Minus1(0));
2294 assertLongEquals(31, $noinline$mulPow2Minus1(1));
2295 assertLongEquals(62, $noinline$mulPow2Minus1(2));
2296 assertLongEquals(3100, $noinline$mulPow2Minus1(100));
2297 assertLongEquals(382695, $noinline$mulPow2Minus1(12345));
Mark Mendellf6529172015-11-17 11:16:56 -05002298
2299 booleanField = false;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002300 assertIntEquals($noinline$booleanFieldNotEqualOne(), 54);
2301 assertIntEquals($noinline$booleanFieldEqualZero(), 54);
Mark Mendellf6529172015-11-17 11:16:56 -05002302 booleanField = true;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002303 assertIntEquals(13, $noinline$booleanFieldNotEqualOne());
2304 assertIntEquals(13, $noinline$booleanFieldEqualZero());
2305 assertIntEquals(54, $noinline$intConditionNotEqualOne(6));
2306 assertIntEquals(13, $noinline$intConditionNotEqualOne(43));
2307 assertIntEquals(54, $noinline$intConditionEqualZero(6));
2308 assertIntEquals(13, $noinline$intConditionEqualZero(43));
2309 assertIntEquals(54, $noinline$floatConditionNotEqualOne(6.0f));
2310 assertIntEquals(13, $noinline$floatConditionNotEqualOne(43.0f));
2311 assertIntEquals(54, $noinline$doubleConditionEqualZero(6.0));
2312 assertIntEquals(13, $noinline$doubleConditionEqualZero(43.0));
Vladimir Markob52bbde2016-02-12 12:06:05 +00002313
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002314 assertIntEquals(1234567, $noinline$intToDoubleToInt(1234567));
2315 assertIntEquals(Integer.MIN_VALUE, $noinline$intToDoubleToInt(Integer.MIN_VALUE));
2316 assertIntEquals(Integer.MAX_VALUE, $noinline$intToDoubleToInt(Integer.MAX_VALUE));
2317 assertStringEquals("d=7654321.0, i=7654321", $noinline$intToDoubleToIntPrint(7654321));
2318 assertIntEquals(12, $noinline$byteToDoubleToInt((byte) 12));
2319 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToInt(Byte.MIN_VALUE));
2320 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToInt(Byte.MAX_VALUE));
2321 assertIntEquals(11, $noinline$floatToDoubleToInt(11.3f));
2322 assertStringEquals("d=12.25, i=12", $noinline$floatToDoubleToIntPrint(12.25f));
2323 assertIntEquals(123, $noinline$byteToDoubleToShort((byte) 123));
2324 assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToShort(Byte.MIN_VALUE));
2325 assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToShort(Byte.MAX_VALUE));
2326 assertIntEquals(1234, $noinline$charToDoubleToShort((char) 1234));
2327 assertIntEquals(Character.MIN_VALUE, $noinline$charToDoubleToShort(Character.MIN_VALUE));
2328 assertIntEquals(/* sign-extended */ -1, $noinline$charToDoubleToShort(Character.MAX_VALUE));
2329 assertIntEquals(12345, $noinline$floatToIntToShort(12345.75f));
2330 assertIntEquals(Short.MAX_VALUE, $noinline$floatToIntToShort((float)(Short.MIN_VALUE - 1)));
2331 assertIntEquals(Short.MIN_VALUE, $noinline$floatToIntToShort((float)(Short.MAX_VALUE + 1)));
2332 assertIntEquals(-54321, $noinline$intToFloatToInt(-54321));
2333 assertDoubleEquals((double) 0x12345678, $noinline$longToIntToDouble(0x1234567812345678L));
2334 assertDoubleEquals(0.0, $noinline$longToIntToDouble(Long.MIN_VALUE));
2335 assertDoubleEquals(-1.0, $noinline$longToIntToDouble(Long.MAX_VALUE));
2336 assertLongEquals(0x0000000012345678L, $noinline$longToIntToLong(0x1234567812345678L));
2337 assertLongEquals(0xffffffff87654321L, $noinline$longToIntToLong(0x1234567887654321L));
2338 assertLongEquals(0L, $noinline$longToIntToLong(Long.MIN_VALUE));
2339 assertLongEquals(-1L, $noinline$longToIntToLong(Long.MAX_VALUE));
2340 assertIntEquals((short) -5678, $noinline$shortToCharToShort((short) -5678));
2341 assertIntEquals(Short.MIN_VALUE, $noinline$shortToCharToShort(Short.MIN_VALUE));
2342 assertIntEquals(Short.MAX_VALUE, $noinline$shortToCharToShort(Short.MAX_VALUE));
2343 assertIntEquals(5678, $noinline$shortToLongToInt((short) 5678));
2344 assertIntEquals(Short.MIN_VALUE, $noinline$shortToLongToInt(Short.MIN_VALUE));
2345 assertIntEquals(Short.MAX_VALUE, $noinline$shortToLongToInt(Short.MAX_VALUE));
2346 assertIntEquals(0x34, $noinline$shortToCharToByte((short) 0x1234));
2347 assertIntEquals(-0x10, $noinline$shortToCharToByte((short) 0x12f0));
2348 assertIntEquals(0, $noinline$shortToCharToByte(Short.MIN_VALUE));
2349 assertIntEquals(-1, $noinline$shortToCharToByte(Short.MAX_VALUE));
2350 assertStringEquals("c=1025, b=1", $noinline$shortToCharToBytePrint((short) 1025));
2351 assertStringEquals("c=1023, b=-1", $noinline$shortToCharToBytePrint((short) 1023));
2352 assertStringEquals("c=65535, b=-1", $noinline$shortToCharToBytePrint((short) -1));
Vladimir Marko8428bd32016-02-12 16:53:57 +00002353
Vladimir Markoc8fb2112017-10-03 11:37:52 +01002354 assertLongEquals(0x55411410L, $noinline$intAndSmallLongConstant(0x55555555));
2355 assertLongEquals(0xffffffffaa028aa2L, $noinline$intAndSmallLongConstant(0xaaaaaaaa));
2356 assertLongEquals(0x44101440L, $noinline$intAndLargeLongConstant(0x55555555));
2357 assertLongEquals(0x208a002aaL, $noinline$intAndLargeLongConstant(0xaaaaaaaa));
2358 assertLongEquals(7L, $noinline$intShr28And15L(0x76543210));
2359
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002360 assertIntEquals(0x21, $noinline$longAnd0xffToByte(0x1234432112344321L));
2361 assertIntEquals(0, $noinline$longAnd0xffToByte(Long.MIN_VALUE));
2362 assertIntEquals(-1, $noinline$longAnd0xffToByte(Long.MAX_VALUE));
2363 assertIntEquals(0x1234, $noinline$intAnd0x1ffffToChar(0x43211234));
2364 assertIntEquals(0, $noinline$intAnd0x1ffffToChar(Integer.MIN_VALUE));
2365 assertIntEquals(Character.MAX_VALUE, $noinline$intAnd0x1ffffToChar(Integer.MAX_VALUE));
2366 assertIntEquals(0x4321, $noinline$intAnd0x17fffToShort(0x87654321));
2367 assertIntEquals(0x0888, $noinline$intAnd0x17fffToShort(0x88888888));
2368 assertIntEquals(0, $noinline$intAnd0x17fffToShort(Integer.MIN_VALUE));
2369 assertIntEquals(Short.MAX_VALUE, $noinline$intAnd0x17fffToShort(Integer.MAX_VALUE));
Vladimir Marko625090f2016-03-14 18:00:05 +00002370
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002371 assertDoubleEquals(0.0, $noinline$shortAnd0xffffToShortToDouble((short) 0));
2372 assertDoubleEquals(1.0, $noinline$shortAnd0xffffToShortToDouble((short) 1));
2373 assertDoubleEquals(-2.0, $noinline$shortAnd0xffffToShortToDouble((short) -2));
2374 assertDoubleEquals(12345.0, $noinline$shortAnd0xffffToShortToDouble((short) 12345));
2375 assertDoubleEquals((double)Short.MAX_VALUE,
2376 $noinline$shortAnd0xffffToShortToDouble(Short.MAX_VALUE));
2377 assertDoubleEquals((double)Short.MIN_VALUE,
2378 $noinline$shortAnd0xffffToShortToDouble(Short.MIN_VALUE));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002379
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002380 assertIntEquals(13, $noinline$intReverseCondition(41));
2381 assertIntEquals(13, $noinline$intReverseConditionNaN(-5));
Anton Shaminbdd79352016-02-15 12:48:36 +06002382
David Brazdilf02c3cf2016-02-29 09:14:51 +00002383 for (String condition : new String[] { "Equal", "NotEqual" }) {
2384 for (String constant : new String[] { "True", "False" }) {
2385 for (String side : new String[] { "Rhs", "Lhs" }) {
2386 String name = condition + constant + side;
Alexandre Ramesa975dcc2016-06-27 11:13:34 +01002387 assertIntEquals(5, $noinline$runSmaliTest(name, true));
2388 assertIntEquals(3, $noinline$runSmaliTest(name, false));
David Brazdilf02c3cf2016-02-29 09:14:51 +00002389 }
2390 }
2391 }
Alexandre Rames50518442016-06-27 11:39:19 +01002392
Igor Murashkin42691732017-06-26 15:57:31 -07002393 assertIntEquals(0, $noinline$runSmaliTestInt("AddSubConst", 1));
2394 assertIntEquals(3, $noinline$runSmaliTestInt("SubAddConst", 2));
2395 assertIntEquals(-16, $noinline$runSmaliTestInt("SubSubConst1", 3));
2396 assertIntEquals(-5, $noinline$runSmaliTestInt("SubSubConst2", 4));
2397 assertIntEquals(26, $noinline$runSmaliTestInt("SubSubConst3", 5));
Alexandre Rames50518442016-06-27 11:39:19 +01002398 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3));
2399 assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3 + 32));
Vladimir Marko7033d492017-09-28 16:32:24 +01002400 assertLongEquals(0xffffffffffffeaf3L,
2401 $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50));
2402 assertLongEquals(0xffffffffffffeaf3L,
2403 $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50 + 64));
Alexandre Rames50518442016-06-27 11:39:19 +01002404 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10));
2405 assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10 + 128));
Vladimir Marko7033d492017-09-28 16:32:24 +01002406 assertLongEquals(0xaf37bc048d159e24L,
2407 $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2));
2408 assertLongEquals(0xaf37bc048d159e24L,
2409 $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2 + 256));
Alexandre Rames50518442016-06-27 11:39:19 +01002410 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13));
2411 assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13 + 512));
Vladimir Marko7033d492017-09-28 16:32:24 +01002412 assertIntEquals(0x5f49eb48, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 2));
2413 assertIntEquals(0xbd4c29b0, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 3));
2414 assertIntEquals(0xc0fed1ca, $noinline$intNecessaryShiftModifications(0xabcdef01, 2));
2415 assertIntEquals(0x03578ebc, $noinline$intNecessaryShiftModifications(0xabcdef01, 3));
Maxim Kazantsevd3278bd2016-07-12 15:55:33 +06002416
2417 assertIntEquals(654321, $noinline$intAddSubSimplifyArg1(arg, 654321));
2418 assertIntEquals(arg, $noinline$intAddSubSimplifyArg2(arg, 654321));
2419 assertIntEquals(arg, $noinline$intSubAddSimplifyLeft(arg, 654321));
2420 assertIntEquals(arg, $noinline$intSubAddSimplifyRight(arg, 654321));
2421 assertFloatEquals(654321.125f, $noinline$floatAddSubSimplifyArg1(floatArg, 654321.125f));
2422 assertFloatEquals(floatArg, $noinline$floatAddSubSimplifyArg2(floatArg, 654321.125f));
2423 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyLeft(floatArg, 654321.125f));
2424 assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyRight(floatArg, 654321.125f));
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002425 }
Mark Mendellf6529172015-11-17 11:16:56 -05002426
David Brazdilf02c3cf2016-02-29 09:14:51 +00002427 private static boolean $inline$true() { return true; }
2428 private static boolean $inline$false() { return false; }
2429
Mark Mendellf6529172015-11-17 11:16:56 -05002430 public static boolean booleanField;
Alexandre Ramesb2fd7bc2015-03-11 16:48:16 +00002431}