xref: /aosp_15_r20/art/test/458-checker-instruct-simplification/src/Main.java (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1 /*
2  * 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  */
16 
17 import java.lang.reflect.Method;
18 
19 public class Main {
20 
assertBooleanEquals(boolean expected, boolean result)21   public static void assertBooleanEquals(boolean expected, boolean result) {
22     if (expected != result) {
23       throw new Error("Expected: " + expected + ", found: " + result);
24     }
25   }
26 
assertIntEquals(int expected, int result)27   public static void assertIntEquals(int expected, int result) {
28     if (expected != result) {
29       throw new Error("Expected: " + expected + ", found: " + result);
30     }
31   }
32 
assertLongEquals(long expected, long result)33   public static void assertLongEquals(long expected, long result) {
34     if (expected != result) {
35       throw new Error("Expected: " + expected + ", found: " + result);
36     }
37   }
38 
assertFloatEquals(float expected, float result)39   public static void assertFloatEquals(float expected, float result) {
40     if (expected != result) {
41       throw new Error("Expected: " + expected + ", found: " + result);
42     }
43   }
44 
assertDoubleEquals(double expected, double result)45   public static void assertDoubleEquals(double expected, double result) {
46     if (expected != result) {
47       throw new Error("Expected: " + expected + ", found: " + result);
48     }
49   }
50 
assertStringEquals(String expected, String result)51   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 
57   /**
58    * Tiny programs exercising optimizations of arithmetic identities.
59    */
60 
61   /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (before)
62   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
63   /// CHECK-DAG:     <<Const0:j\d+>>  LongConstant 0
64   /// CHECK-DAG:     <<Add:j\d+>>     Add [<<Const0>>,<<Arg>>]
65   /// CHECK-DAG:                      Return [<<Add>>]
66 
67   /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
68   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
69   /// CHECK-DAG:                      Return [<<Arg>>]
70 
71   /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
72   /// CHECK-NOT:                        Add
73 
$noinline$Add0(long arg)74   public static long $noinline$Add0(long arg) {
75     return 0 + arg;
76   }
77 
78   /// 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 
$noinline$AddAddSubAddConst(int arg)96   public static int $noinline$AddAddSubAddConst(int arg) {
97     return arg + 1 + 2 - 3 + 4;
98   }
99 
100   /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (before)
101   /// 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>>]
105 
106   /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
107   /// CHECK-DAG:     <<Arg:i\d+>>     ParameterValue
108   /// CHECK-DAG:                      Return [<<Arg>>]
109 
110   /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
111   /// CHECK-NOT:                      And
112 
$noinline$AndAllOnes(int arg)113   public static int $noinline$AndAllOnes(int arg) {
114     return arg & -1;
115   }
116 
117   /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (before)
118   /// 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 
125   /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
126   /// 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 
131   /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
132   /// CHECK-NOT:                       And
133 
$noinline$UShr28And15(int arg)134   public static int $noinline$UShr28And15(int arg) {
135     return (arg >>> 28) & 15;
136   }
137 
138   /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (before)
139   /// 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 
146   /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
147   /// 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 
152   /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
153   /// CHECK-NOT:                       And
154 
$noinline$UShr60And15(long arg)155   public static long $noinline$UShr60And15(long arg) {
156     return (arg >>> 60) & 15;
157   }
158 
159   /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (before)
160   /// 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 
167   /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (after)
168   /// 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 
$noinline$UShr28And7(int arg)175   public static int $noinline$UShr28And7(int arg) {
176     return (arg >>> 28) & 7;
177   }
178 
179   /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (before)
180   /// 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 
187   /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (after)
188   /// 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 
$noinline$UShr60And7(long arg)195   public static long $noinline$UShr60And7(long arg) {
196     return (arg >>> 60) & 7;
197   }
198 
199   /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (before)
200   /// 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 
207   /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
208   /// 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 
213   /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
214   /// CHECK-NOT:                       Shr
215   /// CHECK-NOT:                       And
216 
$noinline$Shr24And255(int arg)217   public static int $noinline$Shr24And255(int arg) {
218     return (arg >> 24) & 255;
219   }
220 
221   /// CHECK-START: int Main.$noinline$Shr25And127(int) instruction_simplifier (before)
222   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
223   /// CHECK-DAG:     <<Const25:i\d+>>  IntConstant 25
224   /// CHECK-DAG:     <<Const127:i\d+>> IntConstant 127
225   /// CHECK-DAG:     <<Shr:i\d+>>      Shr [<<Arg>>,<<Const25>>]
226   /// CHECK-DAG:     <<And:i\d+>>      And [<<Shr>>,<<Const127>>]
227   /// CHECK-DAG:                       Return [<<And>>]
228 
229   /// CHECK-START: int Main.$noinline$Shr25And127(int) instruction_simplifier (after)
230   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
231   /// CHECK-DAG:     <<Const25:i\d+>>  IntConstant 25
232   /// CHECK-DAG:     <<UShr:i\d+>>     UShr [<<Arg>>,<<Const25>>]
233   /// CHECK-DAG:                       Return [<<UShr>>]
234 
235   /// CHECK-START: int Main.$noinline$Shr25And127(int) instruction_simplifier (after)
236   /// CHECK-NOT:                       Shr
237   /// CHECK-NOT:                       And
238 
$noinline$Shr25And127(int arg)239   public static int $noinline$Shr25And127(int arg) {
240     return (arg >> 25) & 127;
241   }
242 
243   /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (before)
244   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
245   /// CHECK-DAG:     <<Const56:i\d+>>  IntConstant 56
246   /// CHECK-DAG:     <<Const255:j\d+>> LongConstant 255
247   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const56>>]
248   /// CHECK-DAG:     <<And:j\d+>>      And [<<Shr>>,<<Const255>>]
249   /// CHECK-DAG:                       Return [<<And>>]
250 
251   /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
252   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
253   /// CHECK-DAG:     <<Const56:i\d+>>  IntConstant 56
254   /// CHECK-DAG:     <<UShr:j\d+>>     UShr [<<Arg>>,<<Const56>>]
255   /// CHECK-DAG:                       Return [<<UShr>>]
256 
257   /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
258   /// CHECK-NOT:                       Shr
259   /// CHECK-NOT:                       And
260 
$noinline$Shr56And255(long arg)261   public static long $noinline$Shr56And255(long arg) {
262     return (arg >> 56) & 255;
263   }
264 
265   /// CHECK-START: long Main.$noinline$Shr57And127(long) instruction_simplifier (before)
266   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
267   /// CHECK-DAG:     <<Const57:i\d+>>  IntConstant 57
268   /// CHECK-DAG:     <<Const127:j\d+>> LongConstant 127
269   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const57>>]
270   /// CHECK-DAG:     <<And:j\d+>>      And [<<Shr>>,<<Const127>>]
271   /// CHECK-DAG:                       Return [<<And>>]
272 
273   /// CHECK-START: long Main.$noinline$Shr57And127(long) instruction_simplifier (after)
274   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
275   /// CHECK-DAG:     <<Const57:i\d+>>  IntConstant 57
276   /// CHECK-DAG:     <<UShr:j\d+>>     UShr [<<Arg>>,<<Const57>>]
277   /// CHECK-DAG:                       Return [<<UShr>>]
278 
279   /// CHECK-START: long Main.$noinline$Shr57And127(long) instruction_simplifier (after)
280   /// CHECK-NOT:                       Shr
281   /// CHECK-NOT:                       And
282 
$noinline$Shr57And127(long arg)283   public static long $noinline$Shr57And127(long arg) {
284     return (arg >> 57) & 127;
285   }
286 
287   /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (before)
288   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
289   /// CHECK-DAG:     <<Const24:i\d+>>  IntConstant 24
290   /// CHECK-DAG:     <<Const127:i\d+>> IntConstant 127
291   /// CHECK-DAG:     <<Shr:i\d+>>      Shr [<<Arg>>,<<Const24>>]
292   /// CHECK-DAG:     <<And:i\d+>>      And [<<Shr>>,<<Const127>>]
293   /// CHECK-DAG:                       Return [<<And>>]
294 
295   /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (after)
296   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
297   /// CHECK-DAG:     <<Const24:i\d+>>  IntConstant 24
298   /// CHECK-DAG:     <<Const127:i\d+>> IntConstant 127
299   /// CHECK-DAG:     <<Shr:i\d+>>      Shr [<<Arg>>,<<Const24>>]
300   /// CHECK-DAG:     <<And:i\d+>>      And [<<Shr>>,<<Const127>>]
301   /// CHECK-DAG:                       Return [<<And>>]
302 
$noinline$Shr24And127(int arg)303   public static int $noinline$Shr24And127(int arg) {
304     return (arg >> 24) & 127;
305   }
306 
307   /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (before)
308   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
309   /// CHECK-DAG:     <<Const56:i\d+>>  IntConstant 56
310   /// CHECK-DAG:     <<Const127:j\d+>> LongConstant 127
311   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const56>>]
312   /// CHECK-DAG:     <<And:j\d+>>      And [<<Shr>>,<<Const127>>]
313   /// CHECK-DAG:                       Return [<<And>>]
314 
315   /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (after)
316   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
317   /// CHECK-DAG:     <<Const56:i\d+>>  IntConstant 56
318   /// CHECK-DAG:     <<Const127:j\d+>> LongConstant 127
319   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const56>>]
320   /// CHECK-DAG:     <<And:j\d+>>      And [<<Shr>>,<<Const127>>]
321   /// CHECK-DAG:                       Return [<<And>>]
322 
$noinline$Shr56And127(long arg)323   public static long $noinline$Shr56And127(long arg) {
324     return (arg >> 56) & 127;
325   }
326 
327   /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (before)
328   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
329   /// CHECK-DAG:     <<Const1:j\d+>>  LongConstant 1
330   /// CHECK-DAG:     <<Div:j\d+>>     Div [<<Arg>>,<<Const1>>]
331   /// CHECK-DAG:                      Return [<<Div>>]
332 
333   /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
334   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
335   /// CHECK-DAG:                      Return [<<Arg>>]
336 
337   /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
338   /// CHECK-NOT:                      Div
339 
$noinline$Div1(long arg)340   public static long $noinline$Div1(long arg) {
341     return arg / 1;
342   }
343 
344   /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (before)
345   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
346   /// CHECK-DAG:     <<ConstN1:i\d+>>  IntConstant -1
347   /// CHECK-DAG:     <<Div:i\d+>>      Div [<<Arg>>,<<ConstN1>>]
348   /// CHECK-DAG:                       Return [<<Div>>]
349 
350   /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
351   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
352   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg>>]
353   /// CHECK-DAG:                       Return [<<Neg>>]
354 
355   /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
356   /// CHECK-NOT:                       Div
357 
$noinline$DivN1(int arg)358   public static int $noinline$DivN1(int arg) {
359     return arg / -1;
360   }
361 
362   /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (before)
363   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
364   /// CHECK-DAG:     <<Const1:j\d+>>  LongConstant 1
365   /// CHECK-DAG:     <<Mul:j\d+>>     Mul [<<Const1>>,<<Arg>>]
366   /// CHECK-DAG:                      Return [<<Mul>>]
367 
368   /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
369   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
370   /// CHECK-DAG:                      Return [<<Arg>>]
371 
372   /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
373   /// CHECK-NOT:                       Mul
374 
$noinline$Mul1(long arg)375   public static long $noinline$Mul1(long arg) {
376     return arg * 1;
377   }
378 
379   /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (before)
380   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
381   /// CHECK-DAG:     <<ConstN1:i\d+>>  IntConstant -1
382   /// CHECK-DAG:     <<Mul:i\d+>>      Mul [<<Arg>>,<<ConstN1>>]
383   /// CHECK-DAG:                       Return [<<Mul>>]
384 
385   /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
386   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
387   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg>>]
388   /// CHECK-DAG:                       Return [<<Neg>>]
389 
390   /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
391   /// CHECK-NOT:                       Mul
392 
$noinline$MulN1(int arg)393   public static int $noinline$MulN1(int arg) {
394     return arg * -1;
395   }
396 
397   /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (before)
398   /// CHECK-DAG:     <<Arg:j\d+>>       ParameterValue
399   /// CHECK-DAG:     <<Const128:j\d+>>  LongConstant 128
400   /// CHECK-DAG:     <<Mul:j\d+>>       Mul [<<Const128>>,<<Arg>>]
401   /// CHECK-DAG:                        Return [<<Mul>>]
402 
403   /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
404   /// CHECK-DAG:     <<Arg:j\d+>>       ParameterValue
405   /// CHECK-DAG:     <<Const7:i\d+>>    IntConstant 7
406   /// CHECK-DAG:     <<Shl:j\d+>>       Shl [<<Arg>>,<<Const7>>]
407   /// CHECK-DAG:                        Return [<<Shl>>]
408 
409   /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
410   /// CHECK-NOT:                        Mul
411 
$noinline$MulPowerOfTwo128(long arg)412   public static long $noinline$MulPowerOfTwo128(long arg) {
413     return arg * 128;
414   }
415 
416   /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (before)
417   /// CHECK-DAG:     <<ArgValue:j\d+>>  ParameterValue
418   /// CHECK-DAG:     <<Const10:j\d+>>   LongConstant 10
419   /// CHECK-DAG:     <<Const11:j\d+>>   LongConstant 11
420   /// CHECK-DAG:     <<Const12:j\d+>>   LongConstant 12
421   /// CHECK-DAG:     <<Mul1:j\d+>>      Mul [<<Const10>>,<<ArgValue>>]
422   /// CHECK-DAG:     <<Mul2:j\d+>>      Mul [<<Mul1>>,<<Const11>>]
423   /// CHECK-DAG:     <<Mul3:j\d+>>      Mul [<<Mul2>>,<<Const12>>]
424   /// CHECK-DAG:                        Return [<<Mul3>>]
425 
426   /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (after)
427   /// CHECK-DAG:     <<ArgValue:j\d+>>   ParameterValue
428   /// CHECK-DAG:     <<Const1320:j\d+>>  LongConstant 1320
429   /// CHECK-DAG:     <<Mul:j\d+>>        Mul [<<ArgValue>>,<<Const1320>>]
430   /// CHECK-DAG:                         Return [<<Mul>>]
431 
$noinline$MulMulMulConst(long arg)432   public static long $noinline$MulMulMulConst(long arg) {
433     return 10 * arg * 11 * 12;
434   }
435 
436   /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (before)
437   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
438   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
439   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Arg>>,<<Const0>>]
440   /// CHECK-DAG:                       Return [<<Or>>]
441 
442   /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
443   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
444   /// CHECK-DAG:                       Return [<<Arg>>]
445 
446   /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
447   /// CHECK-NOT:                       Or
448 
$noinline$Or0(int arg)449   public static int $noinline$Or0(int arg) {
450     return arg | 0;
451   }
452 
453   /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (before)
454   /// CHECK-DAG:     <<Arg:j\d+>>       ParameterValue
455   /// CHECK-DAG:     <<Or:j\d+>>        Or [<<Arg>>,<<Arg>>]
456   /// CHECK-DAG:                        Return [<<Or>>]
457 
458   /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
459   /// CHECK-DAG:     <<Arg:j\d+>>       ParameterValue
460   /// CHECK-DAG:                        Return [<<Arg>>]
461 
462   /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
463   /// CHECK-NOT:                        Or
464 
$noinline$OrSame(long arg)465   public static long $noinline$OrSame(long arg) {
466     return arg | arg;
467   }
468 
469   /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (before)
470   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
471   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
472   /// CHECK-DAG:     <<Shl:i\d+>>      Shl [<<Arg>>,<<Const0>>]
473   /// CHECK-DAG:                       Return [<<Shl>>]
474 
475   /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
476   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
477   /// CHECK-DAG:                       Return [<<Arg>>]
478 
479   /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
480   /// CHECK-NOT:                       Shl
481 
$noinline$Shl0(int arg)482   public static int $noinline$Shl0(int arg) {
483     return arg << 0;
484   }
485 
486   /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (before)
487   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
488   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
489   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const0>>]
490   /// CHECK-DAG:                       Return [<<Shr>>]
491 
492   /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
493   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
494   /// CHECK-DAG:                       Return [<<Arg>>]
495 
496   /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
497   /// CHECK-NOT:                       Shr
498 
$noinline$Shr0(long arg)499   public static long $noinline$Shr0(long arg) {
500     return arg >> 0;
501   }
502 
503   /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (before)
504   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
505   /// CHECK-DAG:     <<Const64:i\d+>>  IntConstant 64
506   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const64>>]
507   /// CHECK-DAG:                       Return [<<Shr>>]
508 
509   /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
510   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
511   /// CHECK-DAG:                       Return [<<Arg>>]
512 
513   /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
514   /// CHECK-NOT:                       Shr
515 
$noinline$Shr64(long arg)516   public static long $noinline$Shr64(long arg) {
517     return arg >> 64;
518   }
519 
520   /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (before)
521   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
522   /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
523   /// CHECK-DAG:     <<Sub:j\d+>>      Sub [<<Arg>>,<<Const0>>]
524   /// CHECK-DAG:                       Return [<<Sub>>]
525 
526   /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
527   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
528   /// CHECK-DAG:                       Return [<<Arg>>]
529 
530   /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
531   /// CHECK-NOT:                       Sub
532 
$noinline$Sub0(long arg)533   public static long $noinline$Sub0(long arg) {
534     return arg - 0;
535   }
536 
537   /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (before)
538   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
539   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
540   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Const0>>,<<Arg>>]
541   /// CHECK-DAG:                       Return [<<Sub>>]
542 
543   /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
544   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
545   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg>>]
546   /// CHECK-DAG:                       Return [<<Neg>>]
547 
548   /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
549   /// CHECK-NOT:                       Sub
550 
$noinline$SubAliasNeg(int arg)551   public static int $noinline$SubAliasNeg(int arg) {
552     return 0 - arg;
553   }
554 
555   /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (before)
556   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
557   /// CHECK-DAG:     <<Const5:i\d+>>    IntConstant 5
558   /// CHECK-DAG:     <<Const6:i\d+>>    IntConstant 6
559   /// CHECK-DAG:     <<Sub:i\d+>>       Sub [<<Const5>>,<<ArgValue>>]
560   /// CHECK-DAG:     <<Add:i\d+>>       Add [<<Sub>>,<<Const6>>]
561   /// CHECK-DAG:                        Return [<<Add>>]
562 
563   /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (after)
564   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
565   /// CHECK-DAG:     <<Const11:i\d+>>   IntConstant 11
566   /// CHECK-DAG:     <<Sub:i\d+>>       Sub [<<Const11>>,<<ArgValue>>]
567   /// CHECK-DAG:                        Return [<<Sub>>]
568 
$noinline$SubAddConst1(int arg)569   public static int $noinline$SubAddConst1(int arg) {
570     return 5 - arg + 6;
571   }
572 
573   /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (before)
574   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
575   /// CHECK-DAG:     <<Const14:i\d+>>   IntConstant 14
576   /// CHECK-DAG:     <<Const13:i\d+>>   IntConstant 13
577   /// CHECK-DAG:     <<Add:i\d+>>       Add [<<ArgValue>>,<<Const13>>]
578   /// CHECK-DAG:     <<Sub:i\d+>>       Sub [<<Const14>>,<<Add>>]
579   /// CHECK-DAG:                        Return [<<Sub>>]
580 
581   /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (after)
582   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
583   /// CHECK-DAG:     <<Const1:i\d+>>    IntConstant 1
584   /// CHECK-DAG:     <<Sub:i\d+>>       Sub [<<Const1>>,<<ArgValue>>]
585   /// CHECK-DAG:                        Return [<<Sub>>]
586 
$noinline$SubAddConst2(int arg)587   public static int $noinline$SubAddConst2(int arg) {
588     return 14 - (arg + 13);
589   }
590 
591   /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (before)
592   /// CHECK-DAG:     <<ArgValue:j\d+>>  ParameterValue
593   /// CHECK-DAG:     <<Const17:j\d+>>   LongConstant 17
594   /// CHECK-DAG:     <<Const18:j\d+>>   LongConstant 18
595   /// CHECK-DAG:     <<Sub1:j\d+>>      Sub [<<Const18>>,<<ArgValue>>]
596   /// CHECK-DAG:     <<Sub2:j\d+>>      Sub [<<Const17>>,<<Sub1>>]
597   /// CHECK-DAG:                        Return [<<Sub2>>]
598 
599   /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (after)
600   /// CHECK-DAG:     <<ArgValue:j\d+>>  ParameterValue
601   /// CHECK-DAG:     <<ConstM1:j\d+>>   LongConstant -1
602   /// CHECK-DAG:     <<Add:j\d+>>       Add [<<ArgValue>>,<<ConstM1>>]
603   /// CHECK-DAG:                        Return [<<Add>>]
604 
$noinline$SubSubConst(long arg)605   public static long $noinline$SubSubConst(long arg) {
606     return 17 - (18 - arg);
607   }
608 
609   /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (before)
610   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
611   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
612   /// CHECK-DAG:     <<UShr:j\d+>>     UShr [<<Arg>>,<<Const0>>]
613   /// CHECK-DAG:                       Return [<<UShr>>]
614 
615   /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
616   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
617   /// CHECK-DAG:                       Return [<<Arg>>]
618 
619   /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
620   /// CHECK-NOT:                       UShr
621 
$noinline$UShr0(long arg)622   public static long $noinline$UShr0(long arg) {
623     return arg >>> 0;
624   }
625 
626   /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (before)
627   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
628   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
629   /// CHECK-DAG:     <<Xor:i\d+>>      Xor [<<Arg>>,<<Const0>>]
630   /// CHECK-DAG:                       Return [<<Xor>>]
631 
632   /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
633   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
634   /// CHECK-DAG:                       Return [<<Arg>>]
635 
636   /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
637   /// CHECK-NOT:                       Xor
638 
$noinline$Xor0(int arg)639   public static int $noinline$Xor0(int arg) {
640     return arg ^ 0;
641   }
642 
643   /**
644    * Test that addition or subtraction operation with both inputs negated are
645    * optimized to use a single negation after the operation.
646    * The transformation tested is implemented in
647    * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
648    */
649 
650   /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (before)
651   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
652   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
653   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg1>>]
654   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Arg2>>]
655   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Neg1>>,<<Neg2>>]
656   /// CHECK-DAG:                       Return [<<Add>>]
657 
658   /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (after)
659   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
660   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
661   /// CHECK-NOT:                       Neg
662   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Arg1>>,<<Arg2>>]
663   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Add>>]
664   /// CHECK-DAG:                       Return [<<Neg>>]
665 
$noinline$AddNegs1(int arg1, int arg2)666   public static int $noinline$AddNegs1(int arg1, int arg2) {
667     return -arg1 + -arg2;
668   }
669 
670   /**
671    * This is similar to the test-case AddNegs1, but the negations have
672    * multiple uses.
673    * The transformation tested is implemented in
674    * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
675    * The current code won't perform the previous optimization. The
676    * transformations do not look at other uses of their inputs. As they don't
677    * know what will happen with other uses, they do not take the risk of
678    * increasing the register pressure by creating or extending live ranges.
679    */
680 
681   /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (before)
682   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
683   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
684   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg1>>]
685   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Arg2>>]
686   /// CHECK-DAG:     <<Add1:i\d+>>     Add [<<Neg1>>,<<Neg2>>]
687   /// CHECK-DAG:     <<Add2:i\d+>>     Add [<<Neg1>>,<<Neg2>>]
688   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Add1>>,<<Add2>>]
689   /// CHECK-DAG:                       Return [<<Or>>]
690 
691   /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (after)
692   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
693   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
694   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg1>>]
695   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Arg2>>]
696   /// CHECK-DAG:     <<Add1:i\d+>>     Add [<<Neg1>>,<<Neg2>>]
697   /// CHECK-DAG:     <<Add2:i\d+>>     Add [<<Neg1>>,<<Neg2>>]
698   /// CHECK-NOT:                       Neg
699   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Add1>>,<<Add2>>]
700   /// CHECK-DAG:                       Return [<<Or>>]
701 
702   /// CHECK-START: int Main.$noinline$AddNegs2(int, int) GVN (after)
703   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
704   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
705   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg1>>]
706   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Arg2>>]
707   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Neg1>>,<<Neg2>>]
708   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Add>>,<<Add>>]
709   /// CHECK-DAG:                       Return [<<Or>>]
710 
$noinline$AddNegs2(int arg1, int arg2)711   public static int $noinline$AddNegs2(int arg1, int arg2) {
712     int temp1 = -arg1;
713     int temp2 = -arg2;
714     return (temp1 + temp2) | (temp1 + temp2);
715   }
716 
717   /**
718    * This follows test-cases AddNegs1 and AddNegs2.
719    * The transformation tested is implemented in
720    * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
721    * The optimization should not happen if it moves an additional instruction in
722    * the loop.
723    */
724 
725   /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (before)
726   //  -------------- Arguments and initial negation operations.
727   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
728   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
729   /// CHECK-DAG:     <<Neg1:j\d+>>     Neg [<<Arg1>>]
730   /// CHECK-DAG:     <<Neg2:j\d+>>     Neg [<<Arg2>>]
731   /// CHECK:                           Goto
732   //  -------------- Loop
733   /// CHECK:                           SuspendCheck
734   /// CHECK:         <<Add:j\d+>>      Add [<<Neg1>>,<<Neg2>>]
735   /// CHECK:                           Goto
736 
737   /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (after)
738   //  -------------- Arguments and initial negation operations.
739   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
740   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
741   /// CHECK-DAG:     <<Neg1:j\d+>>     Neg [<<Arg1>>]
742   /// CHECK-DAG:     <<Neg2:j\d+>>     Neg [<<Arg2>>]
743   /// CHECK:                           Goto
744   //  -------------- Loop
745   /// CHECK:                           SuspendCheck
746   /// CHECK:         <<Add:j\d+>>      Add [<<Neg1>>,<<Neg2>>]
747   /// CHECK-NOT:                       Neg
748   /// CHECK:                           Goto
749 
$noinline$AddNegs3(long arg1, long arg2)750   public static long $noinline$AddNegs3(long arg1, long arg2) {
751     long res = 0;
752     long n_arg1 = -arg1;
753     long n_arg2 = -arg2;
754     for (long i = 0; i < 1; i++) {
755       res += n_arg1 + n_arg2 + i;
756     }
757     return res;
758   }
759 
760   /**
761    * Test the simplification of an addition with a negated argument into a
762    * subtraction.
763    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
764    */
765 
766   /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (before)
767   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
768   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
769   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg1>>]
770   /// CHECK-DAG:     <<Add:j\d+>>      Add [<<Neg>>,<<Arg2>>]
771   /// CHECK-DAG:                       Return [<<Add>>]
772 
773   /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
774   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
775   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
776   /// CHECK-DAG:     <<Sub:j\d+>>      Sub [<<Arg2>>,<<Arg1>>]
777   /// CHECK-DAG:                       Return [<<Sub>>]
778 
779   /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
780   /// CHECK-NOT:                       Neg
781   /// CHECK-NOT:                       Add
782 
$noinline$AddNeg1(long arg1, long arg2)783   public static long $noinline$AddNeg1(long arg1, long arg2) {
784     return -arg1 + arg2;
785   }
786 
787   /**
788    * This is similar to the test-case AddNeg1, but the negation has two uses.
789    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
790    * The current code won't perform the previous optimization. The
791    * transformations do not look at other uses of their inputs. As they don't
792    * know what will happen with other uses, they do not take the risk of
793    * increasing the register pressure by creating or extending live ranges.
794    */
795 
796   /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (before)
797   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
798   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
799   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg2>>]
800   /// CHECK-DAG:     <<Add1:j\d+>>     Add [<<Arg1>>,<<Neg>>]
801   /// CHECK-DAG:     <<Add2:j\d+>>     Add [<<Arg1>>,<<Neg>>]
802   /// CHECK-DAG:     <<Res:j\d+>>      Or [<<Add1>>,<<Add2>>]
803   /// CHECK-DAG:                       Return [<<Res>>]
804 
805   /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
806   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
807   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
808   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg2>>]
809   /// CHECK-DAG:     <<Add1:j\d+>>     Add [<<Arg1>>,<<Neg>>]
810   /// CHECK-DAG:     <<Add2:j\d+>>     Add [<<Arg1>>,<<Neg>>]
811   /// CHECK-DAG:     <<Res:j\d+>>      Or [<<Add1>>,<<Add2>>]
812   /// CHECK-DAG:                       Return [<<Res>>]
813 
814   /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
815   /// CHECK-NOT:                       Sub
816 
$noinline$AddNeg2(long arg1, long arg2)817   public static long $noinline$AddNeg2(long arg1, long arg2) {
818     long temp = -arg2;
819     return (arg1 + temp) | (arg1 + temp);
820   }
821 
822   /**
823    * Test simplification of the `-(-var)` pattern.
824    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
825    */
826 
827   /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (before)
828   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
829   /// CHECK-DAG:     <<Neg1:j\d+>>     Neg [<<Arg>>]
830   /// CHECK-DAG:     <<Neg2:j\d+>>     Neg [<<Neg1>>]
831   /// CHECK-DAG:                       Return [<<Neg2>>]
832 
833   /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
834   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
835   /// CHECK-DAG:                       Return [<<Arg>>]
836 
837   /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
838   /// CHECK-NOT:                       Neg
839 
$noinline$NegNeg1(long arg)840   public static long $noinline$NegNeg1(long arg) {
841     return -(-arg);
842   }
843 
844   /**
845    * Test 'multi-step' simplification, where a first transformation yields a
846    * new simplification possibility for the current instruction.
847    * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
848    * and in `InstructionSimplifierVisitor::VisitAdd`.
849    */
850 
851   /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (before)
852   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
853   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg>>]
854   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Neg1>>]
855   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Neg2>>,<<Neg1>>]
856   /// CHECK-DAG:                       Return [<<Add>>]
857 
858   /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
859   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
860   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg>>,<<Arg>>]
861   /// CHECK-DAG:                       Return [<<Sub>>]
862 
863   /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
864   /// CHECK-NOT:                       Neg
865   /// CHECK-NOT:                       Add
866 
867   /// CHECK-START: int Main.$noinline$NegNeg2(int) constant_folding$after_gvn (after)
868   /// CHECK:         <<Const0:i\d+>>   IntConstant 0
869   /// CHECK-NOT:                       Neg
870   /// CHECK-NOT:                       Add
871   /// CHECK:                           Return [<<Const0>>]
872 
$noinline$NegNeg2(int arg)873   public static int $noinline$NegNeg2(int arg) {
874     int temp = -arg;
875     return temp + -temp;
876   }
877 
878   /**
879    * Test another 'multi-step' simplification, where a first transformation
880    * yields a new simplification possibility for the current instruction.
881    * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
882    * and in `InstructionSimplifierVisitor::VisitSub`.
883    */
884 
885   /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (before)
886   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
887   /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
888   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg>>]
889   /// CHECK-DAG:     <<Sub:j\d+>>      Sub [<<Const0>>,<<Neg>>]
890   /// CHECK-DAG:                       Return [<<Sub>>]
891 
892   /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
893   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
894   /// CHECK-DAG:                       Return [<<Arg>>]
895 
896   /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
897   /// CHECK-NOT:                       Neg
898   /// CHECK-NOT:                       Sub
899 
$noinline$NegNeg3(long arg)900   public static long $noinline$NegNeg3(long arg) {
901     return 0 - -arg;
902   }
903 
904   /**
905    * Test that a negated subtraction is simplified to a subtraction with its
906    * arguments reversed.
907    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
908    */
909 
910   /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (before)
911   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
912   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
913   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg1>>,<<Arg2>>]
914   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Sub>>]
915   /// CHECK-DAG:                       Return [<<Neg>>]
916 
917   /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
918   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
919   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
920   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg2>>,<<Arg1>>]
921   /// CHECK-DAG:                       Return [<<Sub>>]
922 
923   /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
924   /// CHECK-NOT:                       Neg
925 
$noinline$NegSub1(int arg1, int arg2)926   public static int $noinline$NegSub1(int arg1, int arg2) {
927     return -(arg1 - arg2);
928   }
929 
930   /**
931    * This is similar to the test-case NegSub1, but the subtraction has
932    * multiple uses.
933    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
934    * The current code won't perform the previous optimization. The
935    * transformations do not look at other uses of their inputs. As they don't
936    * know what will happen with other uses, they do not take the risk of
937    * increasing the register pressure by creating or extending live ranges.
938    */
939 
940   /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (before)
941   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
942   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
943   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg1>>,<<Arg2>>]
944   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Sub>>]
945   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Sub>>]
946   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Neg1>>,<<Neg2>>]
947   /// CHECK-DAG:                       Return [<<Or>>]
948 
949   /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (after)
950   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
951   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
952   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg1>>,<<Arg2>>]
953   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Sub>>]
954   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Sub>>]
955   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Neg1>>,<<Neg2>>]
956   /// CHECK-DAG:                       Return [<<Or>>]
957 
$noinline$NegSub2(int arg1, int arg2)958   public static int $noinline$NegSub2(int arg1, int arg2) {
959     int temp = arg1 - arg2;
960     return -temp | -temp;
961   }
962 
963     /**
964    * Test the simplification of a subtraction with a negated argument.
965    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
966    */
967 
968   /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (before)
969   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
970   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
971   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg1>>]
972   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Neg>>,<<Arg2>>]
973   /// CHECK-DAG:                       Return [<<Sub>>]
974 
975   /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
976   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
977   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
978   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Arg1>>,<<Arg2>>]
979   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Add>>]
980   /// CHECK-DAG:                       Return [<<Neg>>]
981 
982   /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
983   /// CHECK-NOT:                       Sub
984 
$noinline$SubNeg1(int arg1, int arg2)985   public static int $noinline$SubNeg1(int arg1, int arg2) {
986     return -arg1 - arg2;
987   }
988 
989   /**
990    * This is similar to the test-case SubNeg1, but the negation has
991    * multiple uses.
992    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
993    * The current code won't perform the previous optimization. The
994    * transformations do not look at other uses of their inputs. As they don't
995    * know what will happen with other uses, they do not take the risk of
996    * increasing the register pressure by creating or extending live ranges.
997    */
998 
999   /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (before)
1000   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
1001   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
1002   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg1>>]
1003   /// CHECK-DAG:     <<Sub1:i\d+>>     Sub [<<Neg>>,<<Arg2>>]
1004   /// CHECK-DAG:     <<Sub2:i\d+>>     Sub [<<Neg>>,<<Arg2>>]
1005   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Sub1>>,<<Sub2>>]
1006   /// CHECK-DAG:                       Return [<<Or>>]
1007 
1008   /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
1009   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
1010   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
1011   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg1>>]
1012   /// CHECK-DAG:     <<Sub1:i\d+>>     Sub [<<Neg>>,<<Arg2>>]
1013   /// CHECK-DAG:     <<Sub2:i\d+>>     Sub [<<Neg>>,<<Arg2>>]
1014   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Sub1>>,<<Sub2>>]
1015   /// CHECK-DAG:                       Return [<<Or>>]
1016 
1017   /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
1018   /// CHECK-NOT:                       Add
1019 
$noinline$SubNeg2(int arg1, int arg2)1020   public static int $noinline$SubNeg2(int arg1, int arg2) {
1021     int temp = -arg1;
1022     return (temp - arg2) | (temp - arg2);
1023   }
1024 
1025   /**
1026    * This follows test-cases SubNeg1 and SubNeg2.
1027    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1028    * The optimization should not happen if it moves an additional instruction in
1029    * the loop.
1030    */
1031 
1032   /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (before)
1033   //  -------------- Arguments and initial negation operation.
1034   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
1035   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
1036   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg1>>]
1037   /// CHECK:                           Goto
1038   //  -------------- Loop
1039   /// CHECK:                           SuspendCheck
1040   /// CHECK:         <<Sub:j\d+>>      Sub [<<Neg>>,<<Arg2>>]
1041   /// CHECK:                           Goto
1042 
1043   /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (after)
1044   //  -------------- Arguments and initial negation operation.
1045   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
1046   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
1047   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg1>>]
1048   /// CHECK-DAG:                       Goto
1049   //  -------------- Loop
1050   /// CHECK:                           SuspendCheck
1051   /// CHECK:         <<Sub:j\d+>>      Sub [<<Neg>>,<<Arg2>>]
1052   /// CHECK-NOT:                       Neg
1053   /// CHECK:                           Goto
1054 
$noinline$SubNeg3(long arg1, long arg2)1055   public static long $noinline$SubNeg3(long arg1, long arg2) {
1056     long res = 0;
1057     long temp = -arg1;
1058     for (long i = 0; i < 1; i++) {
1059       res += temp - arg2 - i;
1060     }
1061     return res;
1062   }
1063 
1064   /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) dead_code_elimination$after_inlining (before)
1065   /// CHECK-DAG:     <<Arg:z\d+>>      ParameterValue
1066   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1067   /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
1068   /// CHECK-DAG:     <<Const2:i\d+>>   IntConstant 2
1069   /// CHECK-DAG:                       If [<<Arg>>]
1070   /// CHECK-DAG:     <<Phi1:i\d+>>     Phi [<<Const0>>,<<Const1>>]
1071   /// CHECK-DAG:     <<Cond:z\d+>>     Equal [<<Phi1>>,<<Const2>>]
1072   /// CHECK-DAG:                       If [<<Cond>>]
1073   /// CHECK-DAG:     <<Phi2:i\d+>>     Phi [<<Const0>>,<<Const1>>]
1074   /// CHECK-DAG:                       Return [<<Phi2>>]
1075 
1076   /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) dead_code_elimination$after_inlining (after)
1077   /// CHECK-DAG:     <<True:i\d+>>     IntConstant 1
1078   /// CHECK-DAG:                       Return [<<True>>]
1079 
$noinline$EqualBoolVsIntConst(boolean arg)1080   public static boolean $noinline$EqualBoolVsIntConst(boolean arg) {
1081     // Make calls that will be inlined to make sure the instruction simplifier
1082     // sees the simplification (dead code elimination will also try to simplify it).
1083     return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) != 2;
1084   }
1085 
$inline$ReturnArg(int arg)1086   public static int $inline$ReturnArg(int arg) {
1087     return arg;
1088   }
1089 
1090   /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before)
1091   /// CHECK-DAG:     <<Arg:z\d+>>      ParameterValue
1092   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1093   /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
1094   /// CHECK-DAG:     <<Const2:i\d+>>   IntConstant 2
1095   /// CHECK-DAG:                       If [<<Arg>>]
1096   /// CHECK-DAG:     <<Phi1:i\d+>>     Phi [<<Const0>>,<<Const1>>]
1097   /// CHECK-DAG:     <<Cond:z\d+>>     NotEqual [<<Phi1>>,<<Const2>>]
1098   /// CHECK-DAG:                       If [<<Cond>>]
1099   /// CHECK-DAG:     <<Phi2:i\d+>>     Phi [<<Const0>>,<<Const1>>]
1100   /// CHECK-DAG:                       Return [<<Phi2>>]
1101 
1102   /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) dead_code_elimination$after_inlining (after)
1103   /// CHECK-DAG:     <<False:i\d+>>    IntConstant 0
1104   /// CHECK-DAG:                       Return [<<False>>]
1105 
$noinline$NotEqualBoolVsIntConst(boolean arg)1106   public static boolean $noinline$NotEqualBoolVsIntConst(boolean arg) {
1107     // Make calls that will be inlined to make sure the instruction simplifier
1108     // sees the simplification (dead code elimination will also try to simplify it).
1109     return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) == 2;
1110   }
1111 
1112   /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (before)
1113   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1114   /// CHECK-DAG:      <<Const2:f\d+>>   FloatConstant 2
1115   /// CHECK-DAG:      <<Div:f\d+>>      Div [<<Arg>>,<<Const2>>]
1116   /// CHECK-DAG:                        Return [<<Div>>]
1117 
1118   /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
1119   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1120   /// CHECK-DAG:      <<ConstP5:f\d+>>  FloatConstant 0.5
1121   /// CHECK-DAG:      <<Mul:f\d+>>      Mul [<<Arg>>,<<ConstP5>>]
1122   /// CHECK-DAG:                        Return [<<Mul>>]
1123 
1124   /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
1125   /// CHECK-NOT:                        Div
1126 
$noinline$Div2(float arg)1127   public static float $noinline$Div2(float arg) {
1128     return arg / 2.0f;
1129   }
1130 
1131   /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (before)
1132   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1133   /// CHECK-DAG:      <<Const2:d\d+>>   DoubleConstant 2
1134   /// CHECK-DAG:      <<Div:d\d+>>      Div [<<Arg>>,<<Const2>>]
1135   /// CHECK-DAG:                        Return [<<Div>>]
1136 
1137   /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
1138   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1139   /// CHECK-DAG:      <<ConstP5:d\d+>>  DoubleConstant 0.5
1140   /// CHECK-DAG:      <<Mul:d\d+>>      Mul [<<Arg>>,<<ConstP5>>]
1141   /// CHECK-DAG:                        Return [<<Mul>>]
1142 
1143   /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
1144   /// CHECK-NOT:                        Div
$noinline$Div2(double arg)1145   public static double $noinline$Div2(double arg) {
1146     return arg / 2.0;
1147   }
1148 
1149   /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (before)
1150   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1151   /// CHECK-DAG:      <<ConstMP25:f\d+>>   FloatConstant -0.25
1152   /// CHECK-DAG:      <<Div:f\d+>>      Div [<<Arg>>,<<ConstMP25>>]
1153   /// CHECK-DAG:                        Return [<<Div>>]
1154 
1155   /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
1156   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1157   /// CHECK-DAG:      <<ConstM4:f\d+>>  FloatConstant -4
1158   /// CHECK-DAG:      <<Mul:f\d+>>      Mul [<<Arg>>,<<ConstM4>>]
1159   /// CHECK-DAG:                        Return [<<Mul>>]
1160 
1161   /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
1162   /// CHECK-NOT:                        Div
1163 
$noinline$DivMP25(float arg)1164   public static float $noinline$DivMP25(float arg) {
1165     return arg / -0.25f;
1166   }
1167 
1168   /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (before)
1169   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1170   /// CHECK-DAG:      <<ConstMP25:d\d+>>   DoubleConstant -0.25
1171   /// CHECK-DAG:      <<Div:d\d+>>      Div [<<Arg>>,<<ConstMP25>>]
1172   /// CHECK-DAG:                        Return [<<Div>>]
1173 
1174   /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
1175   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1176   /// CHECK-DAG:      <<ConstM4:d\d+>>  DoubleConstant -4
1177   /// CHECK-DAG:      <<Mul:d\d+>>      Mul [<<Arg>>,<<ConstM4>>]
1178   /// CHECK-DAG:                        Return [<<Mul>>]
1179 
1180   /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
1181   /// CHECK-NOT:                        Div
$noinline$DivMP25(double arg)1182   public static double $noinline$DivMP25(double arg) {
1183     return arg / -0.25f;
1184   }
1185 
1186   /**
1187    * Test strength reduction of factors of the form (2^n + 1).
1188    */
1189 
1190   /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (before)
1191   /// CHECK-DAG:   <<Arg:i\d+>>         ParameterValue
1192   /// CHECK-DAG:   <<Const9:i\d+>>      IntConstant 9
1193   /// CHECK:                            Mul [<<Arg>>,<<Const9>>]
1194 
1195   /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (after)
1196   /// CHECK-DAG:   <<Arg:i\d+>>         ParameterValue
1197   /// CHECK-DAG:   <<Const3:i\d+>>      IntConstant 3
1198   /// CHECK:       <<Shift:i\d+>>       Shl [<<Arg>>,<<Const3>>]
1199   /// CHECK-NEXT:                       Add [<<Arg>>,<<Shift>>]
1200 
$noinline$mulPow2Plus1(int arg)1201   public static int $noinline$mulPow2Plus1(int arg) {
1202     return arg * 9;
1203   }
1204 
1205   /**
1206    * Test strength reduction of factors of the form (2^n - 1).
1207    */
1208 
1209   /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (before)
1210   /// CHECK-DAG:   <<Arg:j\d+>>         ParameterValue
1211   /// CHECK-DAG:   <<Const31:j\d+>>     LongConstant 31
1212   /// CHECK:                            Mul [<<Const31>>,<<Arg>>]
1213 
1214   /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (after)
1215   /// CHECK-DAG:   <<Arg:j\d+>>         ParameterValue
1216   /// CHECK-DAG:   <<Const5:i\d+>>      IntConstant 5
1217   /// CHECK:       <<Shift:j\d+>>       Shl [<<Arg>>,<<Const5>>]
1218   /// CHECK-NEXT:                       Sub [<<Shift>>,<<Arg>>]
1219 
$noinline$mulPow2Minus1(long arg)1220   public static long $noinline$mulPow2Minus1(long arg) {
1221     return arg * 31;
1222   }
1223 
1224   /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (before)
1225   /// CHECK-DAG:      <<Const1:i\d+>>   IntConstant 1
1226   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1227   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1228   /// CHECK-DAG:      <<Field:z\d+>>    StaticFieldGet
1229   /// CHECK-DAG:      <<NE:z\d+>>       NotEqual [<<Field>>,<<Const1>>]
1230   /// CHECK-DAG:                        If [<<NE>>]
1231   /// CHECK-DAG:      <<Phi:i\d+>>      Phi [<<Const13>>,<<Const54>>]
1232   /// CHECK-DAG:                        Return [<<Phi>>]
1233 
1234   /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() select_generator (after)
1235   /// CHECK-DAG:      <<Field:z\d+>>    StaticFieldGet
1236   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1237   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1238   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const54>>,<<Const13>>,<<Field>>]
1239   /// CHECK-DAG:                        Return [<<Select>>]
1240 
$noinline$booleanFieldNotEqualOne()1241   public static int $noinline$booleanFieldNotEqualOne() {
1242     return (booleanField == $inline$true()) ? 13 : 54;
1243   }
1244 
1245   /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (before)
1246   /// CHECK-DAG:      <<Const0:i\d+>>   IntConstant 0
1247   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1248   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1249   /// CHECK-DAG:      <<Field:z\d+>>    StaticFieldGet
1250   /// CHECK-DAG:      <<EQ:z\d+>>       Equal [<<Field>>,<<Const0>>]
1251   /// CHECK-DAG:                        If [<<EQ>>]
1252   /// CHECK-DAG:      <<Phi:i\d+>>      Phi [<<Const13>>,<<Const54>>]
1253   /// CHECK-DAG:                        Return [<<Phi>>]
1254 
1255   /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() select_generator (after)
1256   /// CHECK-DAG:      <<Field:z\d+>>    StaticFieldGet
1257   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1258   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1259   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const54>>,<<Const13>>,<<Field>>]
1260   /// CHECK-DAG:                        Return [<<Select>>]
1261 
$noinline$booleanFieldEqualZero()1262   public static int $noinline$booleanFieldEqualZero() {
1263     return (booleanField != $inline$false()) ? 13 : 54;
1264   }
1265 
1266   /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (before)
1267   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1268   /// CHECK-DAG:      <<Const0:i\d+>>   IntConstant 0
1269   /// CHECK-DAG:      <<Const1:i\d+>>   IntConstant 1
1270   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1271   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1272   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1273   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1274   /// CHECK-DAG:                        If [<<LE>>]
1275   /// CHECK-DAG:      <<Phi1:i\d+>>     Phi [<<Const1>>,<<Const0>>]
1276   /// CHECK-DAG:      <<NE:z\d+>>       NotEqual [<<Phi1>>,<<Const1>>]
1277   /// CHECK-DAG:                        If [<<NE>>]
1278   /// CHECK-DAG:      <<Phi2:i\d+>>     Phi [<<Const13>>,<<Const54>>]
1279   /// CHECK-DAG:                        Return [<<Phi2>>]
1280 
1281   /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) select_generator (after)
1282   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1283   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1284   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1285   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1286   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1287   /// CHECK-DAG:      <<Result:i\d+>>   Select [<<Const13>>,<<Const54>>,<<LE>>]
1288   /// CHECK-DAG:                        Return [<<Result>>]
1289   // Note that we match `LE` from Select because there are two identical
1290   // LessThanOrEqual instructions.
1291 
$noinline$intConditionNotEqualOne(int i)1292   public static int $noinline$intConditionNotEqualOne(int i) {
1293     return ((i > 42) == $inline$true()) ? 13 : 54;
1294   }
1295 
1296   /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (before)
1297   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1298   /// CHECK-DAG:      <<Const0:i\d+>>   IntConstant 0
1299   /// CHECK-DAG:      <<Const1:i\d+>>   IntConstant 1
1300   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1301   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1302   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1303   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1304   /// CHECK-DAG:                        If [<<LE>>]
1305   /// CHECK-DAG:      <<Phi1:i\d+>>     Phi [<<Const1>>,<<Const0>>]
1306   /// CHECK-DAG:      <<EQ:z\d+>>       Equal [<<Phi1>>,<<Const0>>]
1307   /// CHECK-DAG:                        If [<<EQ>>]
1308   /// CHECK-DAG:      <<Phi2:i\d+>>     Phi [<<Const13>>,<<Const54>>]
1309   /// CHECK-DAG:                        Return [<<Phi2>>]
1310 
1311   /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) select_generator (after)
1312   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1313   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1314   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1315   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1316   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1317   /// CHECK-DAG:      <<Result:i\d+>>   Select [<<Const13>>,<<Const54>>,<<LE>>]
1318   /// CHECK-DAG:                        Return [<<Result>>]
1319   // Note that we match `LE` from Select because there are two identical
1320   // LessThanOrEqual instructions.
1321 
$noinline$intConditionEqualZero(int i)1322   public static int $noinline$intConditionEqualZero(int i) {
1323     return ((i > 42) != $inline$false()) ? 13 : 54;
1324   }
1325 
1326   // Test that conditions on float/double are not flipped.
1327 
1328   /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) builder (after)
1329   /// CHECK:                            LessThanOrEqual
1330 
1331   /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) instruction_simplifier$before_codegen (after)
1332   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1333   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1334   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1335   /// CHECK-DAG:      <<Const42:f\d+>>  FloatConstant 42
1336   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1337   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const13>>,<<Const54>>,<<LE>>]
1338   /// CHECK-DAG:                        Return [<<Select>>]
1339 
$noinline$floatConditionNotEqualOne(float f)1340   public static int $noinline$floatConditionNotEqualOne(float f) {
1341     return ((f > 42.0f) == true) ? 13 : 54;
1342   }
1343 
1344   /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) builder (after)
1345   /// CHECK:                            LessThanOrEqual
1346 
1347   /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) instruction_simplifier$before_codegen (after)
1348   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1349   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1350   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1351   /// CHECK-DAG:      <<Const42:d\d+>>  DoubleConstant 42
1352   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1353   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const13>>,<<Const54>>,<<LE>>]
1354   /// CHECK-DAG:                        Return [<<Select>>]
1355 
$noinline$doubleConditionEqualZero(double d)1356   public static int $noinline$doubleConditionEqualZero(double d) {
1357     return ((d > 42.0) != false) ? 13 : 54;
1358   }
1359 
1360   /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (before)
1361   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1362   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1363   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1364   /// CHECK-DAG:                        Return [<<Int>>]
1365 
1366   /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
1367   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1368   /// CHECK-DAG:                        Return [<<Arg>>]
1369 
1370   /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
1371   /// CHECK-NOT:                        TypeConversion
1372 
$noinline$intToDoubleToInt(int value)1373   public static int $noinline$intToDoubleToInt(int value) {
1374     // Lossless conversion followed by a conversion back.
1375     return (int) (double) value;
1376   }
1377 
1378   /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (before)
1379   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1380   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1381   /// CHECK-DAG:      {{i\d+}}          TypeConversion [<<Double>>]
1382 
1383   /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
1384   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1385   /// CHECK-DAG:      {{d\d+}}          TypeConversion [<<Arg>>]
1386 
1387   /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
1388   /// CHECK-DAG:                        TypeConversion
1389   /// CHECK-NOT:                        TypeConversion
1390 
$noinline$intToDoubleToIntPrint(int value)1391   public static String $noinline$intToDoubleToIntPrint(int value) {
1392     // Lossless conversion followed by a conversion back
1393     // with another use of the intermediate result.
1394     double d = (double) value;
1395     int i = (int) d;
1396     return "d=" + d + ", i=" + i;
1397   }
1398 
1399   /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (before)
1400   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
1401   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1402   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1403   /// CHECK-DAG:                        Return [<<Int>>]
1404 
1405   /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
1406   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
1407   /// CHECK-DAG:                        Return [<<Arg>>]
1408 
1409   /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
1410   /// CHECK-NOT:                        TypeConversion
1411 
$noinline$byteToDoubleToInt(byte value)1412   public static int $noinline$byteToDoubleToInt(byte value) {
1413     // Lossless conversion followed by another conversion, use implicit conversion.
1414     return (int) (double) value;
1415   }
1416 
1417   /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (before)
1418   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1419   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1420   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1421   /// CHECK-DAG:                        Return [<<Int>>]
1422 
1423   /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
1424   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1425   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1426   /// CHECK-DAG:                        Return [<<Int>>]
1427 
1428   /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
1429   /// CHECK-DAG:                        TypeConversion
1430   /// CHECK-NOT:                        TypeConversion
1431 
$noinline$floatToDoubleToInt(float value)1432   public static int $noinline$floatToDoubleToInt(float value) {
1433     // Lossless conversion followed by another conversion.
1434     return (int) (double) value;
1435   }
1436 
1437   /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (before)
1438   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1439   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1440   /// CHECK-DAG:      {{i\d+}}          TypeConversion [<<Double>>]
1441 
1442   /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (after)
1443   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1444   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1445   /// CHECK-DAG:      {{i\d+}}          TypeConversion [<<Double>>]
1446 
$noinline$floatToDoubleToIntPrint(float value)1447   public static String $noinline$floatToDoubleToIntPrint(float value) {
1448     // Lossless conversion followed by another conversion with
1449     // an extra use of the intermediate result.
1450     double d = (double) value;
1451     int i = (int) d;
1452     return "d=" + d + ", i=" + i;
1453   }
1454 
1455   /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (before)
1456   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
1457   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1458   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1459   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Int>>]
1460   /// CHECK-DAG:                        Return [<<Short>>]
1461 
1462   /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
1463   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
1464   /// CHECK-DAG:                        Return [<<Arg>>]
1465 
1466   /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
1467   /// CHECK-NOT:                        TypeConversion
1468 
$noinline$byteToDoubleToShort(byte value)1469   public static short $noinline$byteToDoubleToShort(byte value) {
1470     // Originally, this is byte->double->int->short. The first conversion is lossless,
1471     // so we merge this with the second one to byte->int which we omit as it's an implicit
1472     // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1473     return (short) (double) value;
1474   }
1475 
1476   /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (before)
1477   /// CHECK-DAG:      <<Arg:c\d+>>      ParameterValue
1478   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1479   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1480   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Int>>]
1481   /// CHECK-DAG:                        Return [<<Short>>]
1482 
1483   /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
1484   /// CHECK-DAG:      <<Arg:c\d+>>      ParameterValue
1485   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Arg>>]
1486   /// CHECK-DAG:                        Return [<<Short>>]
1487 
1488   /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
1489   /// CHECK-DAG:                        TypeConversion
1490   /// CHECK-NOT:                        TypeConversion
1491 
$noinline$charToDoubleToShort(char value)1492   public static short $noinline$charToDoubleToShort(char value) {
1493     // Originally, this is char->double->int->short. The first conversion is lossless,
1494     // so we merge this with the second one to char->int which we omit as it's an implicit
1495     // conversion. Then we are left with the resulting char->short conversion.
1496     return (short) (double) value;
1497   }
1498 
1499   /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (before)
1500   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1501   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1502   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Int>>]
1503   /// CHECK-DAG:                        Return [<<Short>>]
1504 
1505   /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (after)
1506   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1507   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1508   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Int>>]
1509   /// CHECK-DAG:                        Return [<<Short>>]
1510 
$noinline$floatToIntToShort(float value)1511   public static short $noinline$floatToIntToShort(float value) {
1512     // Lossy FP to integral conversion followed by another conversion: no simplification.
1513     return (short) value;
1514   }
1515 
1516   /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (before)
1517   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1518   /// CHECK-DAG:      <<Float:f\d+>>    TypeConversion [<<Arg>>]
1519   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Float>>]
1520   /// CHECK-DAG:                        Return [<<Int>>]
1521 
1522   /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (after)
1523   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1524   /// CHECK-DAG:      <<Float:f\d+>>    TypeConversion [<<Arg>>]
1525   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Float>>]
1526   /// CHECK-DAG:                        Return [<<Int>>]
1527 
$noinline$intToFloatToInt(int value)1528   public static int $noinline$intToFloatToInt(int value) {
1529     // Lossy integral to FP conversion followed another conversion: no simplification.
1530     return (int) (float) value;
1531   }
1532 
1533   /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (before)
1534   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1535   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1536   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Int>>]
1537   /// CHECK-DAG:                        Return [<<Double>>]
1538 
1539   /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (after)
1540   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1541   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1542   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Int>>]
1543   /// CHECK-DAG:                        Return [<<Double>>]
1544 
$noinline$longToIntToDouble(long value)1545   public static double $noinline$longToIntToDouble(long value) {
1546     // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1547     return (double) (int) value;
1548   }
1549 
1550   /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (before)
1551   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1552   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1553   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Int>>]
1554   /// CHECK-DAG:                        Return [<<Long>>]
1555 
1556   /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (after)
1557   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1558   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1559   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Int>>]
1560   /// CHECK-DAG:                        Return [<<Long>>]
1561 
$noinline$longToIntToLong(long value)1562   public static long $noinline$longToIntToLong(long value) {
1563     // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1564     return (long) (int) value;
1565   }
1566 
1567   /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (before)
1568   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1569   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1570   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Char>>]
1571   /// CHECK-DAG:                        Return [<<Short>>]
1572 
1573   /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (after)
1574   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1575   /// CHECK-DAG:                        Return [<<Arg>>]
1576 
$noinline$shortToCharToShort(short value)1577   public static short $noinline$shortToCharToShort(short value) {
1578     // Integral conversion followed by non-widening integral conversion to original type.
1579     return (short) (char) value;
1580   }
1581 
1582   /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (before)
1583   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1584   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Arg>>]
1585   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Long>>]
1586   /// CHECK-DAG:                        Return [<<Int>>]
1587 
1588   /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (after)
1589   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1590   /// CHECK-DAG:                        Return [<<Arg>>]
1591 
$noinline$shortToLongToInt(short value)1592   public static int $noinline$shortToLongToInt(short value) {
1593     // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1594     return (int) (long) value;
1595   }
1596 
1597   /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (before)
1598   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1599   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1600   /// CHECK-DAG:      <<Byte:b\d+>>     TypeConversion [<<Char>>]
1601   /// CHECK-DAG:                        Return [<<Byte>>]
1602 
1603   /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (after)
1604   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1605   /// CHECK-DAG:      <<Byte:b\d+>>     TypeConversion [<<Arg>>]
1606   /// CHECK-DAG:                        Return [<<Byte>>]
1607 
$noinline$shortToCharToByte(short value)1608   public static byte $noinline$shortToCharToByte(short value) {
1609     // Integral conversion followed by non-widening integral conversion losing bits
1610     // from the original type. Simplify to use only one conversion.
1611     return (byte) (char) value;
1612   }
1613 
1614   /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (before)
1615   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1616   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1617   /// CHECK-DAG:      {{b\d+}}          TypeConversion [<<Char>>]
1618 
1619   /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (after)
1620   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1621   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1622   /// CHECK-DAG:      {{b\d+}}          TypeConversion [<<Char>>]
1623 
$noinline$shortToCharToBytePrint(short value)1624   public static String $noinline$shortToCharToBytePrint(short value) {
1625     // Integral conversion followed by non-widening integral conversion losing bits
1626     // from the original type with an extra use of the intermediate result.
1627     char c = (char) value;
1628     byte b = (byte) c;
1629     return "c=" + ((int) c) + ", b=" + ((int) b);  // implicit conversions.
1630   }
1631 
1632   /// CHECK-START: long Main.$noinline$intAndSmallLongConstant(int) instruction_simplifier (before)
1633   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1634   /// CHECK-DAG:      <<Mask:j\d+>>     LongConstant -12345678
1635   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Arg>>]
1636   /// CHECK-DAG:      <<And:j\d+>>      And [<<Long>>,<<Mask>>]
1637   /// CHECK-DAG:                        Return [<<And>>]
1638 
1639   /// CHECK-START: long Main.$noinline$intAndSmallLongConstant(int) instruction_simplifier (after)
1640   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1641   /// CHECK-DAG:      <<Mask:i\d+>>     IntConstant -12345678
1642   /// CHECK-DAG:      <<And:i\d+>>      And [<<Arg>>,<<Mask>>]
1643   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<And>>]
1644   /// CHECK-DAG:                        Return [<<Long>>]
1645 
$noinline$intAndSmallLongConstant(int value)1646   public static long $noinline$intAndSmallLongConstant(int value) {
1647     return value & -12345678L;  // Shall be simplified (constant is 32-bit).
1648   }
1649 
1650   /// CHECK-START: long Main.$noinline$intAndLargeLongConstant(int) instruction_simplifier (before)
1651   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1652   /// CHECK-DAG:      <<Mask:j\d+>>     LongConstant 9876543210
1653   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Arg>>]
1654   /// CHECK-DAG:      <<And:j\d+>>      And [<<Long>>,<<Mask>>]
1655   /// CHECK-DAG:                        Return [<<And>>]
1656 
1657   /// CHECK-START: long Main.$noinline$intAndLargeLongConstant(int) instruction_simplifier (after)
1658   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1659   /// CHECK-DAG:      <<Mask:j\d+>>     LongConstant 9876543210
1660   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Arg>>]
1661   /// CHECK-DAG:      <<And:j\d+>>      And [<<Long>>,<<Mask>>]
1662   /// CHECK-DAG:                        Return [<<And>>]
1663 
$noinline$intAndLargeLongConstant(int value)1664   public static long $noinline$intAndLargeLongConstant(int value) {
1665     return value & 9876543210L;  // Shall not be simplified (constant is not 32-bit).
1666   }
1667 
1668   /// CHECK-START: long Main.$noinline$intShr28And15L(int) instruction_simplifier (before)
1669   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1670   /// CHECK-DAG:      <<Shift:i\d+>>    IntConstant 28
1671   /// CHECK-DAG:      <<Mask:j\d+>>     LongConstant 15
1672   /// CHECK-DAG:      <<Shifted:i\d+>>  Shr [<<Arg>>,<<Shift>>]
1673   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Shifted>>]
1674   /// CHECK-DAG:      <<And:j\d+>>      And [<<Long>>,<<Mask>>]
1675   /// CHECK-DAG:                        Return [<<And>>]
1676 
1677   /// CHECK-START: long Main.$noinline$intShr28And15L(int) instruction_simplifier (after)
1678   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1679   /// CHECK-DAG:      <<Shift:i\d+>>    IntConstant 28
1680   /// CHECK-DAG:      <<Shifted:i\d+>>  UShr [<<Arg>>,<<Shift>>]
1681   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Shifted>>]
1682   /// CHECK-DAG:                        Return [<<Long>>]
1683 
$noinline$intShr28And15L(int value)1684   public static long $noinline$intShr28And15L(int value) {
1685     return (value >> 28) & 15L;
1686   }
1687 
1688   /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (before)
1689   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1690   /// CHECK-DAG:      <<Mask:j\d+>>     LongConstant 255
1691   /// CHECK-DAG:      <<And:j\d+>>      And [<<Mask>>,<<Arg>>]
1692   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<And>>]
1693   /// CHECK-DAG:      <<Byte:b\d+>>     TypeConversion [<<Int>>]
1694   /// CHECK-DAG:                        Return [<<Byte>>]
1695 
1696   /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
1697   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1698   /// CHECK-DAG:      <<Byte:b\d+>>     TypeConversion [<<Arg>>]
1699   /// CHECK-DAG:                        Return [<<Byte>>]
1700 
1701   /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
1702   /// CHECK-NOT:                        And
1703 
$noinline$longAnd0xffToByte(long value)1704   public static byte $noinline$longAnd0xffToByte(long value) {
1705     return (byte) (value & 0xff);
1706   }
1707 
1708   /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (before)
1709   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1710   /// CHECK-DAG:      <<Mask:i\d+>>     IntConstant 131071
1711   /// CHECK-DAG:      <<And:i\d+>>      And [<<Mask>>,<<Arg>>]
1712   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<And>>]
1713   /// CHECK-DAG:                        Return [<<Char>>]
1714 
1715   /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
1716   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1717   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1718   /// CHECK-DAG:                        Return [<<Char>>]
1719 
1720   /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
1721   /// CHECK-NOT:                        And
1722 
$noinline$intAnd0x1ffffToChar(int value)1723   public static char $noinline$intAnd0x1ffffToChar(int value) {
1724     // Keeping all significant bits and one more.
1725     return (char) (value & 0x1ffff);
1726   }
1727 
1728   /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (before)
1729   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1730   /// CHECK-DAG:      <<Mask:i\d+>>     IntConstant 98303
1731   /// CHECK-DAG:      <<And:i\d+>>      And [<<Mask>>,<<Arg>>]
1732   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<And>>]
1733   /// CHECK-DAG:                        Return [<<Short>>]
1734 
1735   /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (after)
1736   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1737   /// CHECK-DAG:      <<Mask:i\d+>>     IntConstant 98303
1738   /// CHECK-DAG:      <<And:i\d+>>      And [<<Mask>>,<<Arg>>]
1739   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<And>>]
1740   /// CHECK-DAG:                        Return [<<Short>>]
1741 
$noinline$intAnd0x17fffToShort(int value)1742   public static short $noinline$intAnd0x17fffToShort(int value) {
1743     // No simplification: clearing a significant bit.
1744     return (short) (value & 0x17fff);
1745   }
1746 
1747   /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (before)
1748   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1749   /// CHECK-DAG:      <<Mask:i\d+>>     IntConstant 65535
1750   /// CHECK-DAG:      <<And:i\d+>>      And [<<Mask>>,<<Arg>>]
1751   /// CHECK-DAG:      <<Same:s\d+>>     TypeConversion [<<And>>]
1752   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Same>>]
1753   /// CHECK-DAG:                        Return [<<Double>>]
1754 
1755   /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (after)
1756   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1757   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1758   /// CHECK-DAG:                        Return [<<Double>>]
1759 
$noinline$shortAnd0xffffToShortToDouble(short value)1760   public static double $noinline$shortAnd0xffffToShortToDouble(short value) {
1761     short same = (short) (value & 0xffff);
1762     return (double) same;
1763   }
1764 
1765   /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (before)
1766   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1767   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1768   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Const42>>,<<Arg>>]
1769 
1770   /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (after)
1771   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1772   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1773   /// CHECK-DAG:      <<GE:z\d+>>       GreaterThanOrEqual [<<Arg>>,<<Const42>>]
1774 
$noinline$intReverseCondition(int i)1775   public static int $noinline$intReverseCondition(int i) {
1776     return (42 > i) ? 13 : 54;
1777   }
1778 
1779   /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (before)
1780   /// CHECK-DAG:      <<Const42:d\d+>>  DoubleConstant 42
1781   /// CHECK-DAG:      <<Result:d\d+>>   InvokeStaticOrDirect
1782   /// CHECK-DAG:      <<CMP:i\d+>>      Compare [<<Const42>>,<<Result>>]
1783 
1784   /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (after)
1785   /// CHECK-DAG:      <<Const42:d\d+>>  DoubleConstant 42
1786   /// CHECK-DAG:      <<Result:d\d+>>   InvokeStaticOrDirect
1787   /// CHECK-DAG:      <<EQ:z\d+>>       Equal [<<Result>>,<<Const42>>]
1788 
$noinline$intReverseConditionNaN(int i)1789   public static int $noinline$intReverseConditionNaN(int i) {
1790     return (42 != Math.sqrt(i)) ? 13 : 54;
1791   }
1792 
$noinline$runSmaliTest(String name, boolean input)1793   public static int $noinline$runSmaliTest(String name, boolean input) {
1794     try {
1795       Class<?> c = Class.forName("SmaliTests");
1796       Method m = c.getMethod(name, boolean.class);
1797       return (Integer) m.invoke(null, input);
1798     } catch (Exception ex) {
1799       throw new Error(ex);
1800     }
1801   }
1802 
$noinline$runSmaliTest2Boolean(String name, boolean input)1803   public static boolean $noinline$runSmaliTest2Boolean(String name, boolean input) {
1804     try {
1805       Class<?> c = Class.forName("SmaliTests2");
1806       Method m = c.getMethod(name, boolean.class);
1807       return (Boolean) m.invoke(null, input);
1808     } catch (Exception ex) {
1809       throw new Error(ex);
1810     }
1811   }
1812 
$noinline$runSmaliTestInt(String postfix, String name, int arg)1813   public static int $noinline$runSmaliTestInt(String postfix, String name, int arg) {
1814     try {
1815       Class<?> c = Class.forName("SmaliTests" + postfix);
1816       Method m = c.getMethod(name, int.class);
1817       return (Integer) m.invoke(null, arg);
1818     } catch (Exception ex) {
1819       throw new Error(ex);
1820     }
1821   }
1822 
$noinline$runSmaliTestInt(String name, int arg)1823   public static int $noinline$runSmaliTestInt(String name, int arg) {
1824     return $noinline$runSmaliTestInt("", name, arg);
1825   }
1826 
$noinline$runSmaliTest2Long(String name, long arg)1827   public static long $noinline$runSmaliTest2Long(String name, long arg) {
1828     try {
1829       Class<?> c = Class.forName("SmaliTests2");
1830       Method m = c.getMethod(name, long.class);
1831       return (Long) m.invoke(null, arg);
1832     } catch (Exception ex) {
1833       throw new Error(ex);
1834     }
1835   }
1836 
1837   /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1838   /// CHECK:          <<Value:i\d+>>    ParameterValue
1839   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1840   /// CHECK-DAG:      <<Const31:i\d+>>  IntConstant 31
1841   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const31>>]
1842   /// CHECK-DAG:      <<Shl:i\d+>>      Shl [<<Value>>,<<And>>]
1843   /// CHECK-DAG:                        Return [<<Shl>>]
1844 
1845   /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1846   /// CHECK:          <<Value:i\d+>>    ParameterValue
1847   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1848   /// CHECK-DAG:      <<Shl:i\d+>>      Shl [<<Value>>,<<Shift>>]
1849   /// CHECK-DAG:                        Return [<<Shl>>]
1850 
$noinline$intUnnecessaryShiftMasking(int value, int shift)1851   public static int $noinline$intUnnecessaryShiftMasking(int value, int shift) {
1852     return value << (shift & 31);
1853   }
1854 
1855   /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (before)
1856   /// CHECK:          <<Value:j\d+>>    ParameterValue
1857   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1858   /// CHECK-DAG:      <<Const63:i\d+>>  IntConstant 63
1859   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const63>>]
1860   /// CHECK-DAG:      <<Shr:j\d+>>      Shr [<<Value>>,<<And>>]
1861   /// CHECK-DAG:                        Return [<<Shr>>]
1862 
1863   /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (after)
1864   /// CHECK:          <<Value:j\d+>>    ParameterValue
1865   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1866   /// CHECK-DAG:      <<Shr:j\d+>>      Shr [<<Value>>,<<Shift>>]
1867   /// CHECK-DAG:                        Return [<<Shr>>]
1868 
$noinline$longUnnecessaryShiftMasking(long value, int shift)1869   public static long $noinline$longUnnecessaryShiftMasking(long value, int shift) {
1870     return value >> (shift & 63);
1871   }
1872 
1873   /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (before)
1874   /// CHECK:          <<Value:i\d+>>    ParameterValue
1875   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1876   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
1877   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const255>>]
1878   /// CHECK-DAG:      <<UShr:i\d+>>     UShr [<<Value>>,<<And>>]
1879   /// CHECK-DAG:                        Return [<<UShr>>]
1880 
1881   /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (after)
1882   /// CHECK:          <<Value:i\d+>>    ParameterValue
1883   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1884   /// CHECK-DAG:      <<UShr:i\d+>>     UShr [<<Value>>,<<Shift>>]
1885   /// CHECK-DAG:                        Return [<<UShr>>]
1886 
$noinline$intUnnecessaryWiderShiftMasking(int value, int shift)1887   public static int $noinline$intUnnecessaryWiderShiftMasking(int value, int shift) {
1888     return value >>> (shift & 0xff);
1889   }
1890 
1891   /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (before)
1892   /// CHECK:          <<Value:j\d+>>    ParameterValue
1893   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1894   /// CHECK-DAG:      <<Const3:i\d+>>   IntConstant 3
1895   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const3>>]
1896   /// CHECK-DAG:      <<Shl:j\d+>>      Shl [<<Value>>,<<And>>]
1897   /// CHECK-DAG:                        Return [<<Shl>>]
1898 
1899   /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (after)
1900   /// CHECK:          <<Value:j\d+>>    ParameterValue
1901   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1902   /// CHECK-DAG:      <<Const3:i\d+>>   IntConstant 3
1903   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const3>>]
1904   /// CHECK-DAG:      <<Shl:j\d+>>      Shl [<<Value>>,<<And>>]
1905   /// CHECK-DAG:                        Return [<<Shl>>]
1906 
$noinline$longSmallerShiftMasking(long value, int shift)1907   public static long $noinline$longSmallerShiftMasking(long value, int shift) {
1908     return value << (shift & 3);
1909   }
1910 
1911   /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1912   /// CHECK:          <<Value:i\d+>>    ParameterValue
1913   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1914   /// CHECK-DAG:      <<Const31:i\d+>>  IntConstant 31
1915   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const31>>]
1916   /// CHECK-DAG:      <<Shr:i\d+>>      Shr [<<Value>>,<<And>>]
1917   /// CHECK-DAG:      <<Add:i\d+>>      Add [<<Shr>>,<<And>>]
1918   /// CHECK-DAG:                        Return [<<Add>>]
1919 
1920   /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1921   /// CHECK:          <<Value:i\d+>>    ParameterValue
1922   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1923   /// CHECK-DAG:      <<Const31:i\d+>>  IntConstant 31
1924   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const31>>]
1925   /// CHECK-DAG:      <<Shr:i\d+>>      Shr [<<Value>>,<<Shift>>]
1926   /// CHECK-DAG:      <<Add:i\d+>>      Add [<<Shr>>,<<And>>]
1927   /// CHECK-DAG:                        Return [<<Add>>]
1928 
$noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift)1929   public static int $noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift) {
1930     int temp = shift & 31;
1931     return (value >> temp) + temp;
1932   }
1933 
1934   /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (before)
1935   /// CHECK:          <<Value:i\d+>>    ParameterValue
1936   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1937   /// CHECK-DAG:      <<Const32:i\d+>>  IntConstant 32
1938   /// CHECK-DAG:      <<Const64:i\d+>>  IntConstant 64
1939   /// CHECK-DAG:      <<Const96:i\d+>>  IntConstant 96
1940   /// CHECK-DAG:      <<Const128:i\d+>> IntConstant 128
1941   /// CHECK-DAG:      <<Or:i\d+>>       Or [<<Shift>>,<<Const32>>]
1942   /// CHECK-DAG:      <<Xor:i\d+>>      Xor [<<Shift>>,<<Const64>>]
1943   /// CHECK-DAG:      <<Add:i\d+>>      Add [<<Shift>>,<<Const96>>]
1944   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<Shift>>,<<Const128>>]
1945   /// CHECK-DAG:      <<Conv:b\d+>>     TypeConversion [<<Shift>>]
1946   /// CHECK-DAG:                        Shl [<<Value>>,<<Or>>]
1947   /// CHECK-DAG:                        Shr [<<Value>>,<<Xor>>]
1948   /// CHECK-DAG:                        UShr [<<Value>>,<<Add>>]
1949   /// CHECK-DAG:                        Shl [<<Value>>,<<Sub>>]
1950   /// CHECK-DAG:                        Shr [<<Value>>,<<Conv>>]
1951 
1952   /// CHECK-START: int Main.$noinline$intUnnecessaryShiftModifications(int, int) instruction_simplifier (after)
1953   /// CHECK:          <<Value:i\d+>>    ParameterValue
1954   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1955   /// CHECK-DAG:                        Shl [<<Value>>,<<Shift>>]
1956   /// CHECK-DAG:                        Shr [<<Value>>,<<Shift>>]
1957   /// CHECK-DAG:                        UShr [<<Value>>,<<Shift>>]
1958   /// CHECK-DAG:                        Shl [<<Value>>,<<Shift>>]
1959   /// CHECK-DAG:                        Shr [<<Value>>,<<Shift>>]
1960 
$noinline$intUnnecessaryShiftModifications(int value, int shift)1961   public static int $noinline$intUnnecessaryShiftModifications(int value, int shift) {
1962     int c128 = 128;
1963     return (value << (shift | 32)) +
1964            (value >> (shift ^ 64)) +
1965            (value >>> (shift + 96)) +
1966            (value << (shift - c128)) +  // Needs a named constant to generate Sub.
1967            (value >> ((byte) shift));
1968   }
1969 
1970   /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (before)
1971   /// CHECK:          <<Value:i\d+>>    ParameterValue
1972   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1973   /// CHECK-DAG:      <<Const33:i\d+>>  IntConstant 33
1974   /// CHECK-DAG:      <<Const65:i\d+>>  IntConstant 65
1975   /// CHECK-DAG:      <<Const97:i\d+>>  IntConstant 97
1976   /// CHECK-DAG:      <<Const129:i\d+>> IntConstant 129
1977   /// CHECK-DAG:      <<Or:i\d+>>       Or [<<Shift>>,<<Const33>>]
1978   /// CHECK-DAG:      <<Xor:i\d+>>      Xor [<<Shift>>,<<Const65>>]
1979   /// CHECK-DAG:      <<Add:i\d+>>      Add [<<Shift>>,<<Const97>>]
1980   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<Shift>>,<<Const129>>]
1981   /// CHECK-DAG:                        Shl [<<Value>>,<<Or>>]
1982   /// CHECK-DAG:                        Shr [<<Value>>,<<Xor>>]
1983   /// CHECK-DAG:                        UShr [<<Value>>,<<Add>>]
1984   /// CHECK-DAG:                        Shl [<<Value>>,<<Sub>>]
1985 
1986   /// CHECK-START: int Main.$noinline$intNecessaryShiftModifications(int, int) instruction_simplifier (after)
1987   /// CHECK:          <<Value:i\d+>>    ParameterValue
1988   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1989   /// CHECK-DAG:      <<Const33:i\d+>>  IntConstant 33
1990   /// CHECK-DAG:      <<Const65:i\d+>>  IntConstant 65
1991   /// CHECK-DAG:      <<Const97:i\d+>>  IntConstant 97
1992   /// CHECK-DAG:      <<Const129:i\d+>> IntConstant 129
1993   /// CHECK-DAG:      <<Or:i\d+>>       Or [<<Shift>>,<<Const33>>]
1994   /// CHECK-DAG:      <<Xor:i\d+>>      Xor [<<Shift>>,<<Const65>>]
1995   /// CHECK-DAG:      <<Add:i\d+>>      Add [<<Shift>>,<<Const97>>]
1996   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<Shift>>,<<Const129>>]
1997   /// CHECK-DAG:                        Shl [<<Value>>,<<Or>>]
1998   /// CHECK-DAG:                        Shr [<<Value>>,<<Xor>>]
1999   /// CHECK-DAG:                        UShr [<<Value>>,<<Add>>]
2000   /// CHECK-DAG:                        Shl [<<Value>>,<<Sub>>]
2001 
$noinline$intNecessaryShiftModifications(int value, int shift)2002   public static int $noinline$intNecessaryShiftModifications(int value, int shift) {
2003     int c129 = 129;
2004     return (value << (shift | 33)) +
2005            (value >> (shift ^ 65)) +
2006            (value >>> (shift + 97)) +
2007            (value << (shift - c129));  // Needs a named constant to generate Sub.
2008   }
2009 
2010   /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (before)
2011   /// CHECK:          <<X:i\d+>>        ParameterValue
2012   /// CHECK:          <<Y:i\d+>>        ParameterValue
2013   /// CHECK-DAG:      <<Sum:i\d+>>      Add [<<X>>,<<Y>>]
2014   /// CHECK-DAG:      <<Res:i\d+>>      Sub [<<Sum>>,<<X>>]
2015   /// CHECK-DAG:                        Return [<<Res>>]
2016 
2017   /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (after)
2018   /// CHECK:          <<X:i\d+>>        ParameterValue
2019   /// CHECK:          <<Y:i\d+>>        ParameterValue
2020   /// CHECK-DAG:      <<Sum:i\d+>>      Add [<<X>>,<<Y>>]
2021   /// CHECK-DAG:                        Return [<<Y>>]
2022 
$noinline$intAddSubSimplifyArg1(int x, int y)2023   public static int $noinline$intAddSubSimplifyArg1(int x, int y) {
2024     int sum = x + y;
2025     return sum - x;
2026   }
2027 
2028   /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (before)
2029   /// CHECK:          <<X:i\d+>>        ParameterValue
2030   /// CHECK:          <<Y:i\d+>>        ParameterValue
2031   /// CHECK-DAG:      <<Sum:i\d+>>      Add [<<X>>,<<Y>>]
2032   /// CHECK-DAG:      <<Res:i\d+>>      Sub [<<Sum>>,<<Y>>]
2033   /// CHECK-DAG:                        Return [<<Res>>]
2034 
2035   /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (after)
2036   /// CHECK:          <<X:i\d+>>        ParameterValue
2037   /// CHECK:          <<Y:i\d+>>        ParameterValue
2038   /// CHECK-DAG:      <<Sum:i\d+>>      Add [<<X>>,<<Y>>]
2039   /// CHECK-DAG:                        Return [<<X>>]
2040 
$noinline$intAddSubSimplifyArg2(int x, int y)2041   public static int $noinline$intAddSubSimplifyArg2(int x, int y) {
2042     int sum = x + y;
2043     return sum - y;
2044   }
2045 
2046   /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (before)
2047   /// CHECK:          <<X:i\d+>>        ParameterValue
2048   /// CHECK:          <<Y:i\d+>>        ParameterValue
2049   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<X>>,<<Y>>]
2050   /// CHECK-DAG:      <<Res:i\d+>>      Add [<<Sub>>,<<Y>>]
2051   /// CHECK-DAG:                        Return [<<Res>>]
2052 
2053   /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (after)
2054   /// CHECK:          <<X:i\d+>>        ParameterValue
2055   /// CHECK:          <<Y:i\d+>>        ParameterValue
2056   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<X>>,<<Y>>]
2057   /// CHECK-DAG:                        Return [<<X>>]
2058 
$noinline$intSubAddSimplifyLeft(int x, int y)2059   public static int $noinline$intSubAddSimplifyLeft(int x, int y) {
2060     int sub = x - y;
2061     return sub + y;
2062   }
2063 
2064   /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (before)
2065   /// CHECK:          <<X:i\d+>>        ParameterValue
2066   /// CHECK:          <<Y:i\d+>>        ParameterValue
2067   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<X>>,<<Y>>]
2068   /// CHECK-DAG:      <<Res:i\d+>>      Add [<<Y>>,<<Sub>>]
2069   /// CHECK-DAG:                        Return [<<Res>>]
2070 
2071   /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (after)
2072   /// CHECK:          <<X:i\d+>>        ParameterValue
2073   /// CHECK:          <<Y:i\d+>>        ParameterValue
2074   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<X>>,<<Y>>]
2075   /// CHECK-DAG:                        Return [<<X>>]
2076 
$noinline$intSubAddSimplifyRight(int x, int y)2077   public static int $noinline$intSubAddSimplifyRight(int x, int y) {
2078     int sub = x - y;
2079     return y + sub;
2080   }
2081 
2082   /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (before)
2083   /// CHECK:          <<X:f\d+>>        ParameterValue
2084   /// CHECK:          <<Y:f\d+>>        ParameterValue
2085   /// CHECK-DAG:      <<Sum:f\d+>>      Add [<<X>>,<<Y>>]
2086   /// CHECK-DAG:      <<Res:f\d+>>      Sub [<<Sum>>,<<X>>]
2087   /// CHECK-DAG:                        Return [<<Res>>]
2088 
2089   /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (after)
2090   /// CHECK:          <<X:f\d+>>        ParameterValue
2091   /// CHECK:          <<Y:f\d+>>        ParameterValue
2092   /// CHECK-DAG:      <<Sum:f\d+>>      Add [<<X>>,<<Y>>]
2093   /// CHECK-DAG:      <<Res:f\d+>>      Sub [<<Sum>>,<<X>>]
2094   /// CHECK-DAG:                        Return [<<Res>>]
2095 
$noinline$floatAddSubSimplifyArg1(float x, float y)2096   public static float $noinline$floatAddSubSimplifyArg1(float x, float y) {
2097     float sum = x + y;
2098     return sum - x;
2099   }
2100 
2101   /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (before)
2102   /// CHECK:          <<X:f\d+>>        ParameterValue
2103   /// CHECK:          <<Y:f\d+>>        ParameterValue
2104   /// CHECK-DAG:      <<Sum:f\d+>>      Add [<<X>>,<<Y>>]
2105   /// CHECK-DAG:      <<Res:f\d+>>      Sub [<<Sum>>,<<Y>>]
2106   /// CHECK-DAG:                        Return [<<Res>>]
2107 
2108   /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (after)
2109   /// CHECK:          <<X:f\d+>>        ParameterValue
2110   /// CHECK:          <<Y:f\d+>>        ParameterValue
2111   /// CHECK-DAG:      <<Sum:f\d+>>      Add [<<X>>,<<Y>>]
2112   /// CHECK-DAG:      <<Res:f\d+>>      Sub [<<Sum>>,<<Y>>]
2113   /// CHECK-DAG:                        Return [<<Res>>]
2114 
$noinline$floatAddSubSimplifyArg2(float x, float y)2115   public static float $noinline$floatAddSubSimplifyArg2(float x, float y) {
2116     float sum = x + y;
2117     return sum - y;
2118   }
2119 
2120   /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (before)
2121   /// CHECK:          <<X:f\d+>>        ParameterValue
2122   /// CHECK:          <<Y:f\d+>>        ParameterValue
2123   /// CHECK-DAG:      <<Sub:f\d+>>      Sub [<<X>>,<<Y>>]
2124   /// CHECK-DAG:      <<Res:f\d+>>      Add [<<Sub>>,<<Y>>]
2125   /// CHECK-DAG:                        Return [<<Res>>]
2126 
2127   /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (after)
2128   /// CHECK:          <<X:f\d+>>        ParameterValue
2129   /// CHECK:          <<Y:f\d+>>        ParameterValue
2130   /// CHECK-DAG:      <<Sub:f\d+>>      Sub [<<X>>,<<Y>>]
2131   /// CHECK-DAG:      <<Res:f\d+>>      Add [<<Sub>>,<<Y>>]
2132   /// CHECK-DAG:                        Return [<<Res>>]
2133 
$noinline$floatSubAddSimplifyLeft(float x, float y)2134   public static float $noinline$floatSubAddSimplifyLeft(float x, float y) {
2135     float sub = x - y;
2136     return sub + y;
2137   }
2138 
2139   /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (before)
2140   /// CHECK:          <<X:f\d+>>        ParameterValue
2141   /// CHECK:          <<Y:f\d+>>        ParameterValue
2142   /// CHECK-DAG:      <<Sub:f\d+>>      Sub [<<X>>,<<Y>>]
2143   /// CHECK-DAG:      <<Res:f\d+>>      Add [<<Y>>,<<Sub>>]
2144   /// CHECK-DAG:                        Return [<<Res>>]
2145 
2146   /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (after)
2147   /// CHECK:          <<X:f\d+>>        ParameterValue
2148   /// CHECK:          <<Y:f\d+>>        ParameterValue
2149   /// CHECK-DAG:      <<Sub:f\d+>>      Sub [<<X>>,<<Y>>]
2150   /// CHECK-DAG:      <<Res:f\d+>>      Add [<<Y>>,<<Sub>>]
2151   /// CHECK-DAG:                        Return [<<Res>>]
2152 
$noinline$floatSubAddSimplifyRight(float x, float y)2153   public static float $noinline$floatSubAddSimplifyRight(float x, float y) {
2154     float sub = x - y;
2155     return y + sub;
2156   }
2157 
2158   // Sub/Add and Sub/Sub simplifications
2159 
2160   /// CHECK-START: int Main.$noinline$testSubAddInt(int, int) instruction_simplifier (before)
2161   /// CHECK: <<x:i\d+>>   ParameterValue
2162   /// CHECK: <<y:i\d+>>   ParameterValue
2163   /// CHECK: <<add:i\d+>> Add [<<x>>,<<y>>]
2164   /// CHECK: <<sub:i\d+>> Sub [<<y>>,<<add>>]
2165   /// CHECK:              Return [<<sub>>]
2166 
2167   /// CHECK-START: int Main.$noinline$testSubAddInt(int, int) instruction_simplifier (after)
2168   /// CHECK: <<x:i\d+>>   ParameterValue
2169   /// CHECK: <<y:i\d+>>   ParameterValue
2170   /// CHECK: <<add:i\d+>> Add [<<x>>,<<y>>]
2171   /// CHECK: <<neg:i\d+>> Neg [<<x>>]
2172   /// CHECK:              Return [<<neg>>]
2173 
2174   /// CHECK-START: int Main.$noinline$testSubAddInt(int, int) instruction_simplifier (after)
2175   /// CHECK-NOT: Sub
2176 
2177   /// CHECK-START: int Main.$noinline$testSubAddInt(int, int) dead_code_elimination$initial (after)
2178   /// CHECK-NOT: Add
$noinline$testSubAddInt(int x, int y)2179   static int $noinline$testSubAddInt(int x, int y) {
2180     return y - (x + y);
2181   }
2182 
2183   /// CHECK-START: int Main.$noinline$testSubAddOtherVersionInt(int, int) instruction_simplifier (before)
2184   /// CHECK: <<x:i\d+>>   ParameterValue
2185   /// CHECK: <<y:i\d+>>   ParameterValue
2186   /// CHECK: <<add:i\d+>> Add [<<x>>,<<y>>]
2187   /// CHECK: <<sub:i\d+>> Sub [<<x>>,<<add>>]
2188   /// CHECK:              Return [<<sub>>]
2189 
2190   /// CHECK-START: int Main.$noinline$testSubAddOtherVersionInt(int, int) instruction_simplifier (after)
2191   /// CHECK: <<x:i\d+>>   ParameterValue
2192   /// CHECK: <<y:i\d+>>   ParameterValue
2193   /// CHECK: <<add:i\d+>> Add [<<x>>,<<y>>]
2194   /// CHECK: <<neg:i\d+>> Neg [<<y>>]
2195   /// CHECK:              Return [<<neg>>]
2196 
2197   /// CHECK-START: int Main.$noinline$testSubAddOtherVersionInt(int, int) instruction_simplifier (after)
2198   /// CHECK-NOT: Sub
2199 
2200   /// CHECK-START: int Main.$noinline$testSubAddOtherVersionInt(int, int) dead_code_elimination$initial (after)
2201   /// CHECK-NOT: Add
$noinline$testSubAddOtherVersionInt(int x, int y)2202   static int $noinline$testSubAddOtherVersionInt(int x, int y) {
2203     return x - (x + y);
2204   }
2205 
2206   /// CHECK-START: int Main.$noinline$testSubSubInt(int, int) instruction_simplifier (before)
2207   /// CHECK: <<x:i\d+>>    ParameterValue
2208   /// CHECK: <<y:i\d+>>    ParameterValue
2209   /// CHECK: <<sub1:i\d+>> Sub [<<x>>,<<y>>]
2210   /// CHECK: <<sub2:i\d+>> Sub [<<sub1>>,<<x>>]
2211   /// CHECK:               Return [<<sub2>>]
2212 
2213   /// CHECK-START: int Main.$noinline$testSubSubInt(int, int) instruction_simplifier (after)
2214   /// CHECK: <<x:i\d+>>    ParameterValue
2215   /// CHECK: <<y:i\d+>>    ParameterValue
2216   /// CHECK: <<sub1:i\d+>> Sub [<<x>>,<<y>>]
2217   /// CHECK: <<neg:i\d+>>  Neg [<<y>>]
2218   /// CHECK:               Return [<<neg>>]
2219 
2220   /// CHECK-START: int Main.$noinline$testSubSubInt(int, int) instruction_simplifier (after)
2221   /// CHECK:     Sub
2222   /// CHECK-NOT: Sub
2223 
2224   /// CHECK-START: int Main.$noinline$testSubSubInt(int, int) dead_code_elimination$initial (after)
2225   /// CHECK-NOT: Sub
$noinline$testSubSubInt(int x, int y)2226   static int $noinline$testSubSubInt(int x, int y) {
2227     return (x - y) - x;
2228   }
2229 
2230   /// CHECK-START: int Main.$noinline$testSubSubOtherVersionInt(int, int) instruction_simplifier (before)
2231   /// CHECK: <<x:i\d+>>    ParameterValue
2232   /// CHECK: <<y:i\d+>>    ParameterValue
2233   /// CHECK: <<sub1:i\d+>> Sub [<<x>>,<<y>>]
2234   /// CHECK: <<sub2:i\d+>> Sub [<<x>>,<<sub1>>]
2235   /// CHECK:               Return [<<sub2>>]
2236 
2237   /// CHECK-START: int Main.$noinline$testSubSubOtherVersionInt(int, int) instruction_simplifier (after)
2238   /// CHECK: <<x:i\d+>>    ParameterValue
2239   /// CHECK: <<y:i\d+>>    ParameterValue
2240   /// CHECK: <<sub1:i\d+>> Sub [<<x>>,<<y>>]
2241   /// CHECK:               Return [<<y>>]
2242 
2243   /// CHECK-START: int Main.$noinline$testSubSubOtherVersionInt(int, int) instruction_simplifier (after)
2244   /// CHECK:     Sub
2245   /// CHECK-NOT: Sub
2246 
2247   /// CHECK-START: int Main.$noinline$testSubSubOtherVersionInt(int, int) dead_code_elimination$initial (after)
2248   /// CHECK-NOT: Sub
$noinline$testSubSubOtherVersionInt(int x, int y)2249   static int $noinline$testSubSubOtherVersionInt(int x, int y) {
2250     return x - (x - y);
2251   }
2252 
2253   /// CHECK-START: long Main.$noinline$testSubAddLong(long, long) instruction_simplifier (before)
2254   /// CHECK: <<x:j\d+>>   ParameterValue
2255   /// CHECK: <<y:j\d+>>   ParameterValue
2256   /// CHECK: <<add:j\d+>> Add [<<x>>,<<y>>]
2257   /// CHECK: <<sub:j\d+>> Sub [<<y>>,<<add>>]
2258   /// CHECK:              Return [<<sub>>]
2259 
2260   /// CHECK-START: long Main.$noinline$testSubAddLong(long, long) instruction_simplifier (after)
2261   /// CHECK: <<x:j\d+>>   ParameterValue
2262   /// CHECK: <<y:j\d+>>   ParameterValue
2263   /// CHECK: <<add:j\d+>> Add [<<x>>,<<y>>]
2264   /// CHECK: <<neg:j\d+>> Neg [<<x>>]
2265   /// CHECK:              Return [<<neg>>]
2266 
2267   /// CHECK-START: long Main.$noinline$testSubAddLong(long, long) instruction_simplifier (after)
2268   /// CHECK-NOT: Sub
2269 
2270   /// CHECK-START: long Main.$noinline$testSubAddLong(long, long) dead_code_elimination$initial (after)
2271   /// CHECK-NOT: Add
$noinline$testSubAddLong(long x, long y)2272   static long $noinline$testSubAddLong(long x, long y) {
2273     return y - (x + y);
2274   }
2275 
2276   /// CHECK-START: long Main.$noinline$testSubAddOtherVersionLong(long, long) instruction_simplifier (before)
2277   /// CHECK: <<x:j\d+>>   ParameterValue
2278   /// CHECK: <<y:j\d+>>   ParameterValue
2279   /// CHECK: <<add:j\d+>> Add [<<x>>,<<y>>]
2280   /// CHECK: <<sub:j\d+>> Sub [<<x>>,<<add>>]
2281   /// CHECK:              Return [<<sub>>]
2282 
2283   /// CHECK-START: long Main.$noinline$testSubAddOtherVersionLong(long, long) instruction_simplifier (after)
2284   /// CHECK: <<x:j\d+>>   ParameterValue
2285   /// CHECK: <<y:j\d+>>   ParameterValue
2286   /// CHECK: <<add:j\d+>> Add [<<x>>,<<y>>]
2287   /// CHECK: <<neg:j\d+>> Neg [<<y>>]
2288   /// CHECK:              Return [<<neg>>]
2289 
2290   /// CHECK-START: long Main.$noinline$testSubAddOtherVersionLong(long, long) instruction_simplifier (after)
2291   /// CHECK-NOT: Sub
2292 
2293   /// CHECK-START: long Main.$noinline$testSubAddOtherVersionLong(long, long) dead_code_elimination$initial (after)
2294   /// CHECK-NOT: Add
$noinline$testSubAddOtherVersionLong(long x, long y)2295   static long $noinline$testSubAddOtherVersionLong(long x, long y) {
2296     return x - (x + y);
2297   }
2298 
2299   /// CHECK-START: long Main.$noinline$testSubSubLong(long, long) instruction_simplifier (before)
2300   /// CHECK: <<x:j\d+>>    ParameterValue
2301   /// CHECK: <<y:j\d+>>    ParameterValue
2302   /// CHECK: <<sub1:j\d+>> Sub [<<x>>,<<y>>]
2303   /// CHECK: <<sub2:j\d+>> Sub [<<sub1>>,<<x>>]
2304   /// CHECK:               Return [<<sub2>>]
2305 
2306   /// CHECK-START: long Main.$noinline$testSubSubLong(long, long) instruction_simplifier (after)
2307   /// CHECK: <<x:j\d+>>    ParameterValue
2308   /// CHECK: <<y:j\d+>>    ParameterValue
2309   /// CHECK: <<sub1:j\d+>> Sub [<<x>>,<<y>>]
2310   /// CHECK: <<neg:j\d+>>  Neg [<<y>>]
2311   /// CHECK:               Return [<<neg>>]
2312 
2313   /// CHECK-START: long Main.$noinline$testSubSubLong(long, long) instruction_simplifier (after)
2314   /// CHECK:     Sub
2315   /// CHECK-NOT: Sub
2316 
2317   /// CHECK-START: long Main.$noinline$testSubSubLong(long, long) dead_code_elimination$initial (after)
2318   /// CHECK-NOT: Sub
$noinline$testSubSubLong(long x, long y)2319   static long $noinline$testSubSubLong(long x, long y) {
2320     return (x - y) - x;
2321   }
2322 
2323   /// CHECK-START: long Main.$noinline$testSubSubOtherVersionLong(long, long) instruction_simplifier (before)
2324   /// CHECK: <<x:j\d+>>    ParameterValue
2325   /// CHECK: <<y:j\d+>>    ParameterValue
2326   /// CHECK: <<sub1:j\d+>> Sub [<<x>>,<<y>>]
2327   /// CHECK: <<sub2:j\d+>> Sub [<<x>>,<<sub1>>]
2328   /// CHECK:               Return [<<sub2>>]
2329 
2330   /// CHECK-START: long Main.$noinline$testSubSubOtherVersionLong(long, long) instruction_simplifier (after)
2331   /// CHECK: <<x:j\d+>>    ParameterValue
2332   /// CHECK: <<y:j\d+>>    ParameterValue
2333   /// CHECK: <<sub1:j\d+>> Sub [<<x>>,<<y>>]
2334   /// CHECK:               Return [<<y>>]
2335 
2336   /// CHECK-START: long Main.$noinline$testSubSubOtherVersionLong(long, long) instruction_simplifier (after)
2337   /// CHECK:     Sub
2338   /// CHECK-NOT: Sub
2339 
2340   /// CHECK-START: long Main.$noinline$testSubSubOtherVersionLong(long, long) dead_code_elimination$initial (after)
2341   /// CHECK-NOT: Sub
$noinline$testSubSubOtherVersionLong(long x, long y)2342   static long $noinline$testSubSubOtherVersionLong(long x, long y) {
2343     return x - (x - y);
2344   }
2345 
2346   /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteField(Main) instruction_simplifier (before)
2347   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
2348   /// CHECK-DAG:      <<Get:b\d+>>      InstanceFieldGet
2349   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Const255>>]
2350   /// CHECK-DAG:                        Return [<<And>>]
2351 
2352   /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteField(Main) instruction_simplifier (after)
2353   /// CHECK-DAG:      <<Get:a\d+>>      InstanceFieldGet
2354   /// CHECK-DAG:                        Return [<<Get>>]
2355 
2356   /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteField(Main) instruction_simplifier (after)
2357   /// CHECK-NOT:                        And
2358   /// CHECK-NOT:                        TypeConversion
$noinline$getUint8FromInstanceByteField(Main m)2359   public static int $noinline$getUint8FromInstanceByteField(Main m) {
2360     return m.instanceByteField & 0xff;
2361   }
2362 
2363   /// CHECK-START: int Main.$noinline$getUint8FromStaticByteField() instruction_simplifier (before)
2364   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
2365   /// CHECK-DAG:      <<Get:b\d+>>      StaticFieldGet
2366   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Const255>>]
2367   /// CHECK-DAG:                        Return [<<And>>]
2368 
2369   /// CHECK-START: int Main.$noinline$getUint8FromStaticByteField() instruction_simplifier (after)
2370   /// CHECK-DAG:      <<Get:a\d+>>      StaticFieldGet
2371   /// CHECK-DAG:                        Return [<<Get>>]
2372 
2373   /// CHECK-START: int Main.$noinline$getUint8FromStaticByteField() instruction_simplifier (after)
2374   /// CHECK-NOT:                        And
2375   /// CHECK-NOT:                        TypeConversion
$noinline$getUint8FromStaticByteField()2376   public static int $noinline$getUint8FromStaticByteField() {
2377     return staticByteField & 0xff;
2378   }
2379 
2380   /// CHECK-START: int Main.$noinline$getUint8FromByteArray(byte[]) instruction_simplifier (before)
2381   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
2382   /// CHECK-DAG:      <<Get:b\d+>>      ArrayGet
2383   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Const255>>]
2384   /// CHECK-DAG:                        Return [<<And>>]
2385 
2386   /// CHECK-START: int Main.$noinline$getUint8FromByteArray(byte[]) instruction_simplifier (after)
2387   /// CHECK-DAG:      <<Get:a\d+>>      ArrayGet
2388   /// CHECK-DAG:                        Return [<<Get>>]
2389 
2390   /// CHECK-START: int Main.$noinline$getUint8FromByteArray(byte[]) instruction_simplifier (after)
2391   /// CHECK-NOT:                        And
2392   /// CHECK-NOT:                        TypeConversion
$noinline$getUint8FromByteArray(byte[] a)2393   public static int $noinline$getUint8FromByteArray(byte[] a) {
2394     return a[0] & 0xff;
2395   }
2396 
2397   /// CHECK-START: int Main.$noinline$getUint16FromInstanceShortField(Main) instruction_simplifier (before)
2398   /// CHECK-DAG:      <<Cst65535:i\d+>> IntConstant 65535
2399   /// CHECK-DAG:      <<Get:s\d+>>      InstanceFieldGet
2400   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Cst65535>>]
2401   /// CHECK-DAG:                        Return [<<And>>]
2402 
2403   /// CHECK-START: int Main.$noinline$getUint16FromInstanceShortField(Main) instruction_simplifier (after)
2404   /// CHECK-DAG:      <<Get:c\d+>>      InstanceFieldGet
2405   /// CHECK-DAG:                        Return [<<Get>>]
2406 
2407   /// CHECK-START: int Main.$noinline$getUint16FromInstanceShortField(Main) instruction_simplifier (after)
2408   /// CHECK-NOT:                        And
2409   /// CHECK-NOT:                        TypeConversion
$noinline$getUint16FromInstanceShortField(Main m)2410   public static int $noinline$getUint16FromInstanceShortField(Main m) {
2411     return m.instanceShortField & 0xffff;
2412   }
2413 
2414   /// CHECK-START: int Main.$noinline$getUint16FromStaticShortField() instruction_simplifier (before)
2415   /// CHECK-DAG:      <<Cst65535:i\d+>> IntConstant 65535
2416   /// CHECK-DAG:      <<Get:s\d+>>      StaticFieldGet
2417   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Cst65535>>]
2418   /// CHECK-DAG:                        Return [<<And>>]
2419 
2420   /// CHECK-START: int Main.$noinline$getUint16FromStaticShortField() instruction_simplifier (after)
2421   /// CHECK-DAG:      <<Get:c\d+>>      StaticFieldGet
2422   /// CHECK-DAG:                        Return [<<Get>>]
2423 
2424   /// CHECK-START: int Main.$noinline$getUint16FromStaticShortField() instruction_simplifier (after)
2425   /// CHECK-NOT:                        And
2426   /// CHECK-NOT:                        TypeConversion
$noinline$getUint16FromStaticShortField()2427   public static int $noinline$getUint16FromStaticShortField() {
2428     return staticShortField & 0xffff;
2429   }
2430 
2431   /// CHECK-START: int Main.$noinline$getUint16FromShortArray(short[]) instruction_simplifier (before)
2432   /// CHECK-DAG:      <<Cst65535:i\d+>> IntConstant 65535
2433   /// CHECK-DAG:      <<Get:s\d+>>      ArrayGet
2434   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Cst65535>>]
2435   /// CHECK-DAG:                        Return [<<And>>]
2436 
2437   /// CHECK-START: int Main.$noinline$getUint16FromShortArray(short[]) instruction_simplifier (after)
2438   /// CHECK-DAG:      <<Get:c\d+>>      ArrayGet
2439   /// CHECK-DAG:                        Return [<<Get>>]
2440 
2441   /// CHECK-START: int Main.$noinline$getUint16FromShortArray(short[]) instruction_simplifier (after)
2442   /// CHECK-NOT:                        And
2443   /// CHECK-NOT:                        TypeConversion
$noinline$getUint16FromShortArray(short[] a)2444   public static int $noinline$getUint16FromShortArray(short[] a) {
2445     return a[0] & 0xffff;
2446   }
2447 
2448   /// CHECK-START: int Main.$noinline$getInt16FromInstanceCharField(Main) instruction_simplifier (before)
2449   /// CHECK-DAG:      <<Get:c\d+>>      InstanceFieldGet
2450   /// CHECK-DAG:      <<Conv:s\d+>>     TypeConversion [<<Get>>]
2451   /// CHECK-DAG:                        Return [<<Conv>>]
2452 
2453   /// CHECK-START: int Main.$noinline$getInt16FromInstanceCharField(Main) instruction_simplifier (after)
2454   /// CHECK-DAG:      <<Get:s\d+>>      InstanceFieldGet
2455   /// CHECK-DAG:                        Return [<<Get>>]
2456 
2457   /// CHECK-START: int Main.$noinline$getInt16FromInstanceCharField(Main) instruction_simplifier (after)
2458   /// CHECK-NOT:                        And
2459   /// CHECK-NOT:                        TypeConversion
$noinline$getInt16FromInstanceCharField(Main m)2460   public static int $noinline$getInt16FromInstanceCharField(Main m) {
2461     return (short) m.instanceCharField;
2462   }
2463 
2464   /// CHECK-START: int Main.$noinline$getInt16FromStaticCharField() instruction_simplifier (before)
2465   /// CHECK-DAG:      <<Get:c\d+>>      StaticFieldGet
2466   /// CHECK-DAG:      <<Conv:s\d+>>     TypeConversion [<<Get>>]
2467   /// CHECK-DAG:                        Return [<<Conv>>]
2468 
2469   /// CHECK-START: int Main.$noinline$getInt16FromStaticCharField() instruction_simplifier (after)
2470   /// CHECK-DAG:      <<Get:s\d+>>      StaticFieldGet
2471   /// CHECK-DAG:                        Return [<<Get>>]
2472 
2473   /// CHECK-START: int Main.$noinline$getInt16FromStaticCharField() instruction_simplifier (after)
2474   /// CHECK-NOT:                        And
2475   /// CHECK-NOT:                        TypeConversion
$noinline$getInt16FromStaticCharField()2476   public static int $noinline$getInt16FromStaticCharField() {
2477     return (short) staticCharField;
2478   }
2479 
2480   /// CHECK-START: int Main.$noinline$getInt16FromCharArray(char[]) instruction_simplifier (before)
2481   /// CHECK-DAG:      <<Get:c\d+>>      ArrayGet
2482   /// CHECK-DAG:      <<Conv:s\d+>>     TypeConversion [<<Get>>]
2483   /// CHECK-DAG:                        Return [<<Conv>>]
2484 
2485   /// CHECK-START: int Main.$noinline$getInt16FromCharArray(char[]) instruction_simplifier (after)
2486   /// CHECK-DAG:      <<Get:s\d+>>      ArrayGet
2487   /// CHECK-DAG:                        Return [<<Get>>]
2488 
2489   /// CHECK-START: int Main.$noinline$getInt16FromCharArray(char[]) instruction_simplifier (after)
2490   /// CHECK-NOT:                        And
2491   /// CHECK-NOT:                        TypeConversion
$noinline$getInt16FromCharArray(char[] a)2492   public static int $noinline$getInt16FromCharArray(char[] a) {
2493     return (short) a[0];
2494   }
2495 
2496   /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier (before)
2497   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
2498   /// CHECK-DAG:      <<Get:b\d+>>      StaticFieldGet
2499   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Const255>>]
2500   /// CHECK-DAG:      <<Invoke:i\d+>>   InvokeStaticOrDirect [<<And>>{{(,[ij]\d+)?}}]
2501   /// CHECK-DAG:                        Return [<<Invoke>>]
2502 
2503   /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier (after)
2504   /// CHECK-DAG:      <<Get:a\d+>>      StaticFieldGet
2505   /// CHECK-DAG:      <<Invoke:i\d+>>   InvokeStaticOrDirect [<<Get>>{{(,[ij]\d+)?}}]
2506   /// CHECK-DAG:                        Return [<<Invoke>>]
2507 
2508   /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier$after_inlining (before)
2509   /// CHECK-DAG:      <<Get:a\d+>>      StaticFieldGet
2510   /// CHECK-DAG:      <<Conv:b\d+>>     TypeConversion [<<Get>>]
2511   /// CHECK-DAG:                        Return [<<Conv>>]
2512 
2513   /// CHECK-START: int Main.$noinline$byteToUint8AndBack() instruction_simplifier$after_inlining (after)
2514   /// CHECK-DAG:      <<Get:b\d+>>      StaticFieldGet
2515   /// CHECK-DAG:                        Return [<<Get>>]
$noinline$byteToUint8AndBack()2516   public static int $noinline$byteToUint8AndBack() {
2517     return $inline$toByte(staticByteField & 0xff);
2518   }
2519 
$inline$toByte(int value)2520   public static int $inline$toByte(int value) {
2521     return (byte) value;
2522   }
2523 
2524   /// CHECK-START: int Main.$noinline$getStaticCharFieldAnd0xff() instruction_simplifier (before)
2525   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
2526   /// CHECK-DAG:      <<Get:c\d+>>      StaticFieldGet
2527   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Const255>>]
2528   /// CHECK-DAG:                        Return [<<And>>]
2529 
2530   /// CHECK-START: int Main.$noinline$getStaticCharFieldAnd0xff() instruction_simplifier (after)
2531   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
2532   /// CHECK-DAG:      <<Get:c\d+>>      StaticFieldGet
2533   /// CHECK-DAG:      <<Cnv:a\d+>>      TypeConversion [<<Get>>]
2534   /// CHECK-DAG:                        Return [<<Cnv>>]
2535 
2536   /// CHECK-START: int Main.$noinline$getStaticCharFieldAnd0xff() instruction_simplifier (after)
2537   /// CHECK-NOT:      {{a\d+}}          StaticFieldGet
$noinline$getStaticCharFieldAnd0xff()2538   public static int $noinline$getStaticCharFieldAnd0xff() {
2539     return staticCharField & 0xff;
2540   }
2541 
2542   /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main) instruction_simplifier (before)
2543   /// CHECK-DAG:      <<Const8:i\d+>>   IntConstant 8
2544   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
2545   /// CHECK-DAG:      <<Get:b\d+>>      InstanceFieldGet
2546   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Const255>>]
2547   /// CHECK-DAG:      <<Shl:i\d+>>      Shl [<<Get>>,<<Const8>>]
2548   /// CHECK-DAG:      <<Add:i\d+>>      Add [<<And>>,<<Shl>>]
2549   /// CHECK-DAG:                        Return [<<Add>>]
2550 
2551   /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main) instruction_simplifier (after)
2552   /// CHECK-DAG:      <<Const8:i\d+>>   IntConstant 8
2553   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
2554   /// CHECK-DAG:      <<Get:b\d+>>      InstanceFieldGet
2555   /// CHECK-DAG:      <<Cnv:a\d+>>      TypeConversion [<<Get>>]
2556   /// CHECK-DAG:      <<Shl:i\d+>>      Shl [<<Get>>,<<Const8>>]
2557   /// CHECK-DAG:      <<Add:i\d+>>      Add [<<Cnv>>,<<Shl>>]
2558   /// CHECK-DAG:                        Return [<<Add>>]
2559 
2560   /// CHECK-START: int Main.$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main) instruction_simplifier (after)
2561   /// CHECK-NOT:      {{a\d+}}          InstanceFieldGet
$noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main m)2562   public static int $noinline$getUint8FromInstanceByteFieldWithAnotherUse(Main m) {
2563     byte b = m.instanceByteField;
2564     int v1 = b & 0xff;
2565     int v2 = (b << 8);
2566     return v1 + v2;
2567   }
2568 
2569   /// CHECK-START: int Main.$noinline$intAnd0xffToChar(int) instruction_simplifier (before)
2570   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
2571   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
2572   /// CHECK-DAG:      <<And:i\d+>>      And [<<Arg>>,<<Const255>>]
2573   /// CHECK-DAG:      <<Conv:c\d+>>     TypeConversion [<<And>>]
2574   /// CHECK-DAG:                        Return [<<Conv>>]
2575 
2576   /// CHECK-START: int Main.$noinline$intAnd0xffToChar(int) instruction_simplifier (after)
2577   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
2578   /// CHECK-DAG:      <<Conv:a\d+>>     TypeConversion [<<Arg>>]
2579   /// CHECK-DAG:                        Return [<<Conv>>]
$noinline$intAnd0xffToChar(int value)2580   public static int $noinline$intAnd0xffToChar(int value) {
2581     return (char) (value & 0xff);
2582   }
2583 
2584   /// CHECK-START: int Main.$noinline$intAnd0x1ffToChar(int) instruction_simplifier (before)
2585   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
2586   /// CHECK-DAG:      <<Const511:i\d+>> IntConstant 511
2587   /// CHECK-DAG:      <<And:i\d+>>      And [<<Arg>>,<<Const511>>]
2588   /// CHECK-DAG:      <<Conv:c\d+>>     TypeConversion [<<And>>]
2589   /// CHECK-DAG:                        Return [<<Conv>>]
2590 
2591   // TODO: Simplify this. Unlike the $noinline$intAnd0xffToChar(), the TypeConversion
2592   // to `char` is not eliminated despite the result of the And being within the `char` range.
2593 
2594   // CHECK-START: int Main.$noinline$intAnd0x1ffToChar(int) instruction_simplifier (after)
2595   // CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
2596   // CHECK-DAG:      <<Const511:i\d+>> IntConstant 511
2597   // CHECK-DAG:      <<And:i\d+>>      And [<<Arg>>,<<Const511>>]
2598   // CHECK-DAG:                        Return [<<And>>]
$noinline$intAnd0x1ffToChar(int value)2599   public static int $noinline$intAnd0x1ffToChar(int value) {
2600     return (char) (value & 0x1ff);
2601   }
2602 
2603   /// CHECK-START: int Main.$noinline$getInstanceCharFieldAnd0x1ffff(Main) instruction_simplifier (before)
2604   /// CHECK-DAG:      <<Cst1ffff:i\d+>> IntConstant 131071
2605   /// CHECK-DAG:      <<Get:c\d+>>      InstanceFieldGet
2606   /// CHECK-DAG:      <<And:i\d+>>      And [<<Get>>,<<Cst1ffff>>]
2607   /// CHECK-DAG:                        Return [<<And>>]
2608 
2609   /// CHECK-START: int Main.$noinline$getInstanceCharFieldAnd0x1ffff(Main) instruction_simplifier (after)
2610   /// CHECK-DAG:      <<Get:c\d+>>      InstanceFieldGet
2611   /// CHECK-DAG:                        Return [<<Get>>]
$noinline$getInstanceCharFieldAnd0x1ffff(Main m)2612   public static int $noinline$getInstanceCharFieldAnd0x1ffff(Main m) {
2613     return m.instanceCharField & 0x1ffff;
2614   }
2615 
2616   /// CHECK-START: int Main.$noinline$bug68142795Byte(byte) instruction_simplifier (before)
2617   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
2618   /// CHECK-DAG:      <<Const:i\d+>>    IntConstant 255
2619   /// CHECK-DAG:      <<And1:i\d+>>     And [<<Arg>>,<<Const>>]
2620   /// CHECK-DAG:      <<And2:i\d+>>     And [<<And1>>,<<Const>>]
2621   /// CHECK-DAG:      <<Conv:b\d+>>     TypeConversion [<<And2>>]
2622   /// CHECK-DAG:                        Return [<<Conv>>]
2623 
2624   /// CHECK-START: int Main.$noinline$bug68142795Byte(byte) instruction_simplifier (after)
2625   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
2626   /// CHECK-DAG:                        Return [<<Arg>>]
$noinline$bug68142795Byte(byte b)2627   public static int $noinline$bug68142795Byte(byte b) {
2628     return (byte)(0xff & (b & 0xff));
2629   }
2630 
2631   /// CHECK-START: int Main.$noinline$bug68142795Elaborate(byte) instruction_simplifier (before)
2632   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
2633   /// CHECK-DAG:      <<Int255:i\d+>>   IntConstant 255
2634   /// CHECK-DAG:      <<Long255:j\d+>>  LongConstant 255
2635   /// CHECK-DAG:      <<And1:i\d+>>     And [<<Arg>>,<<Int255>>]
2636   /// CHECK-DAG:      <<Conv1:j\d+>>    TypeConversion [<<And1>>]
2637   /// CHECK-DAG:      <<And2:j\d+>>     And [<<Conv1>>,<<Long255>>]
2638   /// CHECK-DAG:      <<Conv2:i\d+>>    TypeConversion [<<And2>>]
2639   /// CHECK-DAG:      <<Conv3:b\d+>>    TypeConversion [<<Conv2>>]
2640   /// CHECK-DAG:                        Return [<<Conv3>>]
2641 
2642   /// CHECK-START: int Main.$noinline$bug68142795Elaborate(byte) instruction_simplifier (after)
2643   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
2644   /// CHECK-DAG:                        Return [<<Arg>>]
$noinline$bug68142795Elaborate(byte b)2645   public static int $noinline$bug68142795Elaborate(byte b) {
2646     return (byte)((int)(((long)(b & 0xff)) & 255L));
2647   }
2648 
2649   /// CHECK-START: int Main.$noinline$emptyStringIndexOf(int) instruction_simplifier (before)
2650   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
2651   /// CHECK-DAG:      <<Empty:l\d+>>    LoadString
2652   /// CHECK-DAG:      <<Equals:i\d+>>   InvokeVirtual [<<Empty>>,<<Arg>>] intrinsic:StringIndexOf
2653   /// CHECK-DAG:                        Return [<<Equals>>]
2654 
2655   /// CHECK-START: int Main.$noinline$emptyStringIndexOf(int) instruction_simplifier (after)
2656   /// CHECK-NOT:                        InvokeVirtual
2657 
2658   /// CHECK-START: int Main.$noinline$emptyStringIndexOf(int) instruction_simplifier (after)
2659   /// CHECK-DAG:      <<Minus1:i\d+>>   IntConstant -1
2660   /// CHECK-DAG:                        Return [<<Minus1>>]
$noinline$emptyStringIndexOf(int ch)2661   public static int $noinline$emptyStringIndexOf(int ch) {
2662     return "".indexOf(ch);
2663   }
2664 
2665   /// CHECK-START: int Main.$noinline$emptyStringIndexOfAfter(int, int) instruction_simplifier (before)
2666   /// CHECK-DAG:      <<Arg1:i\d+>>     ParameterValue
2667   /// CHECK-DAG:      <<Arg2:i\d+>>     ParameterValue
2668   /// CHECK-DAG:      <<Empty:l\d+>>    LoadString
2669   /// CHECK-DAG:      <<Equals:i\d+>>   InvokeVirtual [<<Empty>>,<<Arg1>>,<<Arg2>>] intrinsic:StringIndexOfAfter
2670   /// CHECK-DAG:                        Return [<<Equals>>]
2671 
2672   /// CHECK-START: int Main.$noinline$emptyStringIndexOfAfter(int, int) instruction_simplifier (after)
2673   /// CHECK-NOT:                        InvokeVirtual
2674 
2675   /// CHECK-START: int Main.$noinline$emptyStringIndexOfAfter(int, int) instruction_simplifier (after)
2676   /// CHECK-DAG:      <<Minus1:i\d+>>   IntConstant -1
2677   /// CHECK-DAG:                        Return [<<Minus1>>]
$noinline$emptyStringIndexOfAfter(int ch, int fromIndex)2678   public static int $noinline$emptyStringIndexOfAfter(int ch, int fromIndex) {
2679     return "".indexOf(ch, fromIndex);
2680   }
2681 
2682   /// CHECK-START: int Main.$noinline$singleCharStringIndexOf(int) instruction_simplifier (before)
2683   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
2684   /// CHECK-DAG:      <<Empty:l\d+>>    LoadString
2685   /// CHECK-DAG:      <<Equals:i\d+>>   InvokeVirtual [<<Empty>>,<<Arg>>] intrinsic:StringIndexOf
2686   /// CHECK-DAG:                        Return [<<Equals>>]
2687 
2688   /// CHECK-START: int Main.$noinline$singleCharStringIndexOf(int) instruction_simplifier (after)
2689   /// CHECK-NOT:                        InvokeVirtual
2690 
2691   /// CHECK-START: int Main.$noinline$singleCharStringIndexOf(int) instruction_simplifier (after)
2692   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
2693   /// CHECK-DAG:      <<x:i\d+>>        IntConstant 120
2694   /// CHECK-DAG:      <<Zero:i\d+>>     IntConstant 0
2695   /// CHECK-DAG:      <<Minus1:i\d+>>   IntConstant -1
2696   /// CHECK-DAG:      <<Eq:z\d+>>       Equal [<<Arg>>,<<x>>]
2697   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Minus1>>,<<Zero>>,<<Eq>>]
2698   /// CHECK-DAG:                        Return [<<Select>>]
$noinline$singleCharStringIndexOf(int ch)2699   public static int $noinline$singleCharStringIndexOf(int ch) {
2700     return "x".indexOf(ch);
2701   }
2702 
2703   /// CHECK-START: int Main.$noinline$singleCharStringIndexOfAfter(int, int) instruction_simplifier (before)
2704   /// CHECK-DAG:      <<Arg1:i\d+>>     ParameterValue
2705   /// CHECK-DAG:      <<Arg2:i\d+>>     ParameterValue
2706   /// CHECK-DAG:      <<Empty:l\d+>>    LoadString
2707   /// CHECK-DAG:      <<Equals:i\d+>>   InvokeVirtual [<<Empty>>,<<Arg1>>,<<Arg2>>] intrinsic:StringIndexOfAfter
2708   /// CHECK-DAG:                        Return [<<Equals>>]
2709 
2710   /// CHECK-START: int Main.$noinline$singleCharStringIndexOfAfter(int, int) instruction_simplifier (after)
2711   /// CHECK-DAG:      <<Arg1:i\d+>>     ParameterValue
2712   /// CHECK-DAG:      <<Arg2:i\d+>>     ParameterValue
2713   /// CHECK-DAG:      <<Empty:l\d+>>    LoadString
2714   /// CHECK-DAG:      <<Equals:i\d+>>   InvokeVirtual [<<Empty>>,<<Arg1>>,<<Arg2>>] intrinsic:StringIndexOfAfter
2715   /// CHECK-DAG:                        Return [<<Equals>>]
$noinline$singleCharStringIndexOfAfter(int ch, int fromIndex)2716   public static int $noinline$singleCharStringIndexOfAfter(int ch, int fromIndex) {
2717     return "x".indexOf(ch, fromIndex);  // Not simplified.
2718   }
2719 
2720   /// CHECK-START: byte Main.$noinline$redundantAndNotRedundant(int) instruction_simplifier (before)
2721   /// CHECK-DAG:                       And
2722 
2723   /// CHECK-START: byte Main.$noinline$redundantAndNotRedundant(int) instruction_simplifier (after)
2724   /// CHECK-DAG:                       And
$noinline$redundantAndNotRedundant(int value)2725   public static byte $noinline$redundantAndNotRedundant(int value) {
2726     // Here the AND is not redundant. This test checks that it is not removed.
2727     // 0xf500 = 1111 0101 0000 0000 - bits [11:8] of value will be changed by
2728     // the AND with 0101. These bits are kept following the SHR and TypeConversion.
2729     return (byte) ((value & 0xf500) >> 8);
2730   }
2731 
2732   /// CHECK-START:  byte Main.$noinline$redundantAndOtherUse(int) instruction_simplifier (before)
2733   /// CHECK-DAG:                       And
2734 
2735   /// CHECK-START:  byte Main.$noinline$redundantAndOtherUse(int) instruction_simplifier (after)
2736   /// CHECK-DAG:                       And
$noinline$redundantAndOtherUse(int value)2737   public static byte $noinline$redundantAndOtherUse(int value){
2738     int v1 = value & 0xff00;
2739     // Above AND is redundant in the context of calculating v2.
2740     byte v2 = (byte) (v1 >> 8);
2741     byte v3 = (byte) (v1 - 0x6eef);
2742     // Use of AND result (v1) in calculating v3 means AND must not be removed.
2743     return (byte) (v2 - v3);
2744   }
2745 
2746   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift2(short) instruction_simplifier (before)
2747   /// CHECK-DAG:                       And
2748 
2749   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift2(short) instruction_simplifier (after)
2750   /// CHECK-NOT:                       And
$noinline$redundantAndShortToByteShift2(short value)2751   public static byte $noinline$redundantAndShortToByteShift2(short value) {
2752     // & 0xfff only changes bits higher than bit number 12 inclusive.
2753     // These bits are discarded during Type Conversion to byte.
2754     // Therefore AND is redundant and should be removed.
2755     return (byte) ((value & 0xfff) >> 2);
2756   }
2757 
2758   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift5(short) instruction_simplifier (before)
2759   /// CHECK-DAG:                       And
2760 
2761   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift5(short) instruction_simplifier (after)
2762   /// CHECK-NOT:                       And
$noinline$redundantAndShortToByteShift5(short value)2763   public static byte $noinline$redundantAndShortToByteShift5(short value) {
2764     // & 0xffe0 changes bits [4:0] and bits higher than 16 inclusive.
2765     // These bits are discarded by the right shift and type conversion.
2766     // Therefore AND is redundant and should be removed.
2767     return (byte) ((value & 0xffe0) >> 5);
2768   }
2769 
2770   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift8(short) instruction_simplifier (before)
2771   /// CHECK-DAG:                       And
2772 
2773   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift8(short) instruction_simplifier (after)
2774   /// CHECK-NOT:                       And
$noinline$redundantAndShortToByteShift8(short value)2775   public static byte $noinline$redundantAndShortToByteShift8(short value) {
2776     return (byte) ((value & 0xff00) >> 8);
2777   }
2778 
2779   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift9NotRedundant(short) instruction_simplifier (before)
2780   /// CHECK-DAG:                       And
2781 
2782   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift9NotRedundant(short) instruction_simplifier (after)
2783   /// CHECK-DAG:                       And
$noinline$redundantAndShortToByteShift9NotRedundant(short value)2784   public static byte $noinline$redundantAndShortToByteShift9NotRedundant(short value) {
2785     // Byte and Short operands for bitwise operations (e.g. &,>>) are promoted to Int32 prior to operation.
2786     // Negative operands will be sign extended accordingly: (short: 0xff45) --> (int: 0xffffff45)
2787     // & fe00 will clear bits [31:16]. For negative 'value', this will clear sign bits.
2788     // Without the AND, the right shift will move the sign extended ones into the result instead of zeros.
2789     // Therefore AND is not redundant and should not be removed.
2790     return (byte) ((value & 0xfe00) >> 9);
2791   }
2792 
2793   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift10NotRedundant(short) instruction_simplifier (before)
2794   /// CHECK-DAG:                       And
2795 
2796   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift10NotRedundant(short) instruction_simplifier (after)
2797   /// CHECK-DAG:                       And
$noinline$redundantAndShortToByteShift10NotRedundant(short value)2798   public static byte $noinline$redundantAndShortToByteShift10NotRedundant(short value) {
2799     return (byte) ((value & 0x1ffff) >> 10);
2800   }
2801 
2802   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift12(short) instruction_simplifier (before)
2803   /// CHECK-DAG:                       And
2804 
2805   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift12(short) instruction_simplifier (after)
2806   /// CHECK-NOT:                       And
$noinline$redundantAndShortToByteShift12(short value)2807   public static byte $noinline$redundantAndShortToByteShift12(short value) {
2808     // & fff00 preserves bits [19:8] and clears all others.
2809     // Here the AND preserves enough ones; such that zeros are moved into the result.
2810     // Therefore AND is redundant and can be removed.
2811     return (byte) ((value & 0xfff00) >> 12);
2812   }
2813 
2814   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift15(short) instruction_simplifier (before)
2815   /// CHECK-DAG:                       And
2816 
2817   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift15(short) instruction_simplifier (after)
2818   /// CHECK-NOT:                       And
$noinline$redundantAndShortToByteShift15(short value)2819   public static byte $noinline$redundantAndShortToByteShift15(short value) {
2820     return (byte) ((value & 0xffff00) >> 15);
2821   }
2822 
2823   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift16(short) instruction_simplifier (before)
2824   /// CHECK-DAG:                       And
2825 
2826   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShift16(short) instruction_simplifier (after)
2827   /// CHECK-NOT:                       And
$noinline$redundantAndShortToByteShift16(short value)2828   public static byte $noinline$redundantAndShortToByteShift16(short value) {
2829     return (byte) ((value & 0xf0ffff00) >> 16);
2830   }
2831 
2832   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift2(int) instruction_simplifier (before)
2833   /// CHECK-DAG:                       And
2834 
2835   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift2(int) instruction_simplifier (after)
2836   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShift2(int value)2837   public static byte $noinline$redundantAndIntToByteShift2(int value) {
2838     return (byte) ((value & 0xfff) >> 2);
2839   }
2840 
2841   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift5(int) instruction_simplifier (before)
2842   /// CHECK-DAG:                       And
2843 
2844   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift5(int) instruction_simplifier (after)
2845   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShift5(int value)2846   public static byte $noinline$redundantAndIntToByteShift5(int value) {
2847     return (byte) ((value & 0xffe0) >> 5);
2848   }
2849 
2850   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift8(int) instruction_simplifier (before)
2851   /// CHECK-DAG:                       And
2852 
2853   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift8(int) instruction_simplifier (after)
2854   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShift8(int value)2855   public static byte $noinline$redundantAndIntToByteShift8(int value) {
2856     return (byte) ((value & 0xffffff00) >> 8);
2857   }
2858 
2859   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift9(int) instruction_simplifier (before)
2860   /// CHECK-DAG:                       And
2861 
2862   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift9(int) instruction_simplifier (after)
2863   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShift9(int value)2864   public static byte $noinline$redundantAndIntToByteShift9(int value) {
2865     return (byte) ((value & 0xf001fe00) >> 9);
2866   }
2867 
2868   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift16(int) instruction_simplifier (before)
2869   /// CHECK-DAG:                       And
2870 
2871   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift16(int) instruction_simplifier (after)
2872   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShift16(int value)2873   public static byte $noinline$redundantAndIntToByteShift16(int value) {
2874     return (byte) ((value & 0xf0ff0000) >> 16);
2875   }
2876 
2877   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift20(int) instruction_simplifier (before)
2878   /// CHECK-DAG:                       And
2879 
2880   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift20(int) instruction_simplifier (after)
2881   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShift20(int value)2882   public static byte $noinline$redundantAndIntToByteShift20(int value) {
2883     return (byte) ((value & 0xfff00000) >> 20);
2884   }
2885 
2886   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift25(int) instruction_simplifier (before)
2887   /// CHECK-DAG:                       And
2888 
2889   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift25(int) instruction_simplifier (after)
2890   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShift25(int value)2891   public static byte $noinline$redundantAndIntToByteShift25(int value) {
2892     return (byte) ((value & 0xfe000000) >> 25);
2893   }
2894 
2895   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift24(int) instruction_simplifier (before)
2896   /// CHECK-DAG:                       And
2897 
2898   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift24(int) instruction_simplifier (after)
2899   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShift24(int value)2900   public static byte $noinline$redundantAndIntToByteShift24(int value) {
2901     return (byte) ((value & 0xff000000) >> 24);
2902   }
2903 
2904   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift31(int) instruction_simplifier (before)
2905   /// CHECK-DAG:                       And
2906 
2907   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShift31(int) instruction_simplifier (after)
2908   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShift31(int value)2909   public static byte $noinline$redundantAndIntToByteShift31(int value) {
2910     return (byte) ((value & 0xff000000) >> 31);
2911   }
2912 
2913   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShortAndConstant(short) instruction_simplifier (before)
2914   /// CHECK-DAG:                       And
2915 
2916   /// CHECK-START: byte Main.$noinline$redundantAndShortToByteShortAndConstant(short) instruction_simplifier (after)
2917   /// CHECK-NOT:                       And
$noinline$redundantAndShortToByteShortAndConstant(short value)2918   public static byte $noinline$redundantAndShortToByteShortAndConstant(short value) {
2919     short and_constant = (short) 0xff00;
2920     return (byte) ((value & and_constant) >> 16);
2921   }
2922 
2923   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShortAndConstant(int) instruction_simplifier (before)
2924   /// CHECK-DAG:                       And
2925 
2926   /// CHECK-START: byte Main.$noinline$redundantAndIntToByteShortAndConstant(int) instruction_simplifier (after)
2927   /// CHECK-NOT:                       And
$noinline$redundantAndIntToByteShortAndConstant(int value)2928   public static byte $noinline$redundantAndIntToByteShortAndConstant(int value) {
2929     short and_constant = (short) 0xff00;
2930     return (byte) ((value & and_constant) >> 16);
2931   }
2932 
2933   /// CHECK-START: byte Main.$noinline$redundantAndRegressionNotConstant(int, int) instruction_simplifier (before)
2934   /// CHECK-DAG:                       And
2935 
2936   /// CHECK-START: byte Main.$noinline$redundantAndRegressionNotConstant(int, int) instruction_simplifier (after)
2937   /// CHECK-DAG:                       And
$noinline$redundantAndRegressionNotConstant(int value, int mask)2938   public static byte $noinline$redundantAndRegressionNotConstant(int value, int mask) {
2939     return (byte) ((value & mask) >> 8);
2940   }
2941 
2942   /// CHECK-START: int Main.$noinline$deadAddAfterUnrollingAndSimplification(int[]) dead_code_elimination$before_codegen (before)
2943   /// CHECK-DAG: <<Param:l\d+>>     ParameterValue                             loop:none
2944   /// CHECK-DAG: <<Const0:i\d+>>    IntConstant 0                              loop:none
2945   /// CHECK-DAG: <<Const1:i\d+>>    IntConstant 1                              loop:none
2946   /// CHECK-DAG: <<Const2:i\d+>>    IntConstant 2                              loop:none
2947   /// CHECK-DAG: <<IndexPhi:i\d+>>  Phi [<<Const0>>,{{i\d+}}]                  loop:<<Loop:B\d+>> outer_loop:none
2948   //            Induction variable:
2949   /// CHECK-DAG:                    Add [<<IndexPhi>>,<<Const2>>]              loop:<<Loop>>      outer_loop:none
2950   //            Array Element Addition:
2951   /// CHECK-DAG: <<Store1:i\d+>>    Add [{{i\d+}},<<Const1>>]                  loop:<<Loop>>      outer_loop:none
2952   /// CHECK-DAG: <<Store2:i\d+>>    Add [{{i\d+}},<<Const2>>]                  loop:<<Loop>>      outer_loop:none
2953   /// CHECK-DAG:                    ArraySet [<<Param>>,<<Const0>>,<<Store2>>] loop:<<Loop>>      outer_loop:none
2954 
2955   /// CHECK-START: int Main.$noinline$deadAddAfterUnrollingAndSimplification(int[]) dead_code_elimination$before_codegen (before)
2956   /// CHECK:                        Add
2957   /// CHECK:                        Add
2958   /// CHECK:                        Add
2959   /// CHECK:                        Add
2960   /// CHECK-NOT:                    Add
2961 
2962   /// CHECK-START: int Main.$noinline$deadAddAfterUnrollingAndSimplification(int[]) dead_code_elimination$before_codegen (after)
2963   /// CHECK-DAG: <<Param:l\d+>>     ParameterValue                             loop:none
2964   /// CHECK-DAG: <<Const0:i\d+>>    IntConstant 0                              loop:none
2965   /// CHECK-DAG: <<Const2:i\d+>>    IntConstant 2                              loop:none
2966   /// CHECK-DAG: <<IndexPhi:i\d+>>  Phi [<<Const0>>,{{i\d+}}]                  loop:<<Loop:B\d+>> outer_loop:none
2967   //            Induction variable:
2968   /// CHECK-DAG:                    Add [<<IndexPhi>>,<<Const2>>]              loop:<<Loop>>      outer_loop:none
2969   //            Array Element Addition:
2970   /// CHECK-DAG: <<Store:i\d+>>     Add [{{i\d+}},<<Const2>>]                  loop:<<Loop>>      outer_loop:none
2971   /// CHECK-DAG:                    ArraySet [<<Param>>,<<Const0>>,<<Store>>] loop:<<Loop>>      outer_loop:none
2972 
2973   /// CHECK-START: int Main.$noinline$deadAddAfterUnrollingAndSimplification(int[]) dead_code_elimination$before_codegen (after)
2974   /// CHECK:                        Add
2975   /// CHECK:                        Add
2976   /// CHECK-NOT:                    Add
$noinline$deadAddAfterUnrollingAndSimplification(int[] array)2977   public static int $noinline$deadAddAfterUnrollingAndSimplification(int[] array) {
2978     for (int i = 0; i < 50; ++i) {
2979         // Array access prevents transformation to closed-form expression
2980         array[0]++;
2981     }
2982     return array[0];
2983   }
2984 
2985   // If a == b returns b (which is equal to a) else returns a. This can be simplified to just
2986   // return a.
2987 
2988   /// CHECK-START: int Main.$noinline$returnSecondIfEqualElseFirstInt(int, int) instruction_simplifier$after_gvn (before)
2989   /// CHECK:     <<Param1:i\d+>> ParameterValue
2990   /// CHECK:     <<Param2:i\d+>> ParameterValue
2991   /// CHECK:     <<Select:i\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
2992   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
2993 
2994   /// CHECK-START: int Main.$noinline$returnSecondIfEqualElseFirstInt(int, int) instruction_simplifier$after_gvn (after)
2995   /// CHECK:     <<Param1:i\d+>> ParameterValue
2996   /// CHECK:     <<Param2:i\d+>> ParameterValue
2997   /// CHECK:     <<Return:v\d+>> Return [<<Param1>>]
2998 
2999   /// CHECK-START: int Main.$noinline$returnSecondIfEqualElseFirstInt(int, int) instruction_simplifier$after_gvn (after)
3000   /// CHECK-NOT: Select
$noinline$returnSecondIfEqualElseFirstInt(int a, int b)3001   private static int $noinline$returnSecondIfEqualElseFirstInt(int a, int b) {
3002     return a == b ? b : a;
3003   }
3004 
3005   /// CHECK-START: long Main.$noinline$returnSecondIfEqualElseFirstLong(long, long) instruction_simplifier$after_gvn (before)
3006   /// CHECK:     <<Param1:j\d+>> ParameterValue
3007   /// CHECK:     <<Param2:j\d+>> ParameterValue
3008   /// CHECK:     <<Select:j\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3009   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
3010 
3011   /// CHECK-START: long Main.$noinline$returnSecondIfEqualElseFirstLong(long, long) instruction_simplifier$after_gvn (after)
3012   /// CHECK:     <<Param1:j\d+>> ParameterValue
3013   /// CHECK:     <<Param2:j\d+>> ParameterValue
3014   /// CHECK:     <<Return:v\d+>> Return [<<Param1>>]
3015 
3016   /// CHECK-START: long Main.$noinline$returnSecondIfEqualElseFirstLong(long, long) instruction_simplifier$after_gvn (after)
3017   /// CHECK-NOT: Select
$noinline$returnSecondIfEqualElseFirstLong(long a, long b)3018   private static long $noinline$returnSecondIfEqualElseFirstLong(long a, long b) {
3019     return a == b ? b : a;
3020   }
3021 
3022   // Note that we do not do the optimization for Float/Double.
3023 
3024   /// CHECK-START: float Main.$noinline$returnSecondIfEqualElseFirstFloat(float, float) instruction_simplifier$after_gvn (before)
3025   /// CHECK:     <<Param1:f\d+>> ParameterValue
3026   /// CHECK:     <<Param2:f\d+>> ParameterValue
3027   /// CHECK:     <<Select:f\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3028   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
3029 
3030   /// CHECK-START: float Main.$noinline$returnSecondIfEqualElseFirstFloat(float, float) disassembly (after)
3031   /// CHECK:     <<Param1:f\d+>> ParameterValue
3032   /// CHECK:     <<Param2:f\d+>> ParameterValue
3033   /// CHECK:     <<Select:f\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3034   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
$noinline$returnSecondIfEqualElseFirstFloat(float a, float b)3035   private static float $noinline$returnSecondIfEqualElseFirstFloat(float a, float b) {
3036     return a == b ? b : a;
3037   }
3038 
3039   /// CHECK-START: double Main.$noinline$returnSecondIfEqualElseFirstDouble(double, double) instruction_simplifier$after_gvn (before)
3040   /// CHECK:     <<Param1:d\d+>> ParameterValue
3041   /// CHECK:     <<Param2:d\d+>> ParameterValue
3042   /// CHECK:     <<Select:d\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3043   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
3044 
3045   /// CHECK-START: double Main.$noinline$returnSecondIfEqualElseFirstDouble(double, double) disassembly (after)
3046   /// CHECK:     <<Param1:d\d+>> ParameterValue
3047   /// CHECK:     <<Param2:d\d+>> ParameterValue
3048   /// CHECK:     <<Select:d\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3049   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
$noinline$returnSecondIfEqualElseFirstDouble(double a, double b)3050   private static double $noinline$returnSecondIfEqualElseFirstDouble(double a, double b) {
3051     return a == b ? b : a;
3052   }
3053 
3054   // If a != b returns b else returns a (which is equal to b). This can be simplified to just
3055   // return b.
3056 
3057   /// CHECK-START: int Main.$noinline$returnSecondIfNotEqualElseFirstInt(int, int) instruction_simplifier$after_gvn (before)
3058   /// CHECK:     <<Param1:i\d+>> ParameterValue
3059   /// CHECK:     <<Param2:i\d+>> ParameterValue
3060   /// CHECK:     <<Select:i\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3061   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
3062 
3063   /// CHECK-START: int Main.$noinline$returnSecondIfNotEqualElseFirstInt(int, int) instruction_simplifier$after_gvn (after)
3064   /// CHECK:     <<Param1:i\d+>> ParameterValue
3065   /// CHECK:     <<Param2:i\d+>> ParameterValue
3066   /// CHECK:     <<Return:v\d+>> Return [<<Param2>>]
3067 
3068   /// CHECK-START: int Main.$noinline$returnSecondIfNotEqualElseFirstInt(int, int) instruction_simplifier$after_gvn (after)
3069   /// CHECK-NOT: Select
$noinline$returnSecondIfNotEqualElseFirstInt(int a, int b)3070   private static int $noinline$returnSecondIfNotEqualElseFirstInt(int a, int b) {
3071     return a != b ? b : a;
3072   }
3073 
3074   /// CHECK-START: long Main.$noinline$returnSecondIfNotEqualElseFirstLong(long, long) instruction_simplifier$after_gvn (before)
3075   /// CHECK:     <<Param1:j\d+>> ParameterValue
3076   /// CHECK:     <<Param2:j\d+>> ParameterValue
3077   /// CHECK:     <<Select:j\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3078   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
3079 
3080   /// CHECK-START: long Main.$noinline$returnSecondIfNotEqualElseFirstLong(long, long) instruction_simplifier$after_gvn (after)
3081   /// CHECK:     <<Param1:j\d+>> ParameterValue
3082   /// CHECK:     <<Param2:j\d+>> ParameterValue
3083   /// CHECK:     <<Return:v\d+>> Return [<<Param2>>]
3084 
3085   /// CHECK-START: long Main.$noinline$returnSecondIfNotEqualElseFirstLong(long, long) instruction_simplifier$after_gvn (after)
3086   /// CHECK-NOT: Select
$noinline$returnSecondIfNotEqualElseFirstLong(long a, long b)3087   private static long $noinline$returnSecondIfNotEqualElseFirstLong(long a, long b) {
3088     return a != b ? b : a;
3089   }
3090 
3091   // Note that we do not do the optimization for Float/Double.
3092 
3093   /// CHECK-START: float Main.$noinline$returnSecondIfNotEqualElseFirstFloat(float, float) instruction_simplifier$after_gvn (before)
3094   /// CHECK:     <<Param1:f\d+>> ParameterValue
3095   /// CHECK:     <<Param2:f\d+>> ParameterValue
3096   /// CHECK:     <<Select:f\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3097   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
3098 
3099   /// CHECK-START: float Main.$noinline$returnSecondIfNotEqualElseFirstFloat(float, float) disassembly (after)
3100   /// CHECK:     <<Param1:f\d+>> ParameterValue
3101   /// CHECK:     <<Param2:f\d+>> ParameterValue
3102   /// CHECK:     <<Select:f\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3103   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
$noinline$returnSecondIfNotEqualElseFirstFloat(float a, float b)3104   private static float $noinline$returnSecondIfNotEqualElseFirstFloat(float a, float b) {
3105     return a != b ? b : a;
3106   }
3107 
3108   /// CHECK-START: double Main.$noinline$returnSecondIfNotEqualElseFirstDouble(double, double) instruction_simplifier$after_gvn (before)
3109   /// CHECK:     <<Param1:d\d+>> ParameterValue
3110   /// CHECK:     <<Param2:d\d+>> ParameterValue
3111   /// CHECK:     <<Select:d\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3112   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
3113 
3114   /// CHECK-START: double Main.$noinline$returnSecondIfNotEqualElseFirstDouble(double, double) disassembly (after)
3115   /// CHECK:     <<Param1:d\d+>> ParameterValue
3116   /// CHECK:     <<Param2:d\d+>> ParameterValue
3117   /// CHECK:     <<Select:d\d+>> Select [<<Param2>>,<<Param1>>,<<Cond:z\d+>>]
3118   /// CHECK:     <<Return:v\d+>> Return [<<Select>>]
$noinline$returnSecondIfNotEqualElseFirstDouble(double a, double b)3119   private static double $noinline$returnSecondIfNotEqualElseFirstDouble(double a, double b) {
3120     return a != b ? b : a;
3121   }
3122 
3123   // Check that (x << N >>> N) and (x << N >> N) are simplified to corresponding TypeConversion.
3124 
3125   // Check T -> int -> Unsigned<T> -> int cases.
3126 
3127   /// CHECK-START: int Main.$noinline$testByteToIntAsUnsigned(byte) instruction_simplifier (before)
3128   /// CHECK:     <<Param:b\d+>>   ParameterValue
3129   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3130   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3131   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const24>>]
3132   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3133 
3134   /// CHECK-START: int Main.$noinline$testByteToIntAsUnsigned(byte) instruction_simplifier (after)
3135   /// CHECK:     <<Param:b\d+>>   ParameterValue
3136   /// CHECK:     <<Conv:a\d+>>    TypeConversion [<<Param>>]
3137   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3138 
3139   /// CHECK-START: int Main.$noinline$testByteToIntAsUnsigned(byte) instruction_simplifier (after)
3140   /// CHECK-NOT:                  Shl
3141 
3142   /// CHECK-START: int Main.$noinline$testByteToIntAsUnsigned(byte) instruction_simplifier (after)
3143   /// CHECK-NOT:                  UShr
$noinline$testByteToIntAsUnsigned(byte arg)3144   private static int $noinline$testByteToIntAsUnsigned(byte arg) {
3145     return arg << 24 >>> 24;
3146   }
3147 
3148   /// CHECK-START: int Main.$noinline$testShortToIntAsUnsigned(short) instruction_simplifier (before)
3149   /// CHECK:     <<Param:s\d+>>   ParameterValue
3150   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3151   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const16>>]
3152   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const16>>]
3153   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3154 
3155   /// CHECK-START: int Main.$noinline$testShortToIntAsUnsigned(short) instruction_simplifier (after)
3156   /// CHECK:     <<Param:s\d+>>   ParameterValue
3157   /// CHECK:     <<Conv:c\d+>>    TypeConversion [<<Param>>]
3158   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3159 
3160   /// CHECK-START: int Main.$noinline$testShortToIntAsUnsigned(short) instruction_simplifier (after)
3161   /// CHECK-NOT:                  Shl
3162 
3163   /// CHECK-START: int Main.$noinline$testShortToIntAsUnsigned(short) instruction_simplifier (after)
3164   /// CHECK-NOT:                  UShr
$noinline$testShortToIntAsUnsigned(short arg)3165   private static int $noinline$testShortToIntAsUnsigned(short arg) {
3166     return arg << 16 >>> 16;
3167   }
3168 
3169   /// CHECK-START: int Main.$noinline$testCharToIntAsUnsigned(char) instruction_simplifier (before)
3170   /// CHECK:     <<Param:c\d+>>   ParameterValue
3171   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3172   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const16>>]
3173   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const16>>]
3174   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3175 
3176   /// CHECK-START: int Main.$noinline$testCharToIntAsUnsigned(char) instruction_simplifier (after)
3177   /// CHECK:     <<Param:c\d+>>   ParameterValue
3178   /// CHECK:     <<Return:v\d+>>  Return [<<Param>>]
3179 
3180   /// CHECK-START: int Main.$noinline$testCharToIntAsUnsigned(char) instruction_simplifier (after)
3181   /// CHECK-NOT:                  Shl
3182 
3183   /// CHECK-START: int Main.$noinline$testCharToIntAsUnsigned(char) instruction_simplifier (after)
3184   /// CHECK-NOT:                  UShr
$noinline$testCharToIntAsUnsigned(char arg)3185   private static int $noinline$testCharToIntAsUnsigned(char arg) {
3186     return arg << 16 >>> 16;
3187   }
3188 
3189   // Check T -> int -> Signed<T> -> int cases.
3190 
3191   /// CHECK-START: int Main.$noinline$testByteToIntAsSigned(byte) instruction_simplifier (before)
3192   /// CHECK:     <<Param:b\d+>>   ParameterValue
3193   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3194   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3195   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const24>>]
3196   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3197 
3198   /// CHECK-START: int Main.$noinline$testByteToIntAsSigned(byte) instruction_simplifier (after)
3199   /// CHECK:     <<Param:b\d+>>   ParameterValue
3200   /// CHECK:     <<Return:v\d+>>  Return [<<Param>>]
3201 
3202   /// CHECK-START: int Main.$noinline$testByteToIntAsSigned(byte) instruction_simplifier (after)
3203   /// CHECK-NOT:                  Shl
3204 
3205   /// CHECK-START: int Main.$noinline$testByteToIntAsSigned(byte) instruction_simplifier (after)
3206   /// CHECK-NOT:                  Shr
$noinline$testByteToIntAsSigned(byte arg)3207   private static int $noinline$testByteToIntAsSigned(byte arg) {
3208     return arg << 24 >> 24;
3209   }
3210 
3211   /// CHECK-START: int Main.$noinline$testShortToIntAsSigned(short) instruction_simplifier (before)
3212   /// CHECK:     <<Param:s\d+>>   ParameterValue
3213   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3214   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const16>>]
3215   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const16>>]
3216   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3217 
3218   /// CHECK-START: int Main.$noinline$testShortToIntAsSigned(short) instruction_simplifier (after)
3219   /// CHECK:     <<Param:s\d+>>   ParameterValue
3220   /// CHECK:     <<Return:v\d+>>  Return [<<Param>>]
3221 
3222   /// CHECK-START: int Main.$noinline$testShortToIntAsSigned(short) instruction_simplifier (after)
3223   /// CHECK-NOT:                  Shl
3224 
3225   /// CHECK-START: int Main.$noinline$testShortToIntAsSigned(short) instruction_simplifier (after)
3226   /// CHECK-NOT:                  Shr
$noinline$testShortToIntAsSigned(short arg)3227   private static int $noinline$testShortToIntAsSigned(short arg) {
3228     return arg << 16 >> 16;
3229   }
3230 
3231   /// CHECK-START: int Main.$noinline$testCharToIntAsSigned(char) instruction_simplifier (before)
3232   /// CHECK:     <<Param:c\d+>>   ParameterValue
3233   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3234   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const16>>]
3235   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const16>>]
3236   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3237 
3238   /// CHECK-START: int Main.$noinline$testCharToIntAsSigned(char) instruction_simplifier (after)
3239   /// CHECK:     <<Param:c\d+>>   ParameterValue
3240   /// CHECK:     <<Conv:s\d+>>    TypeConversion [<<Param>>]
3241   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3242 
3243   /// CHECK-START: int Main.$noinline$testCharToIntAsSigned(char) instruction_simplifier (after)
3244   /// CHECK-NOT:                  Shl
3245 
3246   /// CHECK-START: int Main.$noinline$testCharToIntAsSigned(char) instruction_simplifier (after)
3247   /// CHECK-NOT:                  Shr
$noinline$testCharToIntAsSigned(char arg)3248   private static int $noinline$testCharToIntAsSigned(char arg) {
3249     return arg << 16 >> 16;
3250   }
3251 
3252   // Check T -> U (narrowing) -> int cases where M is unsigned type.
3253 
3254   /// CHECK-START: int Main.$noinline$testShortToByteToIntAsUnsigned(short) instruction_simplifier (before)
3255   /// CHECK:     <<Param:s\d+>>   ParameterValue
3256   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3257   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3258   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const24>>]
3259   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3260 
3261   /// CHECK-START: int Main.$noinline$testShortToByteToIntAsUnsigned(short) instruction_simplifier (after)
3262   /// CHECK:     <<Param:s\d+>>   ParameterValue
3263   /// CHECK:     <<Conv:a\d+>>    TypeConversion [<<Param>>]
3264   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3265 
3266   /// CHECK-START: int Main.$noinline$testShortToByteToIntAsUnsigned(short) instruction_simplifier (after)
3267   /// CHECK-NOT:                  Shl
3268 
3269   /// CHECK-START: int Main.$noinline$testShortToByteToIntAsUnsigned(short) instruction_simplifier (after)
3270   /// CHECK-NOT:                  UShr
$noinline$testShortToByteToIntAsUnsigned(short arg)3271   private static int $noinline$testShortToByteToIntAsUnsigned(short arg) {
3272     return arg << 24 >>> 24;
3273   }
3274 
3275   /// CHECK-START: int Main.$noinline$testCharToByteToIntAsUnsigned(char) instruction_simplifier (before)
3276   /// CHECK:     <<Param:c\d+>>   ParameterValue
3277   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3278   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3279   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const24>>]
3280   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3281 
3282   /// CHECK-START: int Main.$noinline$testCharToByteToIntAsUnsigned(char) instruction_simplifier (after)
3283   /// CHECK:     <<Param:c\d+>>   ParameterValue
3284   /// CHECK:     <<Conv:a\d+>>    TypeConversion [<<Param>>]
3285   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3286 
3287   /// CHECK-START: int Main.$noinline$testCharToByteToIntAsUnsigned(char) instruction_simplifier (after)
3288   /// CHECK-NOT:                  Shl
3289 
3290   /// CHECK-START: int Main.$noinline$testCharToByteToIntAsUnsigned(char) instruction_simplifier (after)
3291   /// CHECK-NOT:                  UShr
$noinline$testCharToByteToIntAsUnsigned(char arg)3292   private static int $noinline$testCharToByteToIntAsUnsigned(char arg) {
3293     return arg << 24 >>> 24;
3294   }
3295 
3296   // Check T -> S (narrowing) -> int cases where S is signed type.
3297 
3298   /// CHECK-START: int Main.$noinline$testShortToByteToIntAsSigned(short) instruction_simplifier (before)
3299   /// CHECK:     <<Param:s\d+>>   ParameterValue
3300   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3301   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3302   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const24>>]
3303   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3304 
3305   /// CHECK-START: int Main.$noinline$testShortToByteToIntAsSigned(short) instruction_simplifier (after)
3306   /// CHECK:     <<Param:s\d+>>   ParameterValue
3307   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<Param>>]
3308   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3309 
3310   /// CHECK-START: int Main.$noinline$testShortToByteToIntAsSigned(short) instruction_simplifier (after)
3311   /// CHECK-NOT:                  Shl
3312 
3313   /// CHECK-START: int Main.$noinline$testShortToByteToIntAsSigned(short) instruction_simplifier (after)
3314   /// CHECK-NOT:                  Shr
$noinline$testShortToByteToIntAsSigned(short arg)3315   private static int $noinline$testShortToByteToIntAsSigned(short arg) {
3316     return arg << 24 >> 24;
3317   }
3318 
3319   /// CHECK-START: int Main.$noinline$testCharToByteToIntAsSigned(char) instruction_simplifier (before)
3320   /// CHECK:     <<Param:c\d+>>   ParameterValue
3321   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3322   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3323   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const24>>]
3324   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3325 
3326   /// CHECK-START: int Main.$noinline$testCharToByteToIntAsSigned(char) instruction_simplifier (after)
3327   /// CHECK:     <<Param:c\d+>>   ParameterValue
3328   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<Param>>]
3329   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3330 
3331   /// CHECK-START: int Main.$noinline$testCharToByteToIntAsSigned(char) instruction_simplifier (after)
3332   /// CHECK-NOT:                  Shl
3333 
3334   /// CHECK-START: int Main.$noinline$testCharToByteToIntAsSigned(char) instruction_simplifier (after)
3335   /// CHECK-NOT:                  Shr
$noinline$testCharToByteToIntAsSigned(char arg)3336   private static int $noinline$testCharToByteToIntAsSigned(char arg) {
3337     return arg << 24 >> 24;
3338   }
3339 
3340   // Check int -> U -> int cases where U is a unsigned type.
3341 
3342   /// CHECK-START: int Main.$noinline$testIntToUnsignedByteToInt(int) instruction_simplifier (before)
3343   /// CHECK:     <<Param:i\d+>>   ParameterValue
3344   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3345   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3346   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const24>>]
3347   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3348 
3349   /// CHECK-START: int Main.$noinline$testIntToUnsignedByteToInt(int) instruction_simplifier (after)
3350   /// CHECK:     <<Param:i\d+>>   ParameterValue
3351   /// CHECK:     <<Conv:a\d+>>    TypeConversion [<<Param>>]
3352   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3353 
3354   /// CHECK-START: int Main.$noinline$testIntToUnsignedByteToInt(int) instruction_simplifier (after)
3355   /// CHECK-NOT:                  Shl
3356 
3357   /// CHECK-START: int Main.$noinline$testIntToUnsignedByteToInt(int) instruction_simplifier (after)
3358   /// CHECK-NOT:                  UShr
$noinline$testIntToUnsignedByteToInt(int arg)3359   private static int $noinline$testIntToUnsignedByteToInt(int arg) {
3360     return arg << 24 >>> 24;
3361   }
3362 
3363   /// CHECK-START: int Main.$noinline$testIntToUnsignedShortToInt(int) instruction_simplifier (before)
3364   /// CHECK:     <<Param:i\d+>>   ParameterValue
3365   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3366   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const16>>]
3367   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const16>>]
3368   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3369 
3370   /// CHECK-START: int Main.$noinline$testIntToUnsignedShortToInt(int) instruction_simplifier (after)
3371   /// CHECK:     <<Param:i\d+>>   ParameterValue
3372   /// CHECK:     <<Conv:c\d+>>    TypeConversion [<<Param>>]
3373   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3374 
3375   /// CHECK-START: int Main.$noinline$testIntToUnsignedShortToInt(int) instruction_simplifier (after)
3376   /// CHECK-NOT:                  Shl
3377 
3378   /// CHECK-START: int Main.$noinline$testIntToUnsignedShortToInt(int) instruction_simplifier (after)
3379   /// CHECK-NOT:                  UShr
$noinline$testIntToUnsignedShortToInt(int arg)3380   private static int $noinline$testIntToUnsignedShortToInt(int arg) {
3381     return arg << 16 >>> 16;
3382   }
3383 
3384   // Check int -> S -> int cases where S is a signed type.
3385 
3386   /// CHECK-START: int Main.$noinline$testIntToSignedByteToInt(int) instruction_simplifier (before)
3387   /// CHECK:     <<Param:i\d+>>   ParameterValue
3388   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3389   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3390   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const24>>]
3391   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3392 
3393   /// CHECK-START: int Main.$noinline$testIntToSignedByteToInt(int) instruction_simplifier (after)
3394   /// CHECK:     <<Param:i\d+>>   ParameterValue
3395   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<Param>>]
3396   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3397 
3398   /// CHECK-START: int Main.$noinline$testIntToSignedByteToInt(int) instruction_simplifier (after)
3399   /// CHECK-NOT:                  Shl
3400 
3401   /// CHECK-START: int Main.$noinline$testIntToSignedByteToInt(int) instruction_simplifier (after)
3402   /// CHECK-NOT:                  Shr
$noinline$testIntToSignedByteToInt(int arg)3403   private static int $noinline$testIntToSignedByteToInt(int arg) {
3404     return arg << 24 >> 24;
3405   }
3406 
3407   /// CHECK-START: int Main.$noinline$testIntToSignedShortToInt(int) instruction_simplifier (before)
3408   /// CHECK:     <<Param:i\d+>>   ParameterValue
3409   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3410   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const16>>]
3411   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const16>>]
3412   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3413 
3414   /// CHECK-START: int Main.$noinline$testIntToSignedShortToInt(int) instruction_simplifier (after)
3415   /// CHECK:     <<Param:i\d+>>   ParameterValue
3416   /// CHECK:     <<Conv:s\d+>>    TypeConversion [<<Param>>]
3417   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3418 
3419   /// CHECK-START: int Main.$noinline$testIntToSignedShortToInt(int) instruction_simplifier (after)
3420   /// CHECK-NOT:                  Shl
3421 
3422   /// CHECK-START: int Main.$noinline$testIntToSignedShortToInt(int) instruction_simplifier (after)
3423   /// CHECK-NOT:                  Shr
$noinline$testIntToSignedShortToInt(int arg)3424   private static int $noinline$testIntToSignedShortToInt(int arg) {
3425     return arg << 16 >> 16;
3426   }
3427 
3428   // Check T -> U -> int cases where U is a unsigned type.
3429 
3430   /// CHECK-START: int Main.$noinline$testCharToUnsignedByteToInt(char) instruction_simplifier (before)
3431   /// CHECK:     <<Param:c\d+>>   ParameterValue
3432   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3433   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3434   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const24>>]
3435   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3436 
3437   /// CHECK-START: int Main.$noinline$testCharToUnsignedByteToInt(char) instruction_simplifier (after)
3438   /// CHECK:     <<Param:c\d+>>   ParameterValue
3439   /// CHECK:     <<Conv:a\d+>>    TypeConversion [<<Param>>]
3440   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3441 
3442   /// CHECK-START: int Main.$noinline$testCharToUnsignedByteToInt(char) instruction_simplifier (after)
3443   /// CHECK-NOT:                  Shl
3444 
3445   /// CHECK-START: int Main.$noinline$testCharToUnsignedByteToInt(char) instruction_simplifier (after)
3446   /// CHECK-NOT:                  UShr
$noinline$testCharToUnsignedByteToInt(char arg)3447   private static int $noinline$testCharToUnsignedByteToInt(char arg) {
3448     return arg << 24 >>> 24;
3449   }
3450 
3451   /// CHECK-START: int Main.$noinline$testShortToUnsignedByteToInt(short) instruction_simplifier (before)
3452   /// CHECK:     <<Param:s\d+>>   ParameterValue
3453   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3454   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3455   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const24>>]
3456   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3457 
3458   /// CHECK-START: int Main.$noinline$testShortToUnsignedByteToInt(short) instruction_simplifier (after)
3459   /// CHECK:     <<Param:s\d+>>   ParameterValue
3460   /// CHECK:     <<Conv:a\d+>>    TypeConversion [<<Param>>]
3461   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3462 
3463   /// CHECK-START: int Main.$noinline$testShortToUnsignedByteToInt(short) instruction_simplifier (after)
3464   /// CHECK-NOT:                  Shl
3465 
3466   /// CHECK-START: int Main.$noinline$testShortToUnsignedByteToInt(short) instruction_simplifier (after)
3467   /// CHECK-NOT:                  UShr
$noinline$testShortToUnsignedByteToInt(short arg)3468   private static int $noinline$testShortToUnsignedByteToInt(short arg) {
3469     return arg << 24 >>> 24;
3470   }
3471 
3472   // Check T -> S -> int cases where S is a signed type.
3473 
3474   /// CHECK-START: int Main.$noinline$testCharToSignedByteToInt(char) instruction_simplifier (before)
3475   /// CHECK:     <<Param:c\d+>>   ParameterValue
3476   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3477   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3478   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const24>>]
3479   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3480 
3481   /// CHECK-START: int Main.$noinline$testCharToSignedByteToInt(char) instruction_simplifier (after)
3482   /// CHECK:     <<Param:c\d+>>   ParameterValue
3483   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<Param>>]
3484   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3485 
3486   /// CHECK-START: int Main.$noinline$testCharToSignedByteToInt(char) instruction_simplifier (after)
3487   /// CHECK-NOT:                  Shl
3488 
3489   /// CHECK-START: int Main.$noinline$testCharToSignedByteToInt(char) instruction_simplifier (after)
3490   /// CHECK-NOT:                  Shr
$noinline$testCharToSignedByteToInt(char arg)3491   private static int $noinline$testCharToSignedByteToInt(char arg) {
3492     return arg << 24 >> 24;
3493   }
3494 
3495   /// CHECK-START: int Main.$noinline$testShortToSignedByteToInt(short) instruction_simplifier (before)
3496   /// CHECK:     <<Param:s\d+>>   ParameterValue
3497   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3498   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3499   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const24>>]
3500   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3501 
3502   /// CHECK-START: int Main.$noinline$testShortToSignedByteToInt(short) instruction_simplifier (after)
3503   /// CHECK:     <<Param:s\d+>>   ParameterValue
3504   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<Param>>]
3505   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3506 
3507   /// CHECK-START: int Main.$noinline$testShortToSignedByteToInt(short) instruction_simplifier (after)
3508   /// CHECK-NOT:                  Shl
3509 
3510   /// CHECK-START: int Main.$noinline$testShortToSignedByteToInt(short) instruction_simplifier (after)
3511   /// CHECK-NOT:                  Shr
$noinline$testShortToSignedByteToInt(short arg)3512   private static int $noinline$testShortToSignedByteToInt(short arg) {
3513     return arg << 24 >> 24;
3514   }
3515 
3516   // Check cases with shift amounts > 32.
3517 
3518   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithHugeShiftAmount(int) instruction_simplifier (before)
3519   /// CHECK:     <<Param:i\d+>>   ParameterValue
3520   /// CHECK:     <<Const48:i\d+>> IntConstant 48
3521   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const48>>]
3522   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const48>>]
3523   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3524 
3525   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithHugeShiftAmount(int) instruction_simplifier (after)
3526   /// CHECK:     <<Param:i\d+>>   ParameterValue
3527   /// CHECK:     <<Conv:c\d+>>    TypeConversion [<<Param>>]
3528   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3529 
3530   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithHugeShiftAmount(int) instruction_simplifier (after)
3531   /// CHECK-NOT:                  Shl
3532 
3533   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithHugeShiftAmount(int) instruction_simplifier (after)
3534   /// CHECK-NOT:                  UShr
$noinline$testUnsignedPromotionWithHugeShiftAmount(int arg)3535   private static int $noinline$testUnsignedPromotionWithHugeShiftAmount(int arg) {
3536     return arg << 48 >>> 48;
3537   }
3538 
3539   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithHugeMismatchedShiftAmount(int) instruction_simplifier (before)
3540   /// CHECK:     <<Param:i\d+>>   ParameterValue
3541   /// CHECK:     <<Const48:i\d+>> IntConstant 48
3542   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3543   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const48>>]
3544   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const16>>]
3545   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3546 
3547   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithHugeMismatchedShiftAmount(int) instruction_simplifier (after)
3548   /// CHECK:     <<Param:i\d+>>   ParameterValue
3549   /// CHECK:     <<Conv:c\d+>>    TypeConversion [<<Param>>]
3550   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3551 
3552   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithHugeMismatchedShiftAmount(int) instruction_simplifier (after)
3553   /// CHECK-NOT:                  Shl
3554 
3555   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithHugeMismatchedShiftAmount(int) instruction_simplifier (after)
3556   /// CHECK-NOT:                  UShr
$noinline$testUnsignedPromotionWithHugeMismatchedShiftAmount(int arg)3557   private static int $noinline$testUnsignedPromotionWithHugeMismatchedShiftAmount(int arg) {
3558     return arg << 48 >>> 16;
3559   }
3560 
3561   // Negative checks.
3562 
3563   /// CHECK-START: long Main.$noinline$testUnsignedPromotionToLong(long) instruction_simplifier (after)
3564   /// CHECK:     <<Param:j\d+>>   ParameterValue
3565   /// CHECK:     <<Const56:i\d+>> IntConstant 56
3566   /// CHECK:     <<Shl:j\d+>>     Shl [<<Param>>,<<Const56>>]
3567   /// CHECK:     <<UShr:j\d+>>    UShr [<<Shl>>,<<Const56>>]
3568   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
$noinline$testUnsignedPromotionToLong(long arg)3569   private static long $noinline$testUnsignedPromotionToLong(long arg) {
3570     // Check that we don't do simplification in the case of unsigned promotion to long.
3571     return arg << 56 >>> 56;
3572   }
3573 
3574   /// CHECK-START: long Main.$noinline$testSignedPromotionToLong(long) instruction_simplifier (after)
3575   /// CHECK:     <<Param:j\d+>>   ParameterValue
3576   /// CHECK:     <<Const56:i\d+>> IntConstant 56
3577   /// CHECK:     <<Shl:j\d+>>     Shl [<<Param>>,<<Const56>>]
3578   /// CHECK:     <<Shr:j\d+>>     Shr [<<Shl>>,<<Const56>>]
3579   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
$noinline$testSignedPromotionToLong(long arg)3580   private static long $noinline$testSignedPromotionToLong(long arg) {
3581     // Check that we don't do simplification in the case of signed promotion to long.
3582     return arg << 56 >> 56;
3583   }
3584 
3585   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithNonConstantShiftAmount(int, int) instruction_simplifier (after)
3586   /// CHECK:     <<Param1:i\d+>>  ParameterValue
3587   /// CHECK:     <<Param2:i\d+>>  ParameterValue
3588   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param1>>,<<Param2>>]
3589   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Param2>>]
3590   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3591   private static int
$noinline$testUnsignedPromotionWithNonConstantShiftAmount(int value, int shift_amount)3592   $noinline$testUnsignedPromotionWithNonConstantShiftAmount(int value, int shift_amount) {
3593     // Check that we don't do simplification in the case of unsigned promotion with
3594     // non constant shift amount.
3595     return value << shift_amount >>> shift_amount;
3596   }
3597 
3598   /// CHECK-START: int Main.$noinline$testSignedPromotionWithNonConstantShiftAmount(int, int) instruction_simplifier (after)
3599   /// CHECK:     <<Param1:i\d+>>  ParameterValue
3600   /// CHECK:     <<Param2:i\d+>>  ParameterValue
3601   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param1>>,<<Param2>>]
3602   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Param2>>]
3603   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3604   private static int
$noinline$testSignedPromotionWithNonConstantShiftAmount(int value, int shift_amount)3605   $noinline$testSignedPromotionWithNonConstantShiftAmount(int value, int shift_amount) {
3606     // Check that we don't do simplification in the case of signed promotion with
3607     // non constant shift amount.
3608     return value << shift_amount >> shift_amount;
3609   }
3610 
3611   /// CHECK-START: int Main.$noinline$testUnsignedPromotionWithShlUse(int) instruction_simplifier (after)
3612   /// CHECK:     <<Param:i\d+>>   ParameterValue
3613   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3614   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3615   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const24>>]
3616   /// CHECK:     <<Add:i\d+>>     Add [<<UShr>>,<<Shl>>]
3617   /// CHECK:     <<Return:v\d+>>  Return [<<Add>>]
$noinline$testUnsignedPromotionWithShlUse(int arg)3618   private static int $noinline$testUnsignedPromotionWithShlUse(int arg) {
3619     // Check that we don't do simplification in the case of unsigned promotion
3620     // with shl instruction that has more than 1 user.
3621     int tmp = arg << 24;
3622     return (tmp >>> 24) + tmp;
3623   }
3624 
3625   /// CHECK-START: int Main.$noinline$testSignedPromotionWithShlUse(int) instruction_simplifier (after)
3626   /// CHECK:     <<Param:i\d+>>   ParameterValue
3627   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3628   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3629   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const24>>]
3630   /// CHECK:     <<Add:i\d+>>     Add [<<Shr>>,<<Shl>>]
3631   /// CHECK:     <<Return:v\d+>>  Return [<<Add>>]
$noinline$testSignedPromotionWithShlUse(int arg)3632   private static int $noinline$testSignedPromotionWithShlUse(int arg) {
3633     // Check that we don't do simplification in the case of signed promotion
3634     // with shl instruction that has more than 1 user.
3635     int tmp = arg << 24;
3636     return (tmp >> 24) + tmp;
3637   }
3638 
3639   /// CHECK-START: int Main.$noinline$testUnsignedPromotionPatternWithIncorrectShiftAmountConstant(int) instruction_simplifier (after)
3640   /// CHECK:     <<Param:i\d+>>   ParameterValue
3641   /// CHECK:     <<Const25:i\d+>> IntConstant 25
3642   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const25>>]
3643   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const25>>]
3644   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3645 
3646   private static int
$noinline$testUnsignedPromotionPatternWithIncorrectShiftAmountConstant(int arg)3647   $noinline$testUnsignedPromotionPatternWithIncorrectShiftAmountConstant(int arg) {
3648     // Check that we don't do simplification in the case of 32 - N doesn't correspond
3649     // to the size of an integral type.
3650     return arg << 25 >>> 25;
3651   }
3652 
3653   /// CHECK-START: int Main.$noinline$testSignedPromotionPatternWithIncorrectShiftAmountConstant(int) instruction_simplifier (after)
3654   /// CHECK:     <<Param:i\d+>>   ParameterValue
3655   /// CHECK:     <<Const25:i\d+>> IntConstant 25
3656   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const25>>]
3657   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const25>>]
3658   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3659 
3660   private static int
$noinline$testSignedPromotionPatternWithIncorrectShiftAmountConstant(int arg)3661   $noinline$testSignedPromotionPatternWithIncorrectShiftAmountConstant(int arg) {
3662     // Check that we don't do simplification in the case of 32 - N doesn't correspond
3663     // to the size of an integral type.
3664     return arg << 25 >> 25;
3665   }
3666 
3667   /// CHECK-START: int Main.$noinline$testUnsignedPromotionPatternWithDifferentShiftAmountConstants(int) instruction_simplifier (after)
3668   /// CHECK:     <<Param:i\d+>>   ParameterValue
3669   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3670   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3671   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3672   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const16>>]
3673   /// CHECK:     <<Return:v\d+>>  Return [<<UShr>>]
3674 
3675   private static int
$noinline$testUnsignedPromotionPatternWithDifferentShiftAmountConstants(int arg)3676   $noinline$testUnsignedPromotionPatternWithDifferentShiftAmountConstants(int arg) {
3677     // Check that we don't do simplification in the case of different shift amounts.
3678     return arg << 24 >>> 16;
3679   }
3680 
3681   /// CHECK-START: int Main.$noinline$testSignedPromotionPatternWithDifferentShiftAmountConstants(int) instruction_simplifier (after)
3682   /// CHECK:     <<Param:i\d+>>   ParameterValue
3683   /// CHECK:     <<Const25:i\d+>> IntConstant 25
3684   /// CHECK:     <<Const26:i\d+>> IntConstant 26
3685   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const25>>]
3686   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const26>>]
3687   /// CHECK:     <<Return:v\d+>>  Return [<<Shr>>]
3688 
3689   private static
$noinline$testSignedPromotionPatternWithDifferentShiftAmountConstants(int arg)3690   int $noinline$testSignedPromotionPatternWithDifferentShiftAmountConstants(int arg) {
3691     // Check that we do not simplification in the case of different shift amounts.
3692     return arg << 25 >> 26;
3693   }
3694 
3695   // Check that we don't introduce new implicit type conversions so the following pattern
3696   // does not occur in the graph:
3697   //
3698   // <<ImplicitConv>> TypeConversion
3699   // <<ExplicitConv>> TypeConversonn [<<ImplicitConv>>]
3700   //
3701   // That will lead to a crash because InstructionSimplifier removes implicit type conversions
3702   // and during visiting TypeConversion instruction expects that its inputs have been already
3703   // simplified.
3704   //
3705   // The structure of the following tests is
3706   //
3707   //   (T) ((x << N) >> N) or (T) ((x << N) >>> N)
3708   //
3709   // where
3710   //   * K is a type of x
3711   //   * Shifts correspond to implicit type conversion K -> M
3712   //   * M -> T conversion is explicit
3713   //
3714   // T itself doesn't matter, the only important thing is that M -> T is explicit.
3715   //
3716   // We check cases when shifts correspond to the following implicit type conversions:
3717   //   byte -> byte
3718   //   byte -> short
3719   //   unsigned byte -> unsigned byte
3720   //   unsigned byte -> short
3721   //   unsigned byte -> char
3722   //   short -> short
3723   //   char -> char
3724   //
3725   // To produce unsigned byte bitwise AND with 0xFF is used.
3726 
3727   /// CHECK-START: int Main.$noinline$testByteToByteToChar(byte) instruction_simplifier (before)
3728   /// CHECK:     <<Param:b\d+>>   ParameterValue
3729   /// CHECK:     <<Const24:i\d+>> IntConstant 24
3730   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const24>>]
3731   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const24>>]
3732   /// CHECK:     <<Conv:c\d+>>    TypeConversion [<<Shr>>]
3733   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3734 
3735   /// CHECK-START: int Main.$noinline$testByteToByteToChar(byte) instruction_simplifier (after)
3736   /// CHECK:     <<Param:b\d+>>   ParameterValue
3737   /// CHECK:     <<Conv:c\d+>>    TypeConversion [<<Param>>]
3738   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3739 
3740   /// CHECK-START: int Main.$noinline$testByteToByteToChar(byte) instruction_simplifier (after)
3741   /// CHECK-NOT:                  Shl
3742 
3743   /// CHECK-START: int Main.$noinline$testByteToByteToChar(byte) instruction_simplifier (after)
3744   /// CHECK-NOT:                  Shr
$noinline$testByteToByteToChar(byte arg)3745   private static int $noinline$testByteToByteToChar(byte arg) {
3746     return (char) ((arg << 24) >> 24);
3747   }
3748 
3749   /// CHECK-START: int Main.$noinline$testByteToShortToByte(byte) instruction_simplifier (before)
3750   /// CHECK:     <<Param:b\d+>>   ParameterValue
3751   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3752   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const16>>]
3753   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const16>>]
3754   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<Shr>>]
3755   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3756 
3757   /// CHECK-START: int Main.$noinline$testByteToShortToByte(byte) instruction_simplifier (after)
3758   /// CHECK:     <<Param:b\d+>>   ParameterValue
3759   /// CHECK:     <<Return:v\d+>>  Return [<<Param>>]
3760 
3761   /// CHECK-START: int Main.$noinline$testByteToShortToByte(byte) instruction_simplifier (after)
3762   /// CHECK-NOT:                  Shl
3763 
3764   /// CHECK-START: int Main.$noinline$testByteToShortToByte(byte) instruction_simplifier (after)
3765   /// CHECK-NOT:                  Shr
3766 
3767   /// CHECK-START: int Main.$noinline$testByteToShortToByte(byte) instruction_simplifier (after)
3768   /// CHECK-NOT:                  TypeConversion
$noinline$testByteToShortToByte(byte arg)3769   private static int $noinline$testByteToShortToByte(byte arg) {
3770     return (byte) ((arg << 16) >> 16);
3771   }
3772 
3773   /// CHECK-START: int Main.$noinline$testUnsignedByteToUnsignedByteToByte(byte) instruction_simplifier (before)
3774   /// CHECK:     <<Param:b\d+>>    ParameterValue
3775   /// CHECK:     <<Const255:i\d+>> IntConstant 255
3776   /// CHECK:     <<Const24:i\d+>>  IntConstant 24
3777   /// CHECK:     <<And:i\d+>>      And [<<Param>>,<<Const255>>]
3778   /// CHECK:     <<Shl:i\d+>>      Shl [<<And>>,<<Const24>>]
3779   /// CHECK:     <<UShr:i\d+>>     UShr [<<Shl>>,<<Const24>>]
3780   /// CHECK:     <<Conv:b\d+>>     TypeConversion [<<UShr>>]
3781   /// CHECK:     <<Return:v\d+>>   Return [<<Conv>>]
3782 
3783   /// CHECK-START: int Main.$noinline$testUnsignedByteToUnsignedByteToByte(byte) instruction_simplifier (after)
3784   /// CHECK:     <<Param:b\d+>>   ParameterValue
3785   /// CHECK:     <<Return:v\d+>>  Return [<<Param>>]
3786 
3787   /// CHECK-START: int Main.$noinline$testUnsignedByteToUnsignedByteToByte(byte) instruction_simplifier (after)
3788   /// CHECK-NOT:                  Shl
3789 
3790   /// CHECK-START: int Main.$noinline$testUnsignedByteToUnsignedByteToByte(byte) instruction_simplifier (after)
3791   /// CHECK-NOT:                  Shr
3792 
3793   /// CHECK-START: int Main.$noinline$testUnsignedByteToUnsignedByteToByte(byte) instruction_simplifier (after)
3794   /// CHECK-NOT:                  TypeConversion
$noinline$testUnsignedByteToUnsignedByteToByte(byte arg)3795   private static int $noinline$testUnsignedByteToUnsignedByteToByte(byte arg) {
3796     return (byte) (((arg & 0xFF) << 24) >>> 24);
3797   }
3798 
3799   /// CHECK-START: int Main.$noinline$testUnsignedByteToShortToByte(byte) instruction_simplifier (before)
3800   /// CHECK:     <<Param:b\d+>>    ParameterValue
3801   /// CHECK:     <<Const255:i\d+>> IntConstant 255
3802   /// CHECK:     <<Const16:i\d+>>  IntConstant 16
3803   /// CHECK:     <<And:i\d+>>      And [<<Param>>,<<Const255>>]
3804   /// CHECK:     <<Shl:i\d+>>      Shl [<<And>>,<<Const16>>]
3805   /// CHECK:     <<Shr:i\d+>>      Shr [<<Shl>>,<<Const16>>]
3806   /// CHECK:     <<Conv:b\d+>>     TypeConversion [<<Shr>>]
3807   /// CHECK:     <<Return:v\d+>>   Return [<<Conv>>]
3808 
3809   /// CHECK-START: int Main.$noinline$testUnsignedByteToShortToByte(byte) instruction_simplifier (after)
3810   /// CHECK:     <<Param:b\d+>>   ParameterValue
3811   /// CHECK:     <<Return:v\d+>>  Return [<<Param>>]
3812 
3813   /// CHECK-START: int Main.$noinline$testUnsignedByteToShortToByte(byte) instruction_simplifier (after)
3814   /// CHECK-NOT:                  Shl
3815 
3816   /// CHECK-START: int Main.$noinline$testUnsignedByteToShortToByte(byte) instruction_simplifier (after)
3817   /// CHECK-NOT:                  Shr
3818 
3819   /// CHECK-START: int Main.$noinline$testUnsignedByteToShortToByte(byte) instruction_simplifier (after)
3820   /// CHECK-NOT:                  TypeConversion
$noinline$testUnsignedByteToShortToByte(byte arg)3821   private static int $noinline$testUnsignedByteToShortToByte(byte arg) {
3822     return (byte) (((arg & 0xFF) << 16) >> 16);
3823   }
3824 
3825   /// CHECK-START: int Main.$noinline$testUnsignedByteToCharToByte(byte) instruction_simplifier (before)
3826   /// CHECK:     <<Param:b\d+>>    ParameterValue
3827   /// CHECK:     <<Const255:i\d+>> IntConstant 255
3828   /// CHECK:     <<Const16:i\d+>>  IntConstant 16
3829   /// CHECK:     <<And:i\d+>>      And [<<Param>>,<<Const255>>]
3830   /// CHECK:     <<Shl:i\d+>>      Shl [<<And>>,<<Const16>>]
3831   /// CHECK:     <<UShr:i\d+>>     UShr [<<Shl>>,<<Const16>>]
3832   /// CHECK:     <<Conv:b\d+>>     TypeConversion [<<UShr>>]
3833   /// CHECK:     <<Return:v\d+>>   Return [<<Conv>>]
3834 
3835   /// CHECK-START: int Main.$noinline$testUnsignedByteToCharToByte(byte) instruction_simplifier (after)
3836   /// CHECK:     <<Param:b\d+>>   ParameterValue
3837   /// CHECK:     <<Return:v\d+>>  Return [<<Param>>]
3838 
3839   /// CHECK-START: int Main.$noinline$testUnsignedByteToCharToByte(byte) instruction_simplifier (after)
3840   /// CHECK-NOT:                  Shl
3841 
3842   /// CHECK-START: int Main.$noinline$testUnsignedByteToCharToByte(byte) instruction_simplifier (after)
3843   /// CHECK-NOT:                  Shr
3844 
3845   /// CHECK-START: int Main.$noinline$testUnsignedByteToCharToByte(byte) instruction_simplifier (after)
3846   /// CHECK-NOT:                  TypeConversion
$noinline$testUnsignedByteToCharToByte(byte arg)3847   private static int $noinline$testUnsignedByteToCharToByte(byte arg) {
3848     return (byte) (((arg & 0xFF) << 16) >>> 16);
3849   }
3850 
3851   /// CHECK-START: int Main.$noinline$testShortToShortToByte(short) instruction_simplifier (before)
3852   /// CHECK:     <<Param:s\d+>>   ParameterValue
3853   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3854   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const16>>]
3855   /// CHECK:     <<Shr:i\d+>>     Shr [<<Shl>>,<<Const16>>]
3856   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<Shr>>]
3857   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3858 
3859   /// CHECK-START: int Main.$noinline$testShortToShortToByte(short) instruction_simplifier (after)
3860   /// CHECK:     <<Param:s\d+>>   ParameterValue
3861   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<Param>>]
3862   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3863 
3864   /// CHECK-START: int Main.$noinline$testShortToShortToByte(short) instruction_simplifier (after)
3865   /// CHECK-NOT:                  Shl
3866 
3867   /// CHECK-START: int Main.$noinline$testShortToShortToByte(short) instruction_simplifier (after)
3868   /// CHECK-NOT:                  Shr
$noinline$testShortToShortToByte(short arg)3869   private static int $noinline$testShortToShortToByte(short arg) {
3870     return (byte) ((arg << 16) >> 16);
3871   }
3872 
3873   /// CHECK-START: int Main.$noinline$testCharToCharToByte(char) instruction_simplifier (before)
3874   /// CHECK:     <<Param:c\d+>>   ParameterValue
3875   /// CHECK:     <<Const16:i\d+>> IntConstant 16
3876   /// CHECK:     <<Shl:i\d+>>     Shl [<<Param>>,<<Const16>>]
3877   /// CHECK:     <<UShr:i\d+>>    UShr [<<Shl>>,<<Const16>>]
3878   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<UShr>>]
3879   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3880 
3881   /// CHECK-START: int Main.$noinline$testCharToCharToByte(char) instruction_simplifier (after)
3882   /// CHECK:     <<Param:c\d+>>   ParameterValue
3883   /// CHECK:     <<Conv:b\d+>>    TypeConversion [<<Param>>]
3884   /// CHECK:     <<Return:v\d+>>  Return [<<Conv>>]
3885 
3886   /// CHECK-START: int Main.$noinline$testCharToCharToByte(char) instruction_simplifier (after)
3887   /// CHECK-NOT:                  Shl
3888 
3889   /// CHECK-START: int Main.$noinline$testCharToCharToByte(char) instruction_simplifier (after)
3890   /// CHECK-NOT:                  Shr
$noinline$testCharToCharToByte(char arg)3891   private static int $noinline$testCharToCharToByte(char arg) {
3892     return (byte) ((arg << 16) >>> 16);
3893   }
3894 
main(String[] args)3895   public static void main(String[] args) throws Exception {
3896     Class smaliTests2 = Class.forName("SmaliTests2");
3897     Method $noinline$XorAllOnes = smaliTests2.getMethod("$noinline$XorAllOnes", int.class);
3898     Method $noinline$NotNot1 = smaliTests2.getMethod("$noinline$NotNot1", long.class);
3899     Method $noinline$NotNot2 = smaliTests2.getMethod("$noinline$NotNot2", int.class);
3900     Method $noinline$NotNotBool = smaliTests2.getMethod("$noinline$NotNotBool", boolean.class);
3901     Method $noinline$bug68142795Short = smaliTests2.getMethod("$noinline$bug68142795Short", short.class);
3902     Method $noinline$bug68142795Boolean = smaliTests2.getMethod("$noinline$bug68142795Boolean", boolean.class);
3903 
3904     int arg = 123456;
3905     float floatArg = 123456.125f;
3906 
3907     assertLongEquals(arg, $noinline$Add0(arg));
3908     assertIntEquals(5, $noinline$AddAddSubAddConst(1));
3909     assertIntEquals(arg, $noinline$AndAllOnes(arg));
3910     assertLongEquals(arg, $noinline$Div1(arg));
3911     assertIntEquals(-arg, $noinline$DivN1(arg));
3912     assertLongEquals(arg, $noinline$Mul1(arg));
3913     assertIntEquals(-arg, $noinline$MulN1(arg));
3914     assertLongEquals((128 * arg), $noinline$MulPowerOfTwo128(arg));
3915     assertLongEquals(2640, $noinline$MulMulMulConst(2));
3916     assertIntEquals(arg, $noinline$Or0(arg));
3917     assertLongEquals(arg, $noinline$OrSame(arg));
3918     assertIntEquals(arg, $noinline$Shl0(arg));
3919     assertLongEquals(arg, $noinline$Shr0(arg));
3920     assertLongEquals(arg, $noinline$Shr64(arg));
3921     assertLongEquals(arg, $noinline$Sub0(arg));
3922     assertIntEquals(-arg, $noinline$SubAliasNeg(arg));
3923     assertIntEquals(9, $noinline$SubAddConst1(2));
3924     assertIntEquals(-2, $noinline$SubAddConst2(3));
3925     assertLongEquals(3, $noinline$SubSubConst(4));
3926     assertLongEquals(arg, $noinline$UShr0(arg));
3927     assertIntEquals(arg, $noinline$Xor0(arg));
3928     assertIntEquals(~arg, (int)$noinline$XorAllOnes.invoke(null, arg));
3929     assertIntEquals(-(arg + arg + 1), $noinline$AddNegs1(arg, arg + 1));
3930     assertIntEquals(-(arg + arg + 1), $noinline$AddNegs2(arg, arg + 1));
3931     assertLongEquals(-(2 * arg + 1), $noinline$AddNegs3(arg, arg + 1));
3932     assertLongEquals(1, $noinline$AddNeg1(arg, arg + 1));
3933     assertLongEquals(-1, $noinline$AddNeg2(arg, arg + 1));
3934     assertLongEquals(arg, $noinline$NegNeg1(arg));
3935     assertIntEquals(0, $noinline$NegNeg2(arg));
3936     assertLongEquals(arg, $noinline$NegNeg3(arg));
3937     assertIntEquals(1, $noinline$NegSub1(arg, arg + 1));
3938     assertIntEquals(1, $noinline$NegSub2(arg, arg + 1));
3939     assertLongEquals(arg, (long)$noinline$NotNot1.invoke(null, arg));
3940     assertLongEquals(arg, $noinline$runSmaliTest2Long("$noinline$NotNot1", arg));
3941     assertIntEquals(-1, (int)$noinline$NotNot2.invoke(null, arg));
3942     assertIntEquals(-1, $noinline$runSmaliTestInt("2", "$noinline$NotNot2", arg));
3943     assertIntEquals(-(arg + arg + 1), $noinline$SubNeg1(arg, arg + 1));
3944     assertIntEquals(-(arg + arg + 1), $noinline$SubNeg2(arg, arg + 1));
3945     assertLongEquals(-(2 * arg + 1), $noinline$SubNeg3(arg, arg + 1));
3946     assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
3947     assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
3948     assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
3949     assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
3950     assertBooleanEquals(true, (boolean)$noinline$NotNotBool.invoke(null, true));
3951     assertBooleanEquals(true, $noinline$runSmaliTest2Boolean("$noinline$NotNotBool", true));
3952     assertBooleanEquals(false, (boolean)$noinline$NotNotBool.invoke(null, false));
3953     assertBooleanEquals(false, $noinline$runSmaliTest2Boolean("$noinline$NotNotBool", false));
3954     assertFloatEquals(50.0f, $noinline$Div2(100.0f));
3955     assertDoubleEquals(75.0, $noinline$Div2(150.0));
3956     assertFloatEquals(-400.0f, $noinline$DivMP25(100.0f));
3957     assertDoubleEquals(-600.0, $noinline$DivMP25(150.0));
3958     assertIntEquals(0xc, $noinline$UShr28And15(0xc1234567));
3959     assertLongEquals(0xcL, $noinline$UShr60And15(0xc123456787654321L));
3960     assertIntEquals(0x4, $noinline$UShr28And7(0xc1234567));
3961     assertLongEquals(0x4L, $noinline$UShr60And7(0xc123456787654321L));
3962     assertIntEquals(0xc1, $noinline$Shr24And255(0xc1234567));
3963     assertIntEquals(0x60, $noinline$Shr25And127(0xc1234567));
3964     assertLongEquals(0xc1L, $noinline$Shr56And255(0xc123456787654321L));
3965     assertLongEquals(0x60L, $noinline$Shr57And127(0xc123456787654321L));
3966     assertIntEquals(0x41, $noinline$Shr24And127(0xc1234567));
3967     assertLongEquals(0x41L, $noinline$Shr56And127(0xc123456787654321L));
3968     assertIntEquals(0, $noinline$mulPow2Plus1(0));
3969     assertIntEquals(9, $noinline$mulPow2Plus1(1));
3970     assertIntEquals(18, $noinline$mulPow2Plus1(2));
3971     assertIntEquals(900, $noinline$mulPow2Plus1(100));
3972     assertIntEquals(111105, $noinline$mulPow2Plus1(12345));
3973     assertLongEquals(0, $noinline$mulPow2Minus1(0));
3974     assertLongEquals(31, $noinline$mulPow2Minus1(1));
3975     assertLongEquals(62, $noinline$mulPow2Minus1(2));
3976     assertLongEquals(3100, $noinline$mulPow2Minus1(100));
3977     assertLongEquals(382695, $noinline$mulPow2Minus1(12345));
3978 
3979     booleanField = false;
3980     assertIntEquals($noinline$booleanFieldNotEqualOne(), 54);
3981     assertIntEquals($noinline$booleanFieldEqualZero(), 54);
3982     booleanField = true;
3983     assertIntEquals(13, $noinline$booleanFieldNotEqualOne());
3984     assertIntEquals(13, $noinline$booleanFieldEqualZero());
3985     assertIntEquals(54, $noinline$intConditionNotEqualOne(6));
3986     assertIntEquals(13, $noinline$intConditionNotEqualOne(43));
3987     assertIntEquals(54, $noinline$intConditionEqualZero(6));
3988     assertIntEquals(13, $noinline$intConditionEqualZero(43));
3989     assertIntEquals(54, $noinline$floatConditionNotEqualOne(6.0f));
3990     assertIntEquals(13, $noinline$floatConditionNotEqualOne(43.0f));
3991     assertIntEquals(54, $noinline$doubleConditionEqualZero(6.0));
3992     assertIntEquals(13, $noinline$doubleConditionEqualZero(43.0));
3993 
3994     assertIntEquals(1234567, $noinline$intToDoubleToInt(1234567));
3995     assertIntEquals(Integer.MIN_VALUE, $noinline$intToDoubleToInt(Integer.MIN_VALUE));
3996     assertIntEquals(Integer.MAX_VALUE, $noinline$intToDoubleToInt(Integer.MAX_VALUE));
3997     assertStringEquals("d=7654321.0, i=7654321", $noinline$intToDoubleToIntPrint(7654321));
3998     assertIntEquals(12, $noinline$byteToDoubleToInt((byte) 12));
3999     assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToInt(Byte.MIN_VALUE));
4000     assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToInt(Byte.MAX_VALUE));
4001     assertIntEquals(11, $noinline$floatToDoubleToInt(11.3f));
4002     assertStringEquals("d=12.25, i=12", $noinline$floatToDoubleToIntPrint(12.25f));
4003     assertIntEquals(123, $noinline$byteToDoubleToShort((byte) 123));
4004     assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToShort(Byte.MIN_VALUE));
4005     assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToShort(Byte.MAX_VALUE));
4006     assertIntEquals(1234, $noinline$charToDoubleToShort((char) 1234));
4007     assertIntEquals(Character.MIN_VALUE, $noinline$charToDoubleToShort(Character.MIN_VALUE));
4008     assertIntEquals(/* sign-extended */ -1, $noinline$charToDoubleToShort(Character.MAX_VALUE));
4009     assertIntEquals(12345, $noinline$floatToIntToShort(12345.75f));
4010     assertIntEquals(Short.MAX_VALUE, $noinline$floatToIntToShort((float)(Short.MIN_VALUE - 1)));
4011     assertIntEquals(Short.MIN_VALUE, $noinline$floatToIntToShort((float)(Short.MAX_VALUE + 1)));
4012     assertIntEquals(-54321, $noinline$intToFloatToInt(-54321));
4013     assertDoubleEquals((double) 0x12345678, $noinline$longToIntToDouble(0x1234567812345678L));
4014     assertDoubleEquals(0.0, $noinline$longToIntToDouble(Long.MIN_VALUE));
4015     assertDoubleEquals(-1.0, $noinline$longToIntToDouble(Long.MAX_VALUE));
4016     assertLongEquals(0x0000000012345678L, $noinline$longToIntToLong(0x1234567812345678L));
4017     assertLongEquals(0xffffffff87654321L, $noinline$longToIntToLong(0x1234567887654321L));
4018     assertLongEquals(0L, $noinline$longToIntToLong(Long.MIN_VALUE));
4019     assertLongEquals(-1L, $noinline$longToIntToLong(Long.MAX_VALUE));
4020     assertIntEquals((short) -5678, $noinline$shortToCharToShort((short) -5678));
4021     assertIntEquals(Short.MIN_VALUE, $noinline$shortToCharToShort(Short.MIN_VALUE));
4022     assertIntEquals(Short.MAX_VALUE, $noinline$shortToCharToShort(Short.MAX_VALUE));
4023     assertIntEquals(5678, $noinline$shortToLongToInt((short) 5678));
4024     assertIntEquals(Short.MIN_VALUE, $noinline$shortToLongToInt(Short.MIN_VALUE));
4025     assertIntEquals(Short.MAX_VALUE, $noinline$shortToLongToInt(Short.MAX_VALUE));
4026     assertIntEquals(0x34, $noinline$shortToCharToByte((short) 0x1234));
4027     assertIntEquals(-0x10, $noinline$shortToCharToByte((short) 0x12f0));
4028     assertIntEquals(0, $noinline$shortToCharToByte(Short.MIN_VALUE));
4029     assertIntEquals(-1, $noinline$shortToCharToByte(Short.MAX_VALUE));
4030     assertStringEquals("c=1025, b=1", $noinline$shortToCharToBytePrint((short) 1025));
4031     assertStringEquals("c=1023, b=-1", $noinline$shortToCharToBytePrint((short) 1023));
4032     assertStringEquals("c=65535, b=-1", $noinline$shortToCharToBytePrint((short) -1));
4033 
4034     assertLongEquals(0x55411410L, $noinline$intAndSmallLongConstant(0x55555555));
4035     assertLongEquals(0xffffffffaa028aa2L, $noinline$intAndSmallLongConstant(0xaaaaaaaa));
4036     assertLongEquals(0x44101440L, $noinline$intAndLargeLongConstant(0x55555555));
4037     assertLongEquals(0x208a002aaL, $noinline$intAndLargeLongConstant(0xaaaaaaaa));
4038     assertLongEquals(7L, $noinline$intShr28And15L(0x76543210));
4039 
4040     assertIntEquals(0x21, $noinline$longAnd0xffToByte(0x1234432112344321L));
4041     assertIntEquals(0, $noinline$longAnd0xffToByte(Long.MIN_VALUE));
4042     assertIntEquals(-1, $noinline$longAnd0xffToByte(Long.MAX_VALUE));
4043     assertIntEquals(0x1234, $noinline$intAnd0x1ffffToChar(0x43211234));
4044     assertIntEquals(0, $noinline$intAnd0x1ffffToChar(Integer.MIN_VALUE));
4045     assertIntEquals(Character.MAX_VALUE, $noinline$intAnd0x1ffffToChar(Integer.MAX_VALUE));
4046     assertIntEquals(0x4321, $noinline$intAnd0x17fffToShort(0x87654321));
4047     assertIntEquals(0x0888, $noinline$intAnd0x17fffToShort(0x88888888));
4048     assertIntEquals(0, $noinline$intAnd0x17fffToShort(Integer.MIN_VALUE));
4049     assertIntEquals(Short.MAX_VALUE, $noinline$intAnd0x17fffToShort(Integer.MAX_VALUE));
4050 
4051     assertDoubleEquals(0.0, $noinline$shortAnd0xffffToShortToDouble((short) 0));
4052     assertDoubleEquals(1.0, $noinline$shortAnd0xffffToShortToDouble((short) 1));
4053     assertDoubleEquals(-2.0, $noinline$shortAnd0xffffToShortToDouble((short) -2));
4054     assertDoubleEquals(12345.0, $noinline$shortAnd0xffffToShortToDouble((short) 12345));
4055     assertDoubleEquals((double)Short.MAX_VALUE,
4056                        $noinline$shortAnd0xffffToShortToDouble(Short.MAX_VALUE));
4057     assertDoubleEquals((double)Short.MIN_VALUE,
4058                        $noinline$shortAnd0xffffToShortToDouble(Short.MIN_VALUE));
4059 
4060     assertIntEquals(13, $noinline$intReverseCondition(41));
4061     assertIntEquals(13, $noinline$intReverseConditionNaN(-5));
4062 
4063     for (String condition : new String[] { "Equal", "NotEqual" }) {
4064       for (String constant : new String[] { "True", "False" }) {
4065         for (String side : new String[] { "Rhs", "Lhs" }) {
4066           String name = condition + constant + side;
4067           assertIntEquals(5, $noinline$runSmaliTest(name, true));
4068           assertIntEquals(3, $noinline$runSmaliTest(name, false));
4069         }
4070       }
4071     }
4072 
4073     assertIntEquals(0, $noinline$runSmaliTestInt("AddSubConst", 1));
4074     assertIntEquals(3, $noinline$runSmaliTestInt("SubAddConst", 2));
4075     assertIntEquals(-16, $noinline$runSmaliTestInt("SubSubConst1", 3));
4076     assertIntEquals(-5, $noinline$runSmaliTestInt("SubSubConst2", 4));
4077     assertIntEquals(26, $noinline$runSmaliTestInt("SubSubConst3", 5));
4078     assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3));
4079     assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3 + 32));
4080     assertLongEquals(0xffffffffffffeaf3L,
4081                      $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50));
4082     assertLongEquals(0xffffffffffffeaf3L,
4083                      $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50 + 64));
4084     assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10));
4085     assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10 + 128));
4086     assertLongEquals(0xaf37bc048d159e24L,
4087                      $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2));
4088     assertLongEquals(0xaf37bc048d159e24L,
4089                      $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2 + 256));
4090     assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13));
4091     assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13 + 512));
4092     assertIntEquals(0x5f49eb48, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 2));
4093     assertIntEquals(0xbd4c29b0, $noinline$intUnnecessaryShiftModifications(0xabcdef01, 3));
4094     assertIntEquals(0xc0fed1ca, $noinline$intNecessaryShiftModifications(0xabcdef01, 2));
4095     assertIntEquals(0x03578ebc, $noinline$intNecessaryShiftModifications(0xabcdef01, 3));
4096 
4097     assertIntEquals(654321, $noinline$intAddSubSimplifyArg1(arg, 654321));
4098     assertIntEquals(arg, $noinline$intAddSubSimplifyArg2(arg, 654321));
4099     assertIntEquals(arg, $noinline$intSubAddSimplifyLeft(arg, 654321));
4100     assertIntEquals(arg, $noinline$intSubAddSimplifyRight(arg, 654321));
4101     assertFloatEquals(654321.125f, $noinline$floatAddSubSimplifyArg1(floatArg, 654321.125f));
4102     assertFloatEquals(floatArg, $noinline$floatAddSubSimplifyArg2(floatArg, 654321.125f));
4103     assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyLeft(floatArg, 654321.125f));
4104     assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyRight(floatArg, 654321.125f));
4105 
4106     // Sub/Add and Sub/Sub simplifications
4107     final int[] int_inputs = {0, 1, -1, Integer.MIN_VALUE, Integer.MAX_VALUE, 42, -9000};
4108     for (int x : int_inputs) {
4109       for (int y : int_inputs) {
4110         // y - (x + y) = -x
4111         assertIntEquals(-x, $noinline$testSubAddInt(x, y));
4112         // x - (x + y) = -y.
4113         assertIntEquals(-y, $noinline$testSubAddOtherVersionInt(x, y));
4114         // (x - y) - x = -y.
4115         assertIntEquals(-y, $noinline$testSubSubInt(x, y));
4116         // x - (x - y) = y.
4117         assertIntEquals(y, $noinline$testSubSubOtherVersionInt(x, y));
4118       }
4119     }
4120 
4121     final long[] long_inputs = {0L, 1L, -1L, Long.MIN_VALUE, Long.MAX_VALUE, 0x100000000L,
4122             0x100000001L, -9000L, 0x0123456789ABCDEFL};
4123     for (long x : long_inputs) {
4124       for (long y : long_inputs) {
4125         // y - (x + y) = -x
4126         assertLongEquals(-x, $noinline$testSubAddLong(x, y));
4127         // x - (x + y) = -y.
4128         assertLongEquals(-y, $noinline$testSubAddOtherVersionLong(x, y));
4129         // (x - y) - x = -y.
4130         assertLongEquals(-y, $noinline$testSubSubLong(x, y));
4131         // x - (x - y) = y.
4132         assertLongEquals(y, $noinline$testSubSubOtherVersionLong(x, y));
4133       }
4134     }
4135 
4136     Main m = new Main();
4137     m.instanceByteField = -1;
4138     assertIntEquals(0xff, $noinline$getUint8FromInstanceByteField(m));
4139     staticByteField = -2;
4140     assertIntEquals(0xfe, $noinline$getUint8FromStaticByteField());
4141     assertIntEquals(0xfd, $noinline$getUint8FromByteArray(new byte[] { -3 }));
4142     m.instanceShortField = -4;
4143     assertIntEquals(0xfffc, $noinline$getUint16FromInstanceShortField(m));
4144     staticShortField = -5;
4145     assertIntEquals(0xfffb, $noinline$getUint16FromStaticShortField());
4146     assertIntEquals(0xfffa, $noinline$getUint16FromShortArray(new short[] { -6 }));
4147     m.instanceCharField = 0xfff9;
4148     assertIntEquals(-7, $noinline$getInt16FromInstanceCharField(m));
4149     staticCharField = 0xfff8;
4150     assertIntEquals(-8, $noinline$getInt16FromStaticCharField());
4151     assertIntEquals(-9, $noinline$getInt16FromCharArray(new char[] { 0xfff7 }));
4152 
4153     staticCharField = 0xfff6;
4154     assertIntEquals(0xf6, $noinline$getStaticCharFieldAnd0xff());
4155 
4156     staticByteField = -11;
4157     assertIntEquals(-11, $noinline$byteToUint8AndBack());
4158 
4159     m.instanceByteField = -12;
4160     assertIntEquals(0xfffff4f4, $noinline$getUint8FromInstanceByteFieldWithAnotherUse(m));
4161 
4162     assertIntEquals(0x21, $noinline$intAnd0xffToChar(0x87654321));
4163     assertIntEquals(0x121, $noinline$intAnd0x1ffToChar(0x87654321));
4164 
4165     m.instanceCharField = 'x';
4166     assertIntEquals('x', $noinline$getInstanceCharFieldAnd0x1ffff(m));
4167 
4168     assertIntEquals(0x7f, $noinline$bug68142795Byte((byte) 0x7f));
4169     assertIntEquals((byte) 0x80, $noinline$bug68142795Byte((byte) 0x80));
4170     assertIntEquals(0x7fff, (int)$noinline$bug68142795Short.invoke(null, (short) 0x7fff));
4171     assertIntEquals((short) 0x8000, (int)$noinline$bug68142795Short.invoke(null, (short) 0x8000));
4172     assertIntEquals(0, (int)$noinline$bug68142795Boolean.invoke(null, false));
4173     assertIntEquals(1, (int)$noinline$bug68142795Boolean.invoke(null, true));
4174     assertIntEquals(0x7f, $noinline$bug68142795Elaborate((byte) 0x7f));
4175     assertIntEquals((byte) 0x80, $noinline$bug68142795Elaborate((byte) 0x80));
4176 
4177     assertIntEquals(-1, $noinline$emptyStringIndexOf('a'));
4178     assertIntEquals(-1, $noinline$emptyStringIndexOf('Z'));
4179     assertIntEquals(-1, $noinline$emptyStringIndexOfAfter('a', 0));
4180     assertIntEquals(-1, $noinline$emptyStringIndexOfAfter('Z', -1));
4181 
4182     assertIntEquals(-1, $noinline$singleCharStringIndexOf('a'));
4183     assertIntEquals(0, $noinline$singleCharStringIndexOf('x'));
4184     assertIntEquals(-1, $noinline$singleCharStringIndexOf('Z'));
4185     assertIntEquals(-1, $noinline$singleCharStringIndexOfAfter('a', 0));
4186     assertIntEquals(0, $noinline$singleCharStringIndexOfAfter('x', -1));
4187     assertIntEquals(-1, $noinline$singleCharStringIndexOfAfter('x', 1));
4188     assertIntEquals(-1, $noinline$singleCharStringIndexOfAfter('Z', -1));
4189 
4190     assertIntEquals(0x65,$noinline$redundantAndNotRedundant(0x7fff6f45));
4191     assertIntEquals(0x5e,$noinline$redundantAndOtherUse(0x7fff6f45));
4192 
4193     assertIntEquals(0x79, $noinline$redundantAndShortToByteShift2((short) 0x6de7));
4194     assertIntEquals(0x79, $noinline$redundantAndShortToByteShift2((short) 0xfde7));
4195     assertIntEquals(0x7a, $noinline$redundantAndShortToByteShift5((short) 0x6f45));
4196     assertIntEquals(-6, $noinline$redundantAndShortToByteShift5((short) 0xff45));
4197     assertIntEquals(0x6f, $noinline$redundantAndShortToByteShift8((short) 0x6f45));
4198     assertIntEquals(-1, $noinline$redundantAndShortToByteShift8((short) 0xff45));
4199     assertIntEquals(0x37, $noinline$redundantAndShortToByteShift9NotRedundant((short) 0x6f45));
4200     assertIntEquals(127, $noinline$redundantAndShortToByteShift9NotRedundant((short) 0xff45));
4201     assertIntEquals(127, $noinline$redundantAndShortToByteShift10NotRedundant((short) 0xffff));
4202     assertIntEquals(6, $noinline$redundantAndShortToByteShift12((short) 0x6f45));
4203     assertIntEquals(-1, $noinline$redundantAndShortToByteShift12((short) 0xff45));
4204     assertIntEquals(0, $noinline$redundantAndShortToByteShift15((short) 0x6f45));
4205     assertIntEquals(-1, $noinline$redundantAndShortToByteShift15((short) 0xff45));
4206     assertIntEquals(0, $noinline$redundantAndShortToByteShift16((short) 0x6f45));
4207     assertIntEquals(-1, $noinline$redundantAndShortToByteShift16((short) 0xff45));
4208     assertIntEquals(0, $noinline$redundantAndShortToByteShortAndConstant((short) 0x6f45));
4209     assertIntEquals(-1, $noinline$redundantAndShortToByteShortAndConstant((short) 0xff45));
4210 
4211     assertIntEquals(0x79, $noinline$redundantAndIntToByteShift2(0x7fff6de7));
4212     assertIntEquals(0x79, $noinline$redundantAndIntToByteShift2(0xfffffde7));
4213     assertIntEquals(0x7a, $noinline$redundantAndIntToByteShift5(0x7fff6f45));
4214     assertIntEquals(-6, $noinline$redundantAndIntToByteShift5(0xffffff45));
4215     assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift8(0x7fff6f45));
4216     assertIntEquals(-1, $noinline$redundantAndIntToByteShift8(0xffffff45));
4217     assertIntEquals(-73, $noinline$redundantAndIntToByteShift9(0x7fff6f45));
4218     assertIntEquals(-1, $noinline$redundantAndIntToByteShift9(0xffffff45));
4219     assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift16(0x7f6fffff));
4220     assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift16(0xff6fff45));
4221     assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift20(0x76ffffff));
4222     assertIntEquals(0x6f, $noinline$redundantAndIntToByteShift20(0xf6ffff45));
4223     assertIntEquals(0x7f, $noinline$redundantAndIntToByteShift24(0x7fffffff));
4224     assertIntEquals(-1, $noinline$redundantAndIntToByteShift24(0xffffff45));
4225     assertIntEquals(0x3f, $noinline$redundantAndIntToByteShift25(0x7fffffff));
4226     assertIntEquals(-1, $noinline$redundantAndIntToByteShift25(0xffffff45));
4227     assertIntEquals(0, $noinline$redundantAndIntToByteShift31(0x7fffffff));
4228     assertIntEquals(-1, $noinline$redundantAndIntToByteShift31(0xffffff45));
4229     assertIntEquals(-1, $noinline$redundantAndIntToByteShortAndConstant(0x7fffff45));
4230     assertIntEquals(-1, $noinline$redundantAndIntToByteShortAndConstant(0xffffff45));
4231     assertIntEquals(111, $noinline$redundantAndRegressionNotConstant(-1, 0x6f45));
4232 
4233     assertIntEquals(50, $noinline$deadAddAfterUnrollingAndSimplification(new int[] { 0 }));
4234 
4235     for (int x : int_inputs) {
4236       for (int y : int_inputs) {
4237         assertIntEquals(x, $noinline$returnSecondIfEqualElseFirstInt(x, y));
4238         assertIntEquals(y, $noinline$returnSecondIfNotEqualElseFirstInt(x, y));
4239       }
4240     }
4241 
4242     for (long x : long_inputs) {
4243       for (long y : long_inputs) {
4244         assertLongEquals(x, $noinline$returnSecondIfEqualElseFirstLong(x, y));
4245         assertLongEquals(y, $noinline$returnSecondIfNotEqualElseFirstLong(x, y));
4246       }
4247     }
4248 
4249     assertIntEquals(0xaa, $noinline$testByteToIntAsUnsigned((byte) 0xaa));
4250     assertIntEquals(0xaabb, $noinline$testShortToIntAsUnsigned((short) 0xaabb));
4251     assertIntEquals(0xaabb, $noinline$testCharToIntAsUnsigned((char) 0xaabb));
4252 
4253     assertIntEquals(0xffffffaa, $noinline$testByteToIntAsSigned((byte) 0xaa));
4254     assertIntEquals(0x0a, $noinline$testByteToIntAsSigned((byte) 0x0a));
4255     assertIntEquals(0xffffaabb, $noinline$testShortToIntAsSigned((short) 0xaabb));
4256     assertIntEquals(0x0abb, $noinline$testShortToIntAsSigned((short) 0x0abb));
4257     assertIntEquals(0xffffaabb, $noinline$testCharToIntAsSigned((char) 0xaabb));
4258     assertIntEquals(0x0abb, $noinline$testCharToIntAsSigned((char) 0x0abb));
4259 
4260     assertIntEquals(0xbb, $noinline$testShortToByteToIntAsUnsigned((short) 0xaabb));
4261     assertIntEquals(0xbb, $noinline$testCharToByteToIntAsUnsigned((char) 0x0abb));
4262 
4263     assertIntEquals(0xffffffbb, $noinline$testShortToByteToIntAsSigned((short) 0xaabb));
4264     assertIntEquals(0x0b, $noinline$testShortToByteToIntAsSigned((short) 0xaa0b));
4265     assertIntEquals(0xffffffbb, $noinline$testCharToByteToIntAsSigned((char) 0x0abb));
4266     assertIntEquals(0x0b, $noinline$testCharToByteToIntAsSigned((char) 0x0a0b));
4267 
4268     assertIntEquals(0xdd, $noinline$testIntToUnsignedByteToInt(0xaabbccdd));
4269     assertIntEquals(0xccdd, $noinline$testIntToUnsignedShortToInt(0xaabbccdd));
4270 
4271     assertIntEquals(0xffffffdd, $noinline$testIntToSignedByteToInt(0xaabbccdd));
4272     assertIntEquals(0x0a, $noinline$testIntToSignedByteToInt(0x0a));
4273     assertIntEquals(0xffffccdd, $noinline$testIntToSignedShortToInt(0xaabbccdd));
4274     assertIntEquals(0x0abb, $noinline$testIntToSignedShortToInt(0x0abb));
4275 
4276     assertIntEquals(0xbb, $noinline$testCharToUnsignedByteToInt((char) 0xaabb));
4277     assertIntEquals(0xbb, $noinline$testShortToUnsignedByteToInt((short) 0xaabb));
4278 
4279     assertIntEquals(0xffffffbb, $noinline$testCharToSignedByteToInt((char) 0xaabb));
4280     assertIntEquals(0xffffffbb, $noinline$testShortToSignedByteToInt((short) 0xaabb));
4281     assertIntEquals(0x0b, $noinline$testCharToSignedByteToInt((char) 0xaa0b));
4282     assertIntEquals(0x0b, $noinline$testShortToSignedByteToInt((short) 0xaa0b));
4283 
4284     assertIntEquals(0xccdd,
4285         $noinline$testUnsignedPromotionWithHugeShiftAmount(0xaabbccdd));
4286     assertIntEquals(0xccdd,
4287         $noinline$testUnsignedPromotionWithHugeMismatchedShiftAmount(0xaabbccdd));
4288 
4289     assertLongEquals(0xdd, $noinline$testUnsignedPromotionToLong(0x11223344aabbccddL));
4290     assertLongEquals(0xffffffffffffffddL,
4291         $noinline$testSignedPromotionToLong(0x11223344aabbccddL));
4292 
4293     assertIntEquals(0xccdd,
4294         $noinline$testUnsignedPromotionWithNonConstantShiftAmount(0xaabbccdd, 16));
4295     assertIntEquals(0xffffffdd,
4296         $noinline$testSignedPromotionWithNonConstantShiftAmount(0xaabbccdd, 24));
4297 
4298     assertIntEquals(0xdd0000dd, $noinline$testUnsignedPromotionWithShlUse(0xaabbccdd));
4299     assertIntEquals(0xdcffffdd, $noinline$testSignedPromotionWithShlUse(0xaabbccdd));
4300 
4301     assertIntEquals(0x5d,
4302         $noinline$testUnsignedPromotionPatternWithIncorrectShiftAmountConstant(0xaabbccdd));
4303     assertIntEquals(0xffffffdd,
4304         $noinline$testSignedPromotionPatternWithIncorrectShiftAmountConstant(0xaabbccdd));
4305 
4306     assertIntEquals(0xdd00,
4307         $noinline$testUnsignedPromotionPatternWithDifferentShiftAmountConstants(0xaabbccdd));
4308     assertIntEquals(0xffffffee,
4309         $noinline$testSignedPromotionPatternWithDifferentShiftAmountConstants(0xaabbccdd));
4310 
4311     assertIntEquals(0xffaa, $noinline$testByteToByteToChar((byte) 0xaa));
4312     assertIntEquals(0x0a, $noinline$testByteToByteToChar((byte) 0x0a));
4313 
4314     assertIntEquals(0x0a, $noinline$testByteToShortToByte((byte) 0x0a));
4315     assertIntEquals(0xffffffaa, $noinline$testByteToShortToByte((byte) 0xaa));
4316 
4317     assertIntEquals(0x0a, $noinline$testUnsignedByteToUnsignedByteToByte((byte) 0x0a));
4318     assertIntEquals(0xffffffaa, $noinline$testUnsignedByteToUnsignedByteToByte((byte) 0xaa));
4319 
4320     assertIntEquals(0x0a, $noinline$testUnsignedByteToShortToByte((byte) 0x0a));
4321     assertIntEquals(0xffffffaa, $noinline$testUnsignedByteToShortToByte((byte) 0xaa));
4322 
4323     assertIntEquals(0x0a, $noinline$testUnsignedByteToCharToByte((byte) 0x0a));
4324     assertIntEquals(0xffffffaa, $noinline$testUnsignedByteToCharToByte((byte) 0xaa));
4325 
4326     assertIntEquals(0x0b, $noinline$testShortToShortToByte((short) 0xaa0b));
4327     assertIntEquals(0xffffffbb, $noinline$testShortToShortToByte((short) 0xaabb));
4328 
4329     assertIntEquals(0x0b, $noinline$testCharToCharToByte((char) 0xaa0b));
4330     assertIntEquals(0xffffffbb, $noinline$testCharToCharToByte((char) 0xaabb));
4331   }
4332 
$inline$true()4333   private static boolean $inline$true() { return true; }
$inline$false()4334   private static boolean $inline$false() { return false; }
4335 
4336   public static boolean booleanField;
4337 
4338   public static byte staticByteField;
4339   public static char staticCharField;
4340   public static short staticShortField;
4341 
4342   public byte instanceByteField;
4343   public char instanceCharField;
4344   public short instanceShortField;
4345 }
4346