• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21   static boolean doThrow = false;
22 
assertBooleanEquals(boolean expected, boolean result)23   public static void assertBooleanEquals(boolean expected, boolean result) {
24     if (expected != result) {
25       throw new Error("Expected: " + expected + ", found: " + result);
26     }
27   }
28 
assertIntEquals(int expected, int result)29   public static void assertIntEquals(int expected, int result) {
30     if (expected != result) {
31       throw new Error("Expected: " + expected + ", found: " + result);
32     }
33   }
34 
assertLongEquals(long expected, long result)35   public static void assertLongEquals(long expected, long result) {
36     if (expected != result) {
37       throw new Error("Expected: " + expected + ", found: " + result);
38     }
39   }
40 
assertFloatEquals(float expected, float result)41   public static void assertFloatEquals(float expected, float result) {
42     if (expected != result) {
43       throw new Error("Expected: " + expected + ", found: " + result);
44     }
45   }
46 
assertDoubleEquals(double expected, double result)47   public static void assertDoubleEquals(double expected, double result) {
48     if (expected != result) {
49       throw new Error("Expected: " + expected + ", found: " + result);
50     }
51   }
52 
assertStringEquals(String expected, String result)53   public static void assertStringEquals(String expected, String result) {
54     if (expected == null ? result != null : !expected.equals(result)) {
55       throw new Error("Expected: " + expected + ", found: " + result);
56     }
57   }
58 
59   /**
60    * Tiny programs exercising optimizations of arithmetic identities.
61    */
62 
63   /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (before)
64   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
65   /// CHECK-DAG:     <<Const0:j\d+>>  LongConstant 0
66   /// CHECK-DAG:     <<Add:j\d+>>     Add [<<Const0>>,<<Arg>>]
67   /// CHECK-DAG:                      Return [<<Add>>]
68 
69   /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
70   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
71   /// CHECK-DAG:                      Return [<<Arg>>]
72 
73   /// CHECK-START: long Main.$noinline$Add0(long) instruction_simplifier (after)
74   /// CHECK-NOT:                        Add
75 
$noinline$Add0(long arg)76   public static long $noinline$Add0(long arg) {
77     if (doThrow) { throw new Error(); }
78     return 0 + arg;
79   }
80 
81   /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (before)
82   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
83   /// CHECK-DAG:     <<Const1:i\d+>>    IntConstant 1
84   /// CHECK-DAG:     <<Const2:i\d+>>    IntConstant 2
85   /// CHECK-DAG:     <<ConstM3:i\d+>>   IntConstant -3
86   /// CHECK-DAG:     <<Const4:i\d+>>    IntConstant 4
87   /// CHECK-DAG:     <<Add1:i\d+>>      Add [<<ArgValue>>,<<Const1>>]
88   /// CHECK-DAG:     <<Add2:i\d+>>      Add [<<Add1>>,<<Const2>>]
89   /// CHECK-DAG:     <<Add3:i\d+>>      Add [<<Add2>>,<<ConstM3>>]
90   /// CHECK-DAG:     <<Add4:i\d+>>      Add [<<Add3>>,<<Const4>>]
91   /// CHECK-DAG:                        Return [<<Add4>>]
92 
93   /// CHECK-START: int Main.$noinline$AddAddSubAddConst(int) instruction_simplifier (after)
94   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
95   /// CHECK-DAG:     <<Const4:i\d+>>    IntConstant 4
96   /// CHECK-DAG:     <<Add:i\d+>>       Add [<<ArgValue>>,<<Const4>>]
97   /// CHECK-DAG:                        Return [<<Add>>]
98 
$noinline$AddAddSubAddConst(int arg)99   public static int $noinline$AddAddSubAddConst(int arg) {
100     if (doThrow) { throw new Error(); }
101     return arg + 1 + 2 - 3 + 4;
102   }
103 
104   /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (before)
105   /// CHECK-DAG:     <<Arg:i\d+>>     ParameterValue
106   /// CHECK-DAG:     <<ConstF:i\d+>>  IntConstant -1
107   /// CHECK-DAG:     <<And:i\d+>>     And [<<Arg>>,<<ConstF>>]
108   /// CHECK-DAG:                      Return [<<And>>]
109 
110   /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
111   /// CHECK-DAG:     <<Arg:i\d+>>     ParameterValue
112   /// CHECK-DAG:                      Return [<<Arg>>]
113 
114   /// CHECK-START: int Main.$noinline$AndAllOnes(int) instruction_simplifier (after)
115   /// CHECK-NOT:                      And
116 
$noinline$AndAllOnes(int arg)117   public static int $noinline$AndAllOnes(int arg) {
118     if (doThrow) { throw new Error(); }
119     return arg & -1;
120   }
121 
122   /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (before)
123   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
124   /// CHECK-DAG:     <<Const28:i\d+>>  IntConstant 28
125   /// CHECK-DAG:     <<Const15:i\d+>>  IntConstant 15
126   /// CHECK-DAG:     <<UShr:i\d+>>     UShr [<<Arg>>,<<Const28>>]
127   /// CHECK-DAG:     <<And:i\d+>>      And [<<UShr>>,<<Const15>>]
128   /// CHECK-DAG:                       Return [<<And>>]
129 
130   /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
131   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
132   /// CHECK-DAG:     <<Const28:i\d+>>  IntConstant 28
133   /// CHECK-DAG:     <<UShr:i\d+>>     UShr [<<Arg>>,<<Const28>>]
134   /// CHECK-DAG:                       Return [<<UShr>>]
135 
136   /// CHECK-START: int Main.$noinline$UShr28And15(int) instruction_simplifier (after)
137   /// CHECK-NOT:                       And
138 
$noinline$UShr28And15(int arg)139   public static int $noinline$UShr28And15(int arg) {
140     if (doThrow) { throw new Error(); }
141     return (arg >>> 28) & 15;
142   }
143 
144   /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (before)
145   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
146   /// CHECK-DAG:     <<Const60:i\d+>>  IntConstant 60
147   /// CHECK-DAG:     <<Const15:j\d+>>  LongConstant 15
148   /// CHECK-DAG:     <<UShr:j\d+>>     UShr [<<Arg>>,<<Const60>>]
149   /// CHECK-DAG:     <<And:j\d+>>      And [<<UShr>>,<<Const15>>]
150   /// CHECK-DAG:                       Return [<<And>>]
151 
152   /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
153   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
154   /// CHECK-DAG:     <<Const60:i\d+>>  IntConstant 60
155   /// CHECK-DAG:     <<UShr:j\d+>>     UShr [<<Arg>>,<<Const60>>]
156   /// CHECK-DAG:                       Return [<<UShr>>]
157 
158   /// CHECK-START: long Main.$noinline$UShr60And15(long) instruction_simplifier (after)
159   /// CHECK-NOT:                       And
160 
$noinline$UShr60And15(long arg)161   public static long $noinline$UShr60And15(long arg) {
162     if (doThrow) { throw new Error(); }
163     return (arg >>> 60) & 15;
164   }
165 
166   /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (before)
167   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
168   /// CHECK-DAG:     <<Const28:i\d+>>  IntConstant 28
169   /// CHECK-DAG:     <<Const7:i\d+>>   IntConstant 7
170   /// CHECK-DAG:     <<UShr:i\d+>>     UShr [<<Arg>>,<<Const28>>]
171   /// CHECK-DAG:     <<And:i\d+>>      And [<<UShr>>,<<Const7>>]
172   /// CHECK-DAG:                       Return [<<And>>]
173 
174   /// CHECK-START: int Main.$noinline$UShr28And7(int) instruction_simplifier (after)
175   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
176   /// CHECK-DAG:     <<Const28:i\d+>>  IntConstant 28
177   /// CHECK-DAG:     <<Const7:i\d+>>   IntConstant 7
178   /// CHECK-DAG:     <<UShr:i\d+>>     UShr [<<Arg>>,<<Const28>>]
179   /// CHECK-DAG:     <<And:i\d+>>      And [<<UShr>>,<<Const7>>]
180   /// CHECK-DAG:                       Return [<<And>>]
181 
$noinline$UShr28And7(int arg)182   public static int $noinline$UShr28And7(int arg) {
183     if (doThrow) { throw new Error(); }
184     return (arg >>> 28) & 7;
185   }
186 
187   /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (before)
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 
195   /// CHECK-START: long Main.$noinline$UShr60And7(long) instruction_simplifier (after)
196   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
197   /// CHECK-DAG:     <<Const60:i\d+>>  IntConstant 60
198   /// CHECK-DAG:     <<Const7:j\d+>>   LongConstant 7
199   /// CHECK-DAG:     <<UShr:j\d+>>     UShr [<<Arg>>,<<Const60>>]
200   /// CHECK-DAG:     <<And:j\d+>>      And [<<UShr>>,<<Const7>>]
201   /// CHECK-DAG:                       Return [<<And>>]
202 
$noinline$UShr60And7(long arg)203   public static long $noinline$UShr60And7(long arg) {
204     if (doThrow) { throw new Error(); }
205     return (arg >>> 60) & 7;
206   }
207 
208   /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (before)
209   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
210   /// CHECK-DAG:     <<Const24:i\d+>>  IntConstant 24
211   /// CHECK-DAG:     <<Const255:i\d+>> IntConstant 255
212   /// CHECK-DAG:     <<Shr:i\d+>>      Shr [<<Arg>>,<<Const24>>]
213   /// CHECK-DAG:     <<And:i\d+>>      And [<<Shr>>,<<Const255>>]
214   /// CHECK-DAG:                       Return [<<And>>]
215 
216   /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
217   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
218   /// CHECK-DAG:     <<Const24:i\d+>>  IntConstant 24
219   /// CHECK-DAG:     <<UShr:i\d+>>     UShr [<<Arg>>,<<Const24>>]
220   /// CHECK-DAG:                       Return [<<UShr>>]
221 
222   /// CHECK-START: int Main.$noinline$Shr24And255(int) instruction_simplifier (after)
223   /// CHECK-NOT:                       Shr
224   /// CHECK-NOT:                       And
225 
$noinline$Shr24And255(int arg)226   public static int $noinline$Shr24And255(int arg) {
227     if (doThrow) { throw new Error(); }
228     return (arg >> 24) & 255;
229   }
230 
231   /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (before)
232   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
233   /// CHECK-DAG:     <<Const56:i\d+>>  IntConstant 56
234   /// CHECK-DAG:     <<Const255:j\d+>> LongConstant 255
235   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const56>>]
236   /// CHECK-DAG:     <<And:j\d+>>      And [<<Shr>>,<<Const255>>]
237   /// CHECK-DAG:                       Return [<<And>>]
238 
239   /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
240   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
241   /// CHECK-DAG:     <<Const56:i\d+>>  IntConstant 56
242   /// CHECK-DAG:     <<UShr:j\d+>>     UShr [<<Arg>>,<<Const56>>]
243   /// CHECK-DAG:                       Return [<<UShr>>]
244 
245   /// CHECK-START: long Main.$noinline$Shr56And255(long) instruction_simplifier (after)
246   /// CHECK-NOT:                       Shr
247   /// CHECK-NOT:                       And
248 
$noinline$Shr56And255(long arg)249   public static long $noinline$Shr56And255(long arg) {
250     if (doThrow) { throw new Error(); }
251     return (arg >> 56) & 255;
252   }
253 
254   /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (before)
255   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
256   /// CHECK-DAG:     <<Const24:i\d+>>  IntConstant 24
257   /// CHECK-DAG:     <<Const127:i\d+>> IntConstant 127
258   /// CHECK-DAG:     <<Shr:i\d+>>      Shr [<<Arg>>,<<Const24>>]
259   /// CHECK-DAG:     <<And:i\d+>>      And [<<Shr>>,<<Const127>>]
260   /// CHECK-DAG:                       Return [<<And>>]
261 
262   /// CHECK-START: int Main.$noinline$Shr24And127(int) instruction_simplifier (after)
263   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
264   /// CHECK-DAG:     <<Const24:i\d+>>  IntConstant 24
265   /// CHECK-DAG:     <<Const127:i\d+>> IntConstant 127
266   /// CHECK-DAG:     <<Shr:i\d+>>      Shr [<<Arg>>,<<Const24>>]
267   /// CHECK-DAG:     <<And:i\d+>>      And [<<Shr>>,<<Const127>>]
268   /// CHECK-DAG:                       Return [<<And>>]
269 
$noinline$Shr24And127(int arg)270   public static int $noinline$Shr24And127(int arg) {
271     if (doThrow) { throw new Error(); }
272     return (arg >> 24) & 127;
273   }
274 
275   /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (before)
276   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
277   /// CHECK-DAG:     <<Const56:i\d+>>  IntConstant 56
278   /// CHECK-DAG:     <<Const127:j\d+>> LongConstant 127
279   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const56>>]
280   /// CHECK-DAG:     <<And:j\d+>>      And [<<Shr>>,<<Const127>>]
281   /// CHECK-DAG:                       Return [<<And>>]
282 
283   /// CHECK-START: long Main.$noinline$Shr56And127(long) instruction_simplifier (after)
284   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
285   /// CHECK-DAG:     <<Const56:i\d+>>  IntConstant 56
286   /// CHECK-DAG:     <<Const127:j\d+>> LongConstant 127
287   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const56>>]
288   /// CHECK-DAG:     <<And:j\d+>>      And [<<Shr>>,<<Const127>>]
289   /// CHECK-DAG:                       Return [<<And>>]
290 
$noinline$Shr56And127(long arg)291   public static long $noinline$Shr56And127(long arg) {
292     if (doThrow) { throw new Error(); }
293     return (arg >> 56) & 127;
294   }
295 
296   /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (before)
297   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
298   /// CHECK-DAG:     <<Const1:j\d+>>  LongConstant 1
299   /// CHECK-DAG:     <<Div:j\d+>>     Div [<<Arg>>,<<Const1>>]
300   /// CHECK-DAG:                      Return [<<Div>>]
301 
302   /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
303   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
304   /// CHECK-DAG:                      Return [<<Arg>>]
305 
306   /// CHECK-START: long Main.$noinline$Div1(long) instruction_simplifier (after)
307   /// CHECK-NOT:                      Div
308 
$noinline$Div1(long arg)309   public static long $noinline$Div1(long arg) {
310     if (doThrow) { throw new Error(); }
311     return arg / 1;
312   }
313 
314   /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (before)
315   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
316   /// CHECK-DAG:     <<ConstN1:i\d+>>  IntConstant -1
317   /// CHECK-DAG:     <<Div:i\d+>>      Div [<<Arg>>,<<ConstN1>>]
318   /// CHECK-DAG:                       Return [<<Div>>]
319 
320   /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
321   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
322   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg>>]
323   /// CHECK-DAG:                       Return [<<Neg>>]
324 
325   /// CHECK-START: int Main.$noinline$DivN1(int) instruction_simplifier (after)
326   /// CHECK-NOT:                       Div
327 
$noinline$DivN1(int arg)328   public static int $noinline$DivN1(int arg) {
329     if (doThrow) { throw new Error(); }
330     return arg / -1;
331   }
332 
333   /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (before)
334   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
335   /// CHECK-DAG:     <<Const1:j\d+>>  LongConstant 1
336   /// CHECK-DAG:     <<Mul:j\d+>>     Mul [<<Const1>>,<<Arg>>]
337   /// CHECK-DAG:                      Return [<<Mul>>]
338 
339   /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
340   /// CHECK-DAG:     <<Arg:j\d+>>     ParameterValue
341   /// CHECK-DAG:                      Return [<<Arg>>]
342 
343   /// CHECK-START: long Main.$noinline$Mul1(long) instruction_simplifier (after)
344   /// CHECK-NOT:                       Mul
345 
$noinline$Mul1(long arg)346   public static long $noinline$Mul1(long arg) {
347     if (doThrow) { throw new Error(); }
348     return arg * 1;
349   }
350 
351   /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (before)
352   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
353   /// CHECK-DAG:     <<ConstN1:i\d+>>  IntConstant -1
354   /// CHECK-DAG:     <<Mul:i\d+>>      Mul [<<Arg>>,<<ConstN1>>]
355   /// CHECK-DAG:                       Return [<<Mul>>]
356 
357   /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
358   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
359   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg>>]
360   /// CHECK-DAG:                       Return [<<Neg>>]
361 
362   /// CHECK-START: int Main.$noinline$MulN1(int) instruction_simplifier (after)
363   /// CHECK-NOT:                       Mul
364 
$noinline$MulN1(int arg)365   public static int $noinline$MulN1(int arg) {
366     if (doThrow) { throw new Error(); }
367     return arg * -1;
368   }
369 
370   /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (before)
371   /// CHECK-DAG:     <<Arg:j\d+>>       ParameterValue
372   /// CHECK-DAG:     <<Const128:j\d+>>  LongConstant 128
373   /// CHECK-DAG:     <<Mul:j\d+>>       Mul [<<Const128>>,<<Arg>>]
374   /// CHECK-DAG:                        Return [<<Mul>>]
375 
376   /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
377   /// CHECK-DAG:     <<Arg:j\d+>>       ParameterValue
378   /// CHECK-DAG:     <<Const7:i\d+>>    IntConstant 7
379   /// CHECK-DAG:     <<Shl:j\d+>>       Shl [<<Arg>>,<<Const7>>]
380   /// CHECK-DAG:                        Return [<<Shl>>]
381 
382   /// CHECK-START: long Main.$noinline$MulPowerOfTwo128(long) instruction_simplifier (after)
383   /// CHECK-NOT:                        Mul
384 
$noinline$MulPowerOfTwo128(long arg)385   public static long $noinline$MulPowerOfTwo128(long arg) {
386     if (doThrow) { throw new Error(); }
387     return arg * 128;
388   }
389 
390   /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (before)
391   /// CHECK-DAG:     <<ArgValue:j\d+>>  ParameterValue
392   /// CHECK-DAG:     <<Const10:j\d+>>   LongConstant 10
393   /// CHECK-DAG:     <<Const11:j\d+>>   LongConstant 11
394   /// CHECK-DAG:     <<Const12:j\d+>>   LongConstant 12
395   /// CHECK-DAG:     <<Mul1:j\d+>>      Mul [<<Const10>>,<<ArgValue>>]
396   /// CHECK-DAG:     <<Mul2:j\d+>>      Mul [<<Mul1>>,<<Const11>>]
397   /// CHECK-DAG:     <<Mul3:j\d+>>      Mul [<<Mul2>>,<<Const12>>]
398   /// CHECK-DAG:                        Return [<<Mul3>>]
399 
400   /// CHECK-START: long Main.$noinline$MulMulMulConst(long) instruction_simplifier (after)
401   /// CHECK-DAG:     <<ArgValue:j\d+>>   ParameterValue
402   /// CHECK-DAG:     <<Const1320:j\d+>>  LongConstant 1320
403   /// CHECK-DAG:     <<Mul:j\d+>>        Mul [<<ArgValue>>,<<Const1320>>]
404   /// CHECK-DAG:                         Return [<<Mul>>]
405 
$noinline$MulMulMulConst(long arg)406   public static long $noinline$MulMulMulConst(long arg) {
407     if (doThrow) { throw new Error(); }
408     return 10 * arg * 11 * 12;
409   }
410 
411   /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (before)
412   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
413   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
414   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Arg>>,<<Const0>>]
415   /// CHECK-DAG:                       Return [<<Or>>]
416 
417   /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
418   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
419   /// CHECK-DAG:                       Return [<<Arg>>]
420 
421   /// CHECK-START: int Main.$noinline$Or0(int) instruction_simplifier (after)
422   /// CHECK-NOT:                       Or
423 
$noinline$Or0(int arg)424   public static int $noinline$Or0(int arg) {
425     if (doThrow) { throw new Error(); }
426     return arg | 0;
427   }
428 
429   /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (before)
430   /// CHECK-DAG:     <<Arg:j\d+>>       ParameterValue
431   /// CHECK-DAG:     <<Or:j\d+>>        Or [<<Arg>>,<<Arg>>]
432   /// CHECK-DAG:                        Return [<<Or>>]
433 
434   /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
435   /// CHECK-DAG:     <<Arg:j\d+>>       ParameterValue
436   /// CHECK-DAG:                        Return [<<Arg>>]
437 
438   /// CHECK-START: long Main.$noinline$OrSame(long) instruction_simplifier (after)
439   /// CHECK-NOT:                        Or
440 
$noinline$OrSame(long arg)441   public static long $noinline$OrSame(long arg) {
442     if (doThrow) { throw new Error(); }
443     return arg | arg;
444   }
445 
446   /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (before)
447   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
448   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
449   /// CHECK-DAG:     <<Shl:i\d+>>      Shl [<<Arg>>,<<Const0>>]
450   /// CHECK-DAG:                       Return [<<Shl>>]
451 
452   /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
453   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
454   /// CHECK-DAG:                       Return [<<Arg>>]
455 
456   /// CHECK-START: int Main.$noinline$Shl0(int) instruction_simplifier (after)
457   /// CHECK-NOT:                       Shl
458 
$noinline$Shl0(int arg)459   public static int $noinline$Shl0(int arg) {
460     if (doThrow) { throw new Error(); }
461     return arg << 0;
462   }
463 
464   /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (before)
465   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
466   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
467   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const0>>]
468   /// CHECK-DAG:                       Return [<<Shr>>]
469 
470   /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
471   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
472   /// CHECK-DAG:                       Return [<<Arg>>]
473 
474   /// CHECK-START: long Main.$noinline$Shr0(long) instruction_simplifier (after)
475   /// CHECK-NOT:                       Shr
476 
$noinline$Shr0(long arg)477   public static long $noinline$Shr0(long arg) {
478     if (doThrow) { throw new Error(); }
479     return arg >> 0;
480   }
481 
482   /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (before)
483   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
484   /// CHECK-DAG:     <<Const64:i\d+>>  IntConstant 64
485   /// CHECK-DAG:     <<Shr:j\d+>>      Shr [<<Arg>>,<<Const64>>]
486   /// CHECK-DAG:                       Return [<<Shr>>]
487 
488   /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
489   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
490   /// CHECK-DAG:                       Return [<<Arg>>]
491 
492   /// CHECK-START: long Main.$noinline$Shr64(long) instruction_simplifier (after)
493   /// CHECK-NOT:                       Shr
494 
$noinline$Shr64(long arg)495   public static long $noinline$Shr64(long arg) {
496     if (doThrow) { throw new Error(); }
497     return arg >> 64;
498   }
499 
500   /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (before)
501   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
502   /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
503   /// CHECK-DAG:     <<Sub:j\d+>>      Sub [<<Arg>>,<<Const0>>]
504   /// CHECK-DAG:                       Return [<<Sub>>]
505 
506   /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
507   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
508   /// CHECK-DAG:                       Return [<<Arg>>]
509 
510   /// CHECK-START: long Main.$noinline$Sub0(long) instruction_simplifier (after)
511   /// CHECK-NOT:                       Sub
512 
$noinline$Sub0(long arg)513   public static long $noinline$Sub0(long arg) {
514     if (doThrow) { throw new Error(); }
515     return arg - 0;
516   }
517 
518   /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (before)
519   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
520   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
521   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Const0>>,<<Arg>>]
522   /// CHECK-DAG:                       Return [<<Sub>>]
523 
524   /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
525   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
526   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg>>]
527   /// CHECK-DAG:                       Return [<<Neg>>]
528 
529   /// CHECK-START: int Main.$noinline$SubAliasNeg(int) instruction_simplifier (after)
530   /// CHECK-NOT:                       Sub
531 
$noinline$SubAliasNeg(int arg)532   public static int $noinline$SubAliasNeg(int arg) {
533     if (doThrow) { throw new Error(); }
534     return 0 - arg;
535   }
536 
537   /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (before)
538   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
539   /// CHECK-DAG:     <<Const5:i\d+>>    IntConstant 5
540   /// CHECK-DAG:     <<Const6:i\d+>>    IntConstant 6
541   /// CHECK-DAG:     <<Sub:i\d+>>       Sub [<<Const5>>,<<ArgValue>>]
542   /// CHECK-DAG:     <<Add:i\d+>>       Add [<<Sub>>,<<Const6>>]
543   /// CHECK-DAG:                        Return [<<Add>>]
544 
545   /// CHECK-START: int Main.$noinline$SubAddConst1(int) instruction_simplifier (after)
546   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
547   /// CHECK-DAG:     <<Const11:i\d+>>   IntConstant 11
548   /// CHECK-DAG:     <<Sub:i\d+>>       Sub [<<Const11>>,<<ArgValue>>]
549   /// CHECK-DAG:                        Return [<<Sub>>]
550 
$noinline$SubAddConst1(int arg)551   public static int $noinline$SubAddConst1(int arg) {
552     if (doThrow) { throw new Error(); }
553     return 5 - arg + 6;
554   }
555 
556   /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (before)
557   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
558   /// CHECK-DAG:     <<Const14:i\d+>>   IntConstant 14
559   /// CHECK-DAG:     <<Const13:i\d+>>   IntConstant 13
560   /// CHECK-DAG:     <<Add:i\d+>>       Add [<<ArgValue>>,<<Const13>>]
561   /// CHECK-DAG:     <<Sub:i\d+>>       Sub [<<Const14>>,<<Add>>]
562   /// CHECK-DAG:                        Return [<<Sub>>]
563 
564   /// CHECK-START: int Main.$noinline$SubAddConst2(int) instruction_simplifier (after)
565   /// CHECK-DAG:     <<ArgValue:i\d+>>  ParameterValue
566   /// CHECK-DAG:     <<Const1:i\d+>>    IntConstant 1
567   /// CHECK-DAG:     <<Sub:i\d+>>       Sub [<<Const1>>,<<ArgValue>>]
568   /// CHECK-DAG:                        Return [<<Sub>>]
569 
$noinline$SubAddConst2(int arg)570   public static int $noinline$SubAddConst2(int arg) {
571     if (doThrow) { throw new Error(); }
572     return 14 - (arg + 13);
573   }
574 
575   /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (before)
576   /// CHECK-DAG:     <<ArgValue:j\d+>>  ParameterValue
577   /// CHECK-DAG:     <<Const17:j\d+>>   LongConstant 17
578   /// CHECK-DAG:     <<Const18:j\d+>>   LongConstant 18
579   /// CHECK-DAG:     <<Sub1:j\d+>>      Sub [<<Const18>>,<<ArgValue>>]
580   /// CHECK-DAG:     <<Sub2:j\d+>>      Sub [<<Const17>>,<<Sub1>>]
581   /// CHECK-DAG:                        Return [<<Sub2>>]
582 
583   /// CHECK-START: long Main.$noinline$SubSubConst(long) instruction_simplifier (after)
584   /// CHECK-DAG:     <<ArgValue:j\d+>>  ParameterValue
585   /// CHECK-DAG:     <<ConstM1:j\d+>>   LongConstant -1
586   /// CHECK-DAG:     <<Add:j\d+>>       Add [<<ArgValue>>,<<ConstM1>>]
587   /// CHECK-DAG:                        Return [<<Add>>]
588 
$noinline$SubSubConst(long arg)589   public static long $noinline$SubSubConst(long arg) {
590     if (doThrow) { throw new Error(); }
591     return 17 - (18 - arg);
592   }
593 
594   /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (before)
595   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
596   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
597   /// CHECK-DAG:     <<UShr:j\d+>>     UShr [<<Arg>>,<<Const0>>]
598   /// CHECK-DAG:                       Return [<<UShr>>]
599 
600   /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
601   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
602   /// CHECK-DAG:                       Return [<<Arg>>]
603 
604   /// CHECK-START: long Main.$noinline$UShr0(long) instruction_simplifier (after)
605   /// CHECK-NOT:                       UShr
606 
$noinline$UShr0(long arg)607   public static long $noinline$UShr0(long arg) {
608     if (doThrow) { throw new Error(); }
609     return arg >>> 0;
610   }
611 
612   /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (before)
613   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
614   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
615   /// CHECK-DAG:     <<Xor:i\d+>>      Xor [<<Arg>>,<<Const0>>]
616   /// CHECK-DAG:                       Return [<<Xor>>]
617 
618   /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
619   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
620   /// CHECK-DAG:                       Return [<<Arg>>]
621 
622   /// CHECK-START: int Main.$noinline$Xor0(int) instruction_simplifier (after)
623   /// CHECK-NOT:                       Xor
624 
$noinline$Xor0(int arg)625   public static int $noinline$Xor0(int arg) {
626     if (doThrow) { throw new Error(); }
627     return arg ^ 0;
628   }
629 
630   /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (before)
631   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
632   /// CHECK-DAG:     <<ConstF:i\d+>>   IntConstant -1
633   /// CHECK-DAG:     <<Xor:i\d+>>      Xor [<<Arg>>,<<ConstF>>]
634   /// CHECK-DAG:                       Return [<<Xor>>]
635 
636   /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
637   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
638   /// CHECK-DAG:     <<Not:i\d+>>      Not [<<Arg>>]
639   /// CHECK-DAG:                       Return [<<Not>>]
640 
641   /// CHECK-START: int Main.$noinline$XorAllOnes(int) instruction_simplifier (after)
642   /// CHECK-NOT:                       Xor
643 
$noinline$XorAllOnes(int arg)644   public static int $noinline$XorAllOnes(int arg) {
645     if (doThrow) { throw new Error(); }
646     return arg ^ -1;
647   }
648 
649   /**
650    * Test that addition or subtraction operation with both inputs negated are
651    * optimized to use a single negation after the operation.
652    * The transformation tested is implemented in
653    * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
654    */
655 
656   /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (before)
657   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
658   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
659   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg1>>]
660   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Arg2>>]
661   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Neg1>>,<<Neg2>>]
662   /// CHECK-DAG:                       Return [<<Add>>]
663 
664   /// CHECK-START: int Main.$noinline$AddNegs1(int, int) instruction_simplifier (after)
665   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
666   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
667   /// CHECK-NOT:                       Neg
668   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Arg1>>,<<Arg2>>]
669   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Add>>]
670   /// CHECK-DAG:                       Return [<<Neg>>]
671 
$noinline$AddNegs1(int arg1, int arg2)672   public static int $noinline$AddNegs1(int arg1, int arg2) {
673     if (doThrow) { throw new Error(); }
674     return -arg1 + -arg2;
675   }
676 
677   /**
678    * This is similar to the test-case AddNegs1, but the negations have
679    * multiple uses.
680    * The transformation tested is implemented in
681    * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
682    * The current code won't perform the previous optimization. The
683    * transformations do not look at other uses of their inputs. As they don't
684    * know what will happen with other uses, they do not take the risk of
685    * increasing the register pressure by creating or extending live ranges.
686    */
687 
688   /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (before)
689   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
690   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
691   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg1>>]
692   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Arg2>>]
693   /// CHECK-DAG:     <<Add1:i\d+>>     Add [<<Neg1>>,<<Neg2>>]
694   /// CHECK-DAG:     <<Add2:i\d+>>     Add [<<Neg1>>,<<Neg2>>]
695   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Add1>>,<<Add2>>]
696   /// CHECK-DAG:                       Return [<<Or>>]
697 
698   /// CHECK-START: int Main.$noinline$AddNegs2(int, int) instruction_simplifier (after)
699   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
700   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
701   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg1>>]
702   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Arg2>>]
703   /// CHECK-DAG:     <<Add1:i\d+>>     Add [<<Neg1>>,<<Neg2>>]
704   /// CHECK-DAG:     <<Add2:i\d+>>     Add [<<Neg1>>,<<Neg2>>]
705   /// CHECK-NOT:                       Neg
706   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Add1>>,<<Add2>>]
707   /// CHECK-DAG:                       Return [<<Or>>]
708 
709   /// CHECK-START: int Main.$noinline$AddNegs2(int, int) GVN (after)
710   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
711   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
712   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg1>>]
713   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Arg2>>]
714   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Neg1>>,<<Neg2>>]
715   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Add>>,<<Add>>]
716   /// CHECK-DAG:                       Return [<<Or>>]
717 
$noinline$AddNegs2(int arg1, int arg2)718   public static int $noinline$AddNegs2(int arg1, int arg2) {
719     if (doThrow) { throw new Error(); }
720     int temp1 = -arg1;
721     int temp2 = -arg2;
722     return (temp1 + temp2) | (temp1 + temp2);
723   }
724 
725   /**
726    * This follows test-cases AddNegs1 and AddNegs2.
727    * The transformation tested is implemented in
728    * `InstructionSimplifierVisitor::TryMoveNegOnInputsAfterBinop`.
729    * The optimization should not happen if it moves an additional instruction in
730    * the loop.
731    */
732 
733   /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (before)
734   //  -------------- Arguments and initial negation operations.
735   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
736   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
737   /// CHECK-DAG:     <<Neg1:j\d+>>     Neg [<<Arg1>>]
738   /// CHECK-DAG:     <<Neg2:j\d+>>     Neg [<<Arg2>>]
739   /// CHECK:                           Goto
740   //  -------------- Loop
741   /// CHECK:                           SuspendCheck
742   /// CHECK:         <<Add:j\d+>>      Add [<<Neg1>>,<<Neg2>>]
743   /// CHECK:                           Goto
744 
745   /// CHECK-START: long Main.$noinline$AddNegs3(long, long) instruction_simplifier (after)
746   //  -------------- Arguments and initial negation operations.
747   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
748   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
749   /// CHECK-DAG:     <<Neg1:j\d+>>     Neg [<<Arg1>>]
750   /// CHECK-DAG:     <<Neg2:j\d+>>     Neg [<<Arg2>>]
751   /// CHECK:                           Goto
752   //  -------------- Loop
753   /// CHECK:                           SuspendCheck
754   /// CHECK:         <<Add:j\d+>>      Add [<<Neg1>>,<<Neg2>>]
755   /// CHECK-NOT:                       Neg
756   /// CHECK:                           Goto
757 
$noinline$AddNegs3(long arg1, long arg2)758   public static long $noinline$AddNegs3(long arg1, long arg2) {
759     if (doThrow) { throw new Error(); }
760     long res = 0;
761     long n_arg1 = -arg1;
762     long n_arg2 = -arg2;
763     for (long i = 0; i < 1; i++) {
764       res += n_arg1 + n_arg2 + i;
765     }
766     return res;
767   }
768 
769   /**
770    * Test the simplification of an addition with a negated argument into a
771    * subtraction.
772    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
773    */
774 
775   /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (before)
776   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
777   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
778   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg1>>]
779   /// CHECK-DAG:     <<Add:j\d+>>      Add [<<Neg>>,<<Arg2>>]
780   /// CHECK-DAG:                       Return [<<Add>>]
781 
782   /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
783   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
784   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
785   /// CHECK-DAG:     <<Sub:j\d+>>      Sub [<<Arg2>>,<<Arg1>>]
786   /// CHECK-DAG:                       Return [<<Sub>>]
787 
788   /// CHECK-START: long Main.$noinline$AddNeg1(long, long) instruction_simplifier (after)
789   /// CHECK-NOT:                       Neg
790   /// CHECK-NOT:                       Add
791 
$noinline$AddNeg1(long arg1, long arg2)792   public static long $noinline$AddNeg1(long arg1, long arg2) {
793     if (doThrow) { throw new Error(); }
794     return -arg1 + arg2;
795   }
796 
797   /**
798    * This is similar to the test-case AddNeg1, but the negation has two uses.
799    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitAdd`.
800    * The current code won't perform the previous optimization. The
801    * transformations do not look at other uses of their inputs. As they don't
802    * know what will happen with other uses, they do not take the risk of
803    * increasing the register pressure by creating or extending live ranges.
804    */
805 
806   /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (before)
807   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
808   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
809   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg2>>]
810   /// CHECK-DAG:     <<Add1:j\d+>>     Add [<<Arg1>>,<<Neg>>]
811   /// CHECK-DAG:     <<Add2:j\d+>>     Add [<<Arg1>>,<<Neg>>]
812   /// CHECK-DAG:     <<Res:j\d+>>      Or [<<Add1>>,<<Add2>>]
813   /// CHECK-DAG:                       Return [<<Res>>]
814 
815   /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
816   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
817   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
818   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg2>>]
819   /// CHECK-DAG:     <<Add1:j\d+>>     Add [<<Arg1>>,<<Neg>>]
820   /// CHECK-DAG:     <<Add2:j\d+>>     Add [<<Arg1>>,<<Neg>>]
821   /// CHECK-DAG:     <<Res:j\d+>>      Or [<<Add1>>,<<Add2>>]
822   /// CHECK-DAG:                       Return [<<Res>>]
823 
824   /// CHECK-START: long Main.$noinline$AddNeg2(long, long) instruction_simplifier (after)
825   /// CHECK-NOT:                       Sub
826 
$noinline$AddNeg2(long arg1, long arg2)827   public static long $noinline$AddNeg2(long arg1, long arg2) {
828     if (doThrow) { throw new Error(); }
829     long temp = -arg2;
830     return (arg1 + temp) | (arg1 + temp);
831   }
832 
833   /**
834    * Test simplification of the `-(-var)` pattern.
835    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
836    */
837 
838   /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (before)
839   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
840   /// CHECK-DAG:     <<Neg1:j\d+>>     Neg [<<Arg>>]
841   /// CHECK-DAG:     <<Neg2:j\d+>>     Neg [<<Neg1>>]
842   /// CHECK-DAG:                       Return [<<Neg2>>]
843 
844   /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
845   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
846   /// CHECK-DAG:                       Return [<<Arg>>]
847 
848   /// CHECK-START: long Main.$noinline$NegNeg1(long) instruction_simplifier (after)
849   /// CHECK-NOT:                       Neg
850 
$noinline$NegNeg1(long arg)851   public static long $noinline$NegNeg1(long arg) {
852     if (doThrow) { throw new Error(); }
853     return -(-arg);
854   }
855 
856   /**
857    * Test 'multi-step' simplification, where a first transformation yields a
858    * new simplification possibility for the current instruction.
859    * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
860    * and in `InstructionSimplifierVisitor::VisitAdd`.
861    */
862 
863   /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (before)
864   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
865   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Arg>>]
866   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Neg1>>]
867   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Neg2>>,<<Neg1>>]
868   /// CHECK-DAG:                       Return [<<Add>>]
869 
870   /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
871   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
872   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg>>,<<Arg>>]
873   /// CHECK-DAG:                       Return [<<Sub>>]
874 
875   /// CHECK-START: int Main.$noinline$NegNeg2(int) instruction_simplifier (after)
876   /// CHECK-NOT:                       Neg
877   /// CHECK-NOT:                       Add
878 
879   /// CHECK-START: int Main.$noinline$NegNeg2(int) constant_folding$after_inlining (after)
880   /// CHECK:         <<Const0:i\d+>>   IntConstant 0
881   /// CHECK-NOT:                       Neg
882   /// CHECK-NOT:                       Add
883   /// CHECK:                           Return [<<Const0>>]
884 
$noinline$NegNeg2(int arg)885   public static int $noinline$NegNeg2(int arg) {
886     if (doThrow) { throw new Error(); }
887     int temp = -arg;
888     return temp + -temp;
889   }
890 
891   /**
892    * Test another 'multi-step' simplification, where a first transformation
893    * yields a new simplification possibility for the current instruction.
894    * The transformations tested are implemented in `InstructionSimplifierVisitor::VisitNeg`
895    * and in `InstructionSimplifierVisitor::VisitSub`.
896    */
897 
898   /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (before)
899   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
900   /// CHECK-DAG:     <<Const0:j\d+>>   LongConstant 0
901   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg>>]
902   /// CHECK-DAG:     <<Sub:j\d+>>      Sub [<<Const0>>,<<Neg>>]
903   /// CHECK-DAG:                       Return [<<Sub>>]
904 
905   /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
906   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
907   /// CHECK-DAG:                       Return [<<Arg>>]
908 
909   /// CHECK-START: long Main.$noinline$NegNeg3(long) instruction_simplifier (after)
910   /// CHECK-NOT:                       Neg
911   /// CHECK-NOT:                       Sub
912 
$noinline$NegNeg3(long arg)913   public static long $noinline$NegNeg3(long arg) {
914     if (doThrow) { throw new Error(); }
915     return 0 - -arg;
916   }
917 
918   /**
919    * Test that a negated subtraction is simplified to a subtraction with its
920    * arguments reversed.
921    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
922    */
923 
924   /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (before)
925   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
926   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
927   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg1>>,<<Arg2>>]
928   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Sub>>]
929   /// CHECK-DAG:                       Return [<<Neg>>]
930 
931   /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
932   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
933   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
934   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg2>>,<<Arg1>>]
935   /// CHECK-DAG:                       Return [<<Sub>>]
936 
937   /// CHECK-START: int Main.$noinline$NegSub1(int, int) instruction_simplifier (after)
938   /// CHECK-NOT:                       Neg
939 
$noinline$NegSub1(int arg1, int arg2)940   public static int $noinline$NegSub1(int arg1, int arg2) {
941     if (doThrow) { throw new Error(); }
942     return -(arg1 - arg2);
943   }
944 
945   /**
946    * This is similar to the test-case NegSub1, but the subtraction has
947    * multiple uses.
948    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNeg`.
949    * The current code won't perform the previous optimization. The
950    * transformations do not look at other uses of their inputs. As they don't
951    * know what will happen with other uses, they do not take the risk of
952    * increasing the register pressure by creating or extending live ranges.
953    */
954 
955   /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (before)
956   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
957   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
958   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg1>>,<<Arg2>>]
959   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Sub>>]
960   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Sub>>]
961   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Neg1>>,<<Neg2>>]
962   /// CHECK-DAG:                       Return [<<Or>>]
963 
964   /// CHECK-START: int Main.$noinline$NegSub2(int, int) instruction_simplifier (after)
965   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
966   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
967   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Arg1>>,<<Arg2>>]
968   /// CHECK-DAG:     <<Neg1:i\d+>>     Neg [<<Sub>>]
969   /// CHECK-DAG:     <<Neg2:i\d+>>     Neg [<<Sub>>]
970   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Neg1>>,<<Neg2>>]
971   /// CHECK-DAG:                       Return [<<Or>>]
972 
$noinline$NegSub2(int arg1, int arg2)973   public static int $noinline$NegSub2(int arg1, int arg2) {
974     if (doThrow) { throw new Error(); }
975     int temp = arg1 - arg2;
976     return -temp | -temp;
977   }
978 
979   /**
980    * Test simplification of the `~~var` pattern.
981    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitNot`.
982    */
983 
984   /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (before)
985   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
986   /// CHECK-DAG:     <<Not1:j\d+>>     Not [<<Arg>>]
987   /// CHECK-DAG:     <<Not2:j\d+>>     Not [<<Not1>>]
988   /// CHECK-DAG:                       Return [<<Not2>>]
989 
990   /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
991   /// CHECK-DAG:     <<Arg:j\d+>>      ParameterValue
992   /// CHECK-DAG:                       Return [<<Arg>>]
993 
994   /// CHECK-START: long Main.$noinline$NotNot1(long) instruction_simplifier (after)
995   /// CHECK-NOT:                       Not
996 
$noinline$NotNot1(long arg)997   public static long $noinline$NotNot1(long arg) {
998     if (doThrow) { throw new Error(); }
999     return ~~arg;
1000   }
1001 
1002   /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (before)
1003   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1004   /// CHECK-DAG:     <<Not1:i\d+>>     Not [<<Arg>>]
1005   /// CHECK-DAG:     <<Not2:i\d+>>     Not [<<Not1>>]
1006   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Not2>>,<<Not1>>]
1007   /// CHECK-DAG:                       Return [<<Add>>]
1008 
1009   /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
1010   /// CHECK-DAG:     <<Arg:i\d+>>      ParameterValue
1011   /// CHECK-DAG:     <<Not:i\d+>>      Not [<<Arg>>]
1012   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Arg>>,<<Not>>]
1013   /// CHECK-DAG:                       Return [<<Add>>]
1014 
1015   /// CHECK-START: int Main.$noinline$NotNot2(int) instruction_simplifier (after)
1016   /// CHECK:                           Not
1017   /// CHECK-NOT:                       Not
1018 
$noinline$NotNot2(int arg)1019   public static int $noinline$NotNot2(int arg) {
1020     if (doThrow) { throw new Error(); }
1021     int temp = ~arg;
1022     return temp + ~temp;
1023   }
1024 
1025   /**
1026    * Test the simplification of a subtraction with a negated argument.
1027    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1028    */
1029 
1030   /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (before)
1031   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
1032   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
1033   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg1>>]
1034   /// CHECK-DAG:     <<Sub:i\d+>>      Sub [<<Neg>>,<<Arg2>>]
1035   /// CHECK-DAG:                       Return [<<Sub>>]
1036 
1037   /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
1038   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
1039   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
1040   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<Arg1>>,<<Arg2>>]
1041   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Add>>]
1042   /// CHECK-DAG:                       Return [<<Neg>>]
1043 
1044   /// CHECK-START: int Main.$noinline$SubNeg1(int, int) instruction_simplifier (after)
1045   /// CHECK-NOT:                       Sub
1046 
$noinline$SubNeg1(int arg1, int arg2)1047   public static int $noinline$SubNeg1(int arg1, int arg2) {
1048     if (doThrow) { throw new Error(); }
1049     return -arg1 - arg2;
1050   }
1051 
1052   /**
1053    * This is similar to the test-case SubNeg1, but the negation has
1054    * multiple uses.
1055    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1056    * The current code won't perform the previous optimization. The
1057    * transformations do not look at other uses of their inputs. As they don't
1058    * know what will happen with other uses, they do not take the risk of
1059    * increasing the register pressure by creating or extending live ranges.
1060    */
1061 
1062   /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (before)
1063   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
1064   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
1065   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg1>>]
1066   /// CHECK-DAG:     <<Sub1:i\d+>>     Sub [<<Neg>>,<<Arg2>>]
1067   /// CHECK-DAG:     <<Sub2:i\d+>>     Sub [<<Neg>>,<<Arg2>>]
1068   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Sub1>>,<<Sub2>>]
1069   /// CHECK-DAG:                       Return [<<Or>>]
1070 
1071   /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
1072   /// CHECK-DAG:     <<Arg1:i\d+>>     ParameterValue
1073   /// CHECK-DAG:     <<Arg2:i\d+>>     ParameterValue
1074   /// CHECK-DAG:     <<Neg:i\d+>>      Neg [<<Arg1>>]
1075   /// CHECK-DAG:     <<Sub1:i\d+>>     Sub [<<Neg>>,<<Arg2>>]
1076   /// CHECK-DAG:     <<Sub2:i\d+>>     Sub [<<Neg>>,<<Arg2>>]
1077   /// CHECK-DAG:     <<Or:i\d+>>       Or [<<Sub1>>,<<Sub2>>]
1078   /// CHECK-DAG:                       Return [<<Or>>]
1079 
1080   /// CHECK-START: int Main.$noinline$SubNeg2(int, int) instruction_simplifier (after)
1081   /// CHECK-NOT:                       Add
1082 
$noinline$SubNeg2(int arg1, int arg2)1083   public static int $noinline$SubNeg2(int arg1, int arg2) {
1084     if (doThrow) { throw new Error(); }
1085     int temp = -arg1;
1086     return (temp - arg2) | (temp - arg2);
1087   }
1088 
1089   /**
1090    * This follows test-cases SubNeg1 and SubNeg2.
1091    * The transformation tested is implemented in `InstructionSimplifierVisitor::VisitSub`.
1092    * The optimization should not happen if it moves an additional instruction in
1093    * the loop.
1094    */
1095 
1096   /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (before)
1097   //  -------------- Arguments and initial negation operation.
1098   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
1099   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
1100   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg1>>]
1101   /// CHECK:                           Goto
1102   //  -------------- Loop
1103   /// CHECK:                           SuspendCheck
1104   /// CHECK:         <<Sub:j\d+>>      Sub [<<Neg>>,<<Arg2>>]
1105   /// CHECK:                           Goto
1106 
1107   /// CHECK-START: long Main.$noinline$SubNeg3(long, long) instruction_simplifier (after)
1108   //  -------------- Arguments and initial negation operation.
1109   /// CHECK-DAG:     <<Arg1:j\d+>>     ParameterValue
1110   /// CHECK-DAG:     <<Arg2:j\d+>>     ParameterValue
1111   /// CHECK-DAG:     <<Neg:j\d+>>      Neg [<<Arg1>>]
1112   /// CHECK-DAG:                       Goto
1113   //  -------------- Loop
1114   /// CHECK:                           SuspendCheck
1115   /// CHECK:         <<Sub:j\d+>>      Sub [<<Neg>>,<<Arg2>>]
1116   /// CHECK-NOT:                       Neg
1117   /// CHECK:                           Goto
1118 
$noinline$SubNeg3(long arg1, long arg2)1119   public static long $noinline$SubNeg3(long arg1, long arg2) {
1120     if (doThrow) { throw new Error(); }
1121     long res = 0;
1122     long temp = -arg1;
1123     for (long i = 0; i < 1; i++) {
1124       res += temp - arg2 - i;
1125     }
1126     return res;
1127   }
1128 
1129   /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before)
1130   /// CHECK-DAG:     <<Arg:z\d+>>      ParameterValue
1131   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1132   /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
1133   /// CHECK-DAG:     <<Const2:i\d+>>   IntConstant 2
1134   /// CHECK-DAG:     <<NotArg:i\d+>>   Select [<<Const1>>,<<Const0>>,<<Arg>>]
1135   /// CHECK-DAG:     <<Cond:z\d+>>     Equal [<<NotArg>>,<<Const2>>]
1136   /// CHECK-DAG:     <<NotCond:i\d+>>  Select [<<Const1>>,<<Const0>>,<<Cond>>]
1137   /// CHECK-DAG:                       Return [<<NotCond>>]
1138 
1139   /// CHECK-START: boolean Main.$noinline$EqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after)
1140   /// CHECK-DAG:     <<True:i\d+>>     IntConstant 1
1141   /// CHECK-DAG:                       Return [<<True>>]
1142 
$noinline$EqualBoolVsIntConst(boolean arg)1143   public static boolean $noinline$EqualBoolVsIntConst(boolean arg) {
1144     if (doThrow) { throw new Error(); }
1145     // Make calls that will be inlined to make sure the instruction simplifier
1146     // sees the simplification (dead code elimination will also try to simplify it).
1147     return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) != 2;
1148   }
1149 
$inline$ReturnArg(int arg)1150   public static int $inline$ReturnArg(int arg) {
1151     return arg;
1152   }
1153 
1154   /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (before)
1155   /// CHECK-DAG:     <<Arg:z\d+>>      ParameterValue
1156   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
1157   /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
1158   /// CHECK-DAG:     <<Const2:i\d+>>   IntConstant 2
1159   /// CHECK-DAG:     <<NotArg:i\d+>>   Select [<<Const1>>,<<Const0>>,<<Arg>>]
1160   /// CHECK-DAG:     <<Cond:z\d+>>     NotEqual [<<NotArg>>,<<Const2>>]
1161   /// CHECK-DAG:     <<NotCond:i\d+>>  Select [<<Const1>>,<<Const0>>,<<Cond>>]
1162   /// CHECK-DAG:                       Return [<<NotCond>>]
1163 
1164   /// CHECK-START: boolean Main.$noinline$NotEqualBoolVsIntConst(boolean) instruction_simplifier$after_inlining (after)
1165   /// CHECK-DAG:     <<False:i\d+>>    IntConstant 0
1166   /// CHECK-DAG:                       Return [<<False>>]
1167 
$noinline$NotEqualBoolVsIntConst(boolean arg)1168   public static boolean $noinline$NotEqualBoolVsIntConst(boolean arg) {
1169     if (doThrow) { throw new Error(); }
1170     // Make calls that will be inlined to make sure the instruction simplifier
1171     // sees the simplification (dead code elimination will also try to simplify it).
1172     return (arg ? $inline$ReturnArg(0) : $inline$ReturnArg(1)) == 2;
1173   }
1174 
1175   /*
1176    * Test simplification of double Boolean negation. Note that sometimes
1177    * both negations can be removed but we only expect the simplifier to
1178    * remove the second.
1179    */
1180 
1181   /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (before)
1182   /// CHECK-DAG:     <<Arg:z\d+>>       ParameterValue
1183   /// CHECK-DAG:     <<Const1:i\d+>>    IntConstant 1
1184   /// CHECK-DAG:     <<Result:z\d+>>    InvokeStaticOrDirect
1185   /// CHECK-DAG:     <<NotResult:i\d+>> Xor [<<Result>>,<<Const1>>]
1186   /// CHECK-DAG:                        Return [<<NotResult>>]
1187 
1188   /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier (after)
1189   /// CHECK-DAG:     <<Arg:z\d+>>       ParameterValue
1190   /// CHECK-DAG:     <<Result:z\d+>>    InvokeStaticOrDirect
1191   /// CHECK-DAG:     <<NotResult:z\d+>> BooleanNot [<<Result>>]
1192   /// CHECK-DAG:                        Return [<<NotResult>>]
1193 
1194   /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (before)
1195   /// CHECK-DAG:     <<Arg:z\d+>>       ParameterValue
1196   /// CHECK-DAG:     <<NotArg:z\d+>>    BooleanNot [<<Arg>>]
1197   /// CHECK-DAG:     <<NotNotArg:z\d+>> BooleanNot [<<NotArg>>]
1198   /// CHECK-DAG:                        Return [<<NotNotArg>>]
1199 
1200   /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) instruction_simplifier$after_inlining (after)
1201   /// CHECK-DAG:     <<Arg:z\d+>>       ParameterValue
1202   /// CHECK-DAG:     <<NotArg:z\d+>>    BooleanNot [<<Arg>>]
1203   /// CHECK-DAG:                        Return [<<Arg>>]
1204 
1205   /// CHECK-START: boolean Main.$noinline$NotNotBool(boolean) dead_code_elimination$final (after)
1206   /// CHECK-DAG:     <<Arg:z\d+>>       ParameterValue
1207   /// CHECK-DAG:                        Return [<<Arg>>]
1208 
NegateValue(boolean arg)1209   public static boolean NegateValue(boolean arg) {
1210     return !arg;
1211   }
1212 
$noinline$NotNotBool(boolean arg)1213   public static boolean $noinline$NotNotBool(boolean arg) {
1214     if (doThrow) { throw new Error(); }
1215     return !(NegateValue(arg));
1216   }
1217 
1218   /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (before)
1219   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1220   /// CHECK-DAG:      <<Const2:f\d+>>   FloatConstant 2
1221   /// CHECK-DAG:      <<Div:f\d+>>      Div [<<Arg>>,<<Const2>>]
1222   /// CHECK-DAG:                        Return [<<Div>>]
1223 
1224   /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
1225   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1226   /// CHECK-DAG:      <<ConstP5:f\d+>>  FloatConstant 0.5
1227   /// CHECK-DAG:      <<Mul:f\d+>>      Mul [<<Arg>>,<<ConstP5>>]
1228   /// CHECK-DAG:                        Return [<<Mul>>]
1229 
1230   /// CHECK-START: float Main.$noinline$Div2(float) instruction_simplifier (after)
1231   /// CHECK-NOT:                        Div
1232 
$noinline$Div2(float arg)1233   public static float $noinline$Div2(float arg) {
1234     if (doThrow) { throw new Error(); }
1235     return arg / 2.0f;
1236   }
1237 
1238   /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (before)
1239   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1240   /// CHECK-DAG:      <<Const2:d\d+>>   DoubleConstant 2
1241   /// CHECK-DAG:      <<Div:d\d+>>      Div [<<Arg>>,<<Const2>>]
1242   /// CHECK-DAG:                        Return [<<Div>>]
1243 
1244   /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
1245   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1246   /// CHECK-DAG:      <<ConstP5:d\d+>>  DoubleConstant 0.5
1247   /// CHECK-DAG:      <<Mul:d\d+>>      Mul [<<Arg>>,<<ConstP5>>]
1248   /// CHECK-DAG:                        Return [<<Mul>>]
1249 
1250   /// CHECK-START: double Main.$noinline$Div2(double) instruction_simplifier (after)
1251   /// CHECK-NOT:                        Div
$noinline$Div2(double arg)1252   public static double $noinline$Div2(double arg) {
1253     if (doThrow) { throw new Error(); }
1254     return arg / 2.0;
1255   }
1256 
1257   /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (before)
1258   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1259   /// CHECK-DAG:      <<ConstMP25:f\d+>>   FloatConstant -0.25
1260   /// CHECK-DAG:      <<Div:f\d+>>      Div [<<Arg>>,<<ConstMP25>>]
1261   /// CHECK-DAG:                        Return [<<Div>>]
1262 
1263   /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
1264   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1265   /// CHECK-DAG:      <<ConstM4:f\d+>>  FloatConstant -4
1266   /// CHECK-DAG:      <<Mul:f\d+>>      Mul [<<Arg>>,<<ConstM4>>]
1267   /// CHECK-DAG:                        Return [<<Mul>>]
1268 
1269   /// CHECK-START: float Main.$noinline$DivMP25(float) instruction_simplifier (after)
1270   /// CHECK-NOT:                        Div
1271 
$noinline$DivMP25(float arg)1272   public static float $noinline$DivMP25(float arg) {
1273     if (doThrow) { throw new Error(); }
1274     return arg / -0.25f;
1275   }
1276 
1277   /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (before)
1278   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1279   /// CHECK-DAG:      <<ConstMP25:d\d+>>   DoubleConstant -0.25
1280   /// CHECK-DAG:      <<Div:d\d+>>      Div [<<Arg>>,<<ConstMP25>>]
1281   /// CHECK-DAG:                        Return [<<Div>>]
1282 
1283   /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
1284   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1285   /// CHECK-DAG:      <<ConstM4:d\d+>>  DoubleConstant -4
1286   /// CHECK-DAG:      <<Mul:d\d+>>      Mul [<<Arg>>,<<ConstM4>>]
1287   /// CHECK-DAG:                        Return [<<Mul>>]
1288 
1289   /// CHECK-START: double Main.$noinline$DivMP25(double) instruction_simplifier (after)
1290   /// CHECK-NOT:                        Div
$noinline$DivMP25(double arg)1291   public static double $noinline$DivMP25(double arg) {
1292     if (doThrow) { throw new Error(); }
1293     return arg / -0.25f;
1294   }
1295 
1296   /**
1297    * Test strength reduction of factors of the form (2^n + 1).
1298    */
1299 
1300   /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (before)
1301   /// CHECK-DAG:   <<Arg:i\d+>>         ParameterValue
1302   /// CHECK-DAG:   <<Const9:i\d+>>      IntConstant 9
1303   /// CHECK:                            Mul [<<Arg>>,<<Const9>>]
1304 
1305   /// CHECK-START: int Main.$noinline$mulPow2Plus1(int) instruction_simplifier (after)
1306   /// CHECK-DAG:   <<Arg:i\d+>>         ParameterValue
1307   /// CHECK-DAG:   <<Const3:i\d+>>      IntConstant 3
1308   /// CHECK:       <<Shift:i\d+>>       Shl [<<Arg>>,<<Const3>>]
1309   /// CHECK-NEXT:                       Add [<<Arg>>,<<Shift>>]
1310 
$noinline$mulPow2Plus1(int arg)1311   public static int $noinline$mulPow2Plus1(int arg) {
1312     if (doThrow) { throw new Error(); }
1313     return arg * 9;
1314   }
1315 
1316   /**
1317    * Test strength reduction of factors of the form (2^n - 1).
1318    */
1319 
1320   /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (before)
1321   /// CHECK-DAG:   <<Arg:j\d+>>         ParameterValue
1322   /// CHECK-DAG:   <<Const31:j\d+>>     LongConstant 31
1323   /// CHECK:                            Mul [<<Const31>>,<<Arg>>]
1324 
1325   /// CHECK-START: long Main.$noinline$mulPow2Minus1(long) instruction_simplifier (after)
1326   /// CHECK-DAG:   <<Arg:j\d+>>         ParameterValue
1327   /// CHECK-DAG:   <<Const5:i\d+>>      IntConstant 5
1328   /// CHECK:       <<Shift:j\d+>>       Shl [<<Arg>>,<<Const5>>]
1329   /// CHECK-NEXT:                       Sub [<<Shift>>,<<Arg>>]
1330 
$noinline$mulPow2Minus1(long arg)1331   public static long $noinline$mulPow2Minus1(long arg) {
1332     if (doThrow) { throw new Error(); }
1333     return arg * 31;
1334   }
1335 
1336   /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (before)
1337   /// CHECK-DAG:      <<Const1:i\d+>>   IntConstant 1
1338   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1339   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1340   /// CHECK-DAG:      <<doThrow:z\d+>>  StaticFieldGet
1341   /// CHECK-DAG:      <<Field:z\d+>>    StaticFieldGet
1342   /// CHECK-DAG:      <<NE:z\d+>>       NotEqual [<<Field>>,<<Const1>>]
1343   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const13>>,<<Const54>>,<<NE>>]
1344   /// CHECK-DAG:                        Return [<<Select>>]
1345 
1346   /// CHECK-START: int Main.$noinline$booleanFieldNotEqualOne() instruction_simplifier$after_inlining (after)
1347   /// CHECK-DAG:      <<doThrow:z\d+>>  StaticFieldGet
1348   /// CHECK-DAG:      <<Field:z\d+>>    StaticFieldGet
1349   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1350   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1351   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const54>>,<<Const13>>,<<Field>>]
1352   /// CHECK-DAG:                        Return [<<Select>>]
1353 
$noinline$booleanFieldNotEqualOne()1354   public static int $noinline$booleanFieldNotEqualOne() {
1355     if (doThrow) { throw new Error(); }
1356     return (booleanField == $inline$true()) ? 13 : 54;
1357   }
1358 
1359   /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (before)
1360   /// CHECK-DAG:      <<Const0:i\d+>>   IntConstant 0
1361   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1362   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1363   /// CHECK-DAG:      <<doThrow:z\d+>>  StaticFieldGet
1364   /// CHECK-DAG:      <<Field:z\d+>>    StaticFieldGet
1365   /// CHECK-DAG:      <<NE:z\d+>>       Equal [<<Field>>,<<Const0>>]
1366   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const13>>,<<Const54>>,<<NE>>]
1367   /// CHECK-DAG:                        Return [<<Select>>]
1368 
1369   /// CHECK-START: int Main.$noinline$booleanFieldEqualZero() instruction_simplifier$after_inlining (after)
1370   /// CHECK-DAG:      <<doThrow:z\d+>>  StaticFieldGet
1371   /// CHECK-DAG:      <<Field:z\d+>>    StaticFieldGet
1372   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1373   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1374   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const54>>,<<Const13>>,<<Field>>]
1375   /// CHECK-DAG:                        Return [<<Select>>]
1376 
$noinline$booleanFieldEqualZero()1377   public static int $noinline$booleanFieldEqualZero() {
1378     if (doThrow) { throw new Error(); }
1379     return (booleanField != $inline$false()) ? 13 : 54;
1380   }
1381 
1382   /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (before)
1383   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1384   /// CHECK-DAG:      <<Const0:i\d+>>   IntConstant 0
1385   /// CHECK-DAG:      <<Const1:i\d+>>   IntConstant 1
1386   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1387   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1388   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1389   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1390   /// CHECK-DAG:      <<GT:i\d+>>       Select [<<Const1>>,<<Const0>>,<<LE>>]
1391   /// CHECK-DAG:      <<NE:z\d+>>       NotEqual [<<GT>>,<<Const1>>]
1392   /// CHECK-DAG:      <<Result:i\d+>>   Select [<<Const13>>,<<Const54>>,<<NE>>]
1393   /// CHECK-DAG:                        Return [<<Result>>]
1394 
1395   /// CHECK-START: int Main.$noinline$intConditionNotEqualOne(int) instruction_simplifier$after_inlining (after)
1396   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1397   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1398   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1399   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1400   /// CHECK-DAG:      <<Result:i\d+>>   Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
1401   /// CHECK-DAG:      <<LE>>            LessThanOrEqual [<<Arg>>,<<Const42>>]
1402   /// CHECK-DAG:                        Return [<<Result>>]
1403   // Note that we match `LE` from Select because there are two identical
1404   // LessThanOrEqual instructions.
1405 
$noinline$intConditionNotEqualOne(int i)1406   public static int $noinline$intConditionNotEqualOne(int i) {
1407     if (doThrow) { throw new Error(); }
1408     return ((i > 42) == $inline$true()) ? 13 : 54;
1409   }
1410 
1411   /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (before)
1412   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1413   /// CHECK-DAG:      <<Const0:i\d+>>   IntConstant 0
1414   /// CHECK-DAG:      <<Const1:i\d+>>   IntConstant 1
1415   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1416   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1417   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1418   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1419   /// CHECK-DAG:      <<GT:i\d+>>       Select [<<Const1>>,<<Const0>>,<<LE>>]
1420   /// CHECK-DAG:      <<NE:z\d+>>       Equal [<<GT>>,<<Const0>>]
1421   /// CHECK-DAG:      <<Result:i\d+>>   Select [<<Const13>>,<<Const54>>,<<NE>>]
1422   /// CHECK-DAG:                        Return [<<Result>>]
1423 
1424   /// CHECK-START: int Main.$noinline$intConditionEqualZero(int) instruction_simplifier$after_inlining (after)
1425   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1426   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1427   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1428   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1429   /// CHECK-DAG:      <<Result:i\d+>>   Select [<<Const13>>,<<Const54>>,<<LE:z\d+>>]
1430   /// CHECK-DAG:      <<LE>>            LessThanOrEqual [<<Arg>>,<<Const42>>]
1431   /// CHECK-DAG:                        Return [<<Result>>]
1432   // Note that we match `LE` from Select because there are two identical
1433   // LessThanOrEqual instructions.
1434 
$noinline$intConditionEqualZero(int i)1435   public static int $noinline$intConditionEqualZero(int i) {
1436     if (doThrow) { throw new Error(); }
1437     return ((i > 42) != $inline$false()) ? 13 : 54;
1438   }
1439 
1440   // Test that conditions on float/double are not flipped.
1441 
1442   /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) builder (after)
1443   /// CHECK:                            LessThanOrEqual
1444 
1445   /// CHECK-START: int Main.$noinline$floatConditionNotEqualOne(float) instruction_simplifier$before_codegen (after)
1446   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1447   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1448   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1449   /// CHECK-DAG:      <<Const42:f\d+>>  FloatConstant 42
1450   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1451   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const13>>,<<Const54>>,<<LE>>]
1452   /// CHECK-DAG:                        Return [<<Select>>]
1453 
$noinline$floatConditionNotEqualOne(float f)1454   public static int $noinline$floatConditionNotEqualOne(float f) {
1455     if (doThrow) { throw new Error(); }
1456     return ((f > 42.0f) == true) ? 13 : 54;
1457   }
1458 
1459   /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) builder (after)
1460   /// CHECK:                            LessThanOrEqual
1461 
1462   /// CHECK-START: int Main.$noinline$doubleConditionEqualZero(double) instruction_simplifier$before_codegen (after)
1463   /// CHECK-DAG:      <<Arg:d\d+>>      ParameterValue
1464   /// CHECK-DAG:      <<Const13:i\d+>>  IntConstant 13
1465   /// CHECK-DAG:      <<Const54:i\d+>>  IntConstant 54
1466   /// CHECK-DAG:      <<Const42:d\d+>>  DoubleConstant 42
1467   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Arg>>,<<Const42>>]
1468   /// CHECK-DAG:      <<Select:i\d+>>   Select [<<Const13>>,<<Const54>>,<<LE>>]
1469   /// CHECK-DAG:                        Return [<<Select>>]
1470 
$noinline$doubleConditionEqualZero(double d)1471   public static int $noinline$doubleConditionEqualZero(double d) {
1472     if (doThrow) { throw new Error(); }
1473     return ((d > 42.0) != false) ? 13 : 54;
1474   }
1475 
1476   /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (before)
1477   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1478   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1479   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1480   /// CHECK-DAG:                        Return [<<Int>>]
1481 
1482   /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
1483   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1484   /// CHECK-DAG:                        Return [<<Arg>>]
1485 
1486   /// CHECK-START: int Main.$noinline$intToDoubleToInt(int) instruction_simplifier (after)
1487   /// CHECK-NOT:                        TypeConversion
1488 
$noinline$intToDoubleToInt(int value)1489   public static int $noinline$intToDoubleToInt(int value) {
1490     if (doThrow) { throw new Error(); }
1491     // Lossless conversion followed by a conversion back.
1492     return (int) (double) value;
1493   }
1494 
1495   /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (before)
1496   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1497   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1498   /// CHECK-DAG:      {{i\d+}}          TypeConversion [<<Double>>]
1499 
1500   /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
1501   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1502   /// CHECK-DAG:      {{d\d+}}          TypeConversion [<<Arg>>]
1503 
1504   /// CHECK-START: java.lang.String Main.$noinline$intToDoubleToIntPrint(int) instruction_simplifier (after)
1505   /// CHECK-DAG:                        TypeConversion
1506   /// CHECK-NOT:                        TypeConversion
1507 
$noinline$intToDoubleToIntPrint(int value)1508   public static String $noinline$intToDoubleToIntPrint(int value) {
1509     if (doThrow) { throw new Error(); }
1510     // Lossless conversion followed by a conversion back
1511     // with another use of the intermediate result.
1512     double d = (double) value;
1513     int i = (int) d;
1514     return "d=" + d + ", i=" + i;
1515   }
1516 
1517   /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (before)
1518   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
1519   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1520   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1521   /// CHECK-DAG:                        Return [<<Int>>]
1522 
1523   /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
1524   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
1525   /// CHECK-DAG:                        Return [<<Arg>>]
1526 
1527   /// CHECK-START: int Main.$noinline$byteToDoubleToInt(byte) instruction_simplifier (after)
1528   /// CHECK-NOT:                        TypeConversion
1529 
$noinline$byteToDoubleToInt(byte value)1530   public static int $noinline$byteToDoubleToInt(byte value) {
1531     if (doThrow) { throw new Error(); }
1532     // Lossless conversion followed by another conversion, use implicit conversion.
1533     return (int) (double) value;
1534   }
1535 
1536   /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (before)
1537   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1538   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1539   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1540   /// CHECK-DAG:                        Return [<<Int>>]
1541 
1542   /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
1543   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1544   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1545   /// CHECK-DAG:                        Return [<<Int>>]
1546 
1547   /// CHECK-START: int Main.$noinline$floatToDoubleToInt(float) instruction_simplifier (after)
1548   /// CHECK-DAG:                        TypeConversion
1549   /// CHECK-NOT:                        TypeConversion
1550 
$noinline$floatToDoubleToInt(float value)1551   public static int $noinline$floatToDoubleToInt(float value) {
1552     if (doThrow) { throw new Error(); }
1553     // Lossless conversion followed by another conversion.
1554     return (int) (double) value;
1555   }
1556 
1557   /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (before)
1558   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1559   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1560   /// CHECK-DAG:      {{i\d+}}          TypeConversion [<<Double>>]
1561 
1562   /// CHECK-START: java.lang.String Main.$noinline$floatToDoubleToIntPrint(float) instruction_simplifier (after)
1563   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1564   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1565   /// CHECK-DAG:      {{i\d+}}          TypeConversion [<<Double>>]
1566 
$noinline$floatToDoubleToIntPrint(float value)1567   public static String $noinline$floatToDoubleToIntPrint(float value) {
1568     if (doThrow) { throw new Error(); }
1569     // Lossless conversion followed by another conversion with
1570     // an extra use of the intermediate result.
1571     double d = (double) value;
1572     int i = (int) d;
1573     return "d=" + d + ", i=" + i;
1574   }
1575 
1576   /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (before)
1577   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
1578   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1579   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1580   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Int>>]
1581   /// CHECK-DAG:                        Return [<<Short>>]
1582 
1583   /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
1584   /// CHECK-DAG:      <<Arg:b\d+>>      ParameterValue
1585   /// CHECK-DAG:                        Return [<<Arg>>]
1586 
1587   /// CHECK-START: short Main.$noinline$byteToDoubleToShort(byte) instruction_simplifier (after)
1588   /// CHECK-NOT:                        TypeConversion
1589 
$noinline$byteToDoubleToShort(byte value)1590   public static short $noinline$byteToDoubleToShort(byte value) {
1591     if (doThrow) { throw new Error(); }
1592     // Originally, this is byte->double->int->short. The first conversion is lossless,
1593     // so we merge this with the second one to byte->int which we omit as it's an implicit
1594     // conversion. Then we eliminate the resulting byte->short as an implicit conversion.
1595     return (short) (double) value;
1596   }
1597 
1598   /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (before)
1599   /// CHECK-DAG:      <<Arg:c\d+>>      ParameterValue
1600   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1601   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Double>>]
1602   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Int>>]
1603   /// CHECK-DAG:                        Return [<<Short>>]
1604 
1605   /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
1606   /// CHECK-DAG:      <<Arg:c\d+>>      ParameterValue
1607   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Arg>>]
1608   /// CHECK-DAG:                        Return [<<Short>>]
1609 
1610   /// CHECK-START: short Main.$noinline$charToDoubleToShort(char) instruction_simplifier (after)
1611   /// CHECK-DAG:                        TypeConversion
1612   /// CHECK-NOT:                        TypeConversion
1613 
$noinline$charToDoubleToShort(char value)1614   public static short $noinline$charToDoubleToShort(char value) {
1615     if (doThrow) { throw new Error(); }
1616     // Originally, this is char->double->int->short. The first conversion is lossless,
1617     // so we merge this with the second one to char->int which we omit as it's an implicit
1618     // conversion. Then we are left with the resulting char->short conversion.
1619     return (short) (double) value;
1620   }
1621 
1622   /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (before)
1623   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1624   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1625   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Int>>]
1626   /// CHECK-DAG:                        Return [<<Short>>]
1627 
1628   /// CHECK-START: short Main.$noinline$floatToIntToShort(float) instruction_simplifier (after)
1629   /// CHECK-DAG:      <<Arg:f\d+>>      ParameterValue
1630   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1631   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Int>>]
1632   /// CHECK-DAG:                        Return [<<Short>>]
1633 
$noinline$floatToIntToShort(float value)1634   public static short $noinline$floatToIntToShort(float value) {
1635     if (doThrow) { throw new Error(); }
1636     // Lossy FP to integral conversion followed by another conversion: no simplification.
1637     return (short) value;
1638   }
1639 
1640   /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (before)
1641   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1642   /// CHECK-DAG:      <<Float:f\d+>>    TypeConversion [<<Arg>>]
1643   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Float>>]
1644   /// CHECK-DAG:                        Return [<<Int>>]
1645 
1646   /// CHECK-START: int Main.$noinline$intToFloatToInt(int) instruction_simplifier (after)
1647   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1648   /// CHECK-DAG:      <<Float:f\d+>>    TypeConversion [<<Arg>>]
1649   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Float>>]
1650   /// CHECK-DAG:                        Return [<<Int>>]
1651 
$noinline$intToFloatToInt(int value)1652   public static int $noinline$intToFloatToInt(int value) {
1653     if (doThrow) { throw new Error(); }
1654     // Lossy integral to FP conversion followed another conversion: no simplification.
1655     return (int) (float) value;
1656   }
1657 
1658   /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (before)
1659   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1660   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1661   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Int>>]
1662   /// CHECK-DAG:                        Return [<<Double>>]
1663 
1664   /// CHECK-START: double Main.$noinline$longToIntToDouble(long) instruction_simplifier (after)
1665   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1666   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1667   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Int>>]
1668   /// CHECK-DAG:                        Return [<<Double>>]
1669 
$noinline$longToIntToDouble(long value)1670   public static double $noinline$longToIntToDouble(long value) {
1671     if (doThrow) { throw new Error(); }
1672     // Lossy long-to-int conversion followed an integral to FP conversion: no simplification.
1673     return (double) (int) value;
1674   }
1675 
1676   /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (before)
1677   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1678   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1679   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Int>>]
1680   /// CHECK-DAG:                        Return [<<Long>>]
1681 
1682   /// CHECK-START: long Main.$noinline$longToIntToLong(long) instruction_simplifier (after)
1683   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1684   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Arg>>]
1685   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Int>>]
1686   /// CHECK-DAG:                        Return [<<Long>>]
1687 
$noinline$longToIntToLong(long value)1688   public static long $noinline$longToIntToLong(long value) {
1689     if (doThrow) { throw new Error(); }
1690     // Lossy long-to-int conversion followed an int-to-long conversion: no simplification.
1691     return (long) (int) value;
1692   }
1693 
1694   /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (before)
1695   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1696   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1697   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<Char>>]
1698   /// CHECK-DAG:                        Return [<<Short>>]
1699 
1700   /// CHECK-START: short Main.$noinline$shortToCharToShort(short) instruction_simplifier (after)
1701   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1702   /// CHECK-DAG:                        Return [<<Arg>>]
1703 
$noinline$shortToCharToShort(short value)1704   public static short $noinline$shortToCharToShort(short value) {
1705     if (doThrow) { throw new Error(); }
1706     // Integral conversion followed by non-widening integral conversion to original type.
1707     return (short) (char) value;
1708   }
1709 
1710   /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (before)
1711   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1712   /// CHECK-DAG:      <<Long:j\d+>>     TypeConversion [<<Arg>>]
1713   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<Long>>]
1714   /// CHECK-DAG:                        Return [<<Int>>]
1715 
1716   /// CHECK-START: int Main.$noinline$shortToLongToInt(short) instruction_simplifier (after)
1717   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1718   /// CHECK-DAG:                        Return [<<Arg>>]
1719 
$noinline$shortToLongToInt(short value)1720   public static int $noinline$shortToLongToInt(short value) {
1721     if (doThrow) { throw new Error(); }
1722     // Integral conversion followed by non-widening integral conversion, use implicit conversion.
1723     return (int) (long) value;
1724   }
1725 
1726   /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (before)
1727   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1728   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1729   /// CHECK-DAG:      <<Byte:b\d+>>     TypeConversion [<<Char>>]
1730   /// CHECK-DAG:                        Return [<<Byte>>]
1731 
1732   /// CHECK-START: byte Main.$noinline$shortToCharToByte(short) instruction_simplifier (after)
1733   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1734   /// CHECK-DAG:      <<Byte:b\d+>>     TypeConversion [<<Arg>>]
1735   /// CHECK-DAG:                        Return [<<Byte>>]
1736 
$noinline$shortToCharToByte(short value)1737   public static byte $noinline$shortToCharToByte(short value) {
1738     if (doThrow) { throw new Error(); }
1739     // Integral conversion followed by non-widening integral conversion losing bits
1740     // from the original type. Simplify to use only one conversion.
1741     return (byte) (char) value;
1742   }
1743 
1744   /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (before)
1745   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1746   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1747   /// CHECK-DAG:      {{b\d+}}          TypeConversion [<<Char>>]
1748 
1749   /// CHECK-START: java.lang.String Main.$noinline$shortToCharToBytePrint(short) instruction_simplifier (after)
1750   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1751   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1752   /// CHECK-DAG:      {{b\d+}}          TypeConversion [<<Char>>]
1753 
$noinline$shortToCharToBytePrint(short value)1754   public static String $noinline$shortToCharToBytePrint(short value) {
1755     if (doThrow) { throw new Error(); }
1756     // Integral conversion followed by non-widening integral conversion losing bits
1757     // from the original type with an extra use of the intermediate result.
1758     char c = (char) value;
1759     byte b = (byte) c;
1760     return "c=" + ((int) c) + ", b=" + ((int) b);  // implicit conversions.
1761   }
1762 
1763   /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (before)
1764   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1765   /// CHECK-DAG:      <<Mask:j\d+>>     LongConstant 255
1766   /// CHECK-DAG:      <<And:j\d+>>      And [<<Mask>>,<<Arg>>]
1767   /// CHECK-DAG:      <<Int:i\d+>>      TypeConversion [<<And>>]
1768   /// CHECK-DAG:      <<Byte:b\d+>>     TypeConversion [<<Int>>]
1769   /// CHECK-DAG:                        Return [<<Byte>>]
1770 
1771   /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
1772   /// CHECK-DAG:      <<Arg:j\d+>>      ParameterValue
1773   /// CHECK-DAG:      <<Byte:b\d+>>     TypeConversion [<<Arg>>]
1774   /// CHECK-DAG:                        Return [<<Byte>>]
1775 
1776   /// CHECK-START: byte Main.$noinline$longAnd0xffToByte(long) instruction_simplifier (after)
1777   /// CHECK-NOT:                        And
1778 
$noinline$longAnd0xffToByte(long value)1779   public static byte $noinline$longAnd0xffToByte(long value) {
1780     if (doThrow) { throw new Error(); }
1781     return (byte) (value & 0xff);
1782   }
1783 
1784   /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (before)
1785   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1786   /// CHECK-DAG:      <<Mask:i\d+>>     IntConstant 131071
1787   /// CHECK-DAG:      <<And:i\d+>>      And [<<Mask>>,<<Arg>>]
1788   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<And>>]
1789   /// CHECK-DAG:                        Return [<<Char>>]
1790 
1791   /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
1792   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1793   /// CHECK-DAG:      <<Char:c\d+>>     TypeConversion [<<Arg>>]
1794   /// CHECK-DAG:                        Return [<<Char>>]
1795 
1796   /// CHECK-START: char Main.$noinline$intAnd0x1ffffToChar(int) instruction_simplifier (after)
1797   /// CHECK-NOT:                        And
1798 
$noinline$intAnd0x1ffffToChar(int value)1799   public static char $noinline$intAnd0x1ffffToChar(int value) {
1800     if (doThrow) { throw new Error(); }
1801     // Keeping all significant bits and one more.
1802     return (char) (value & 0x1ffff);
1803   }
1804 
1805   /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (before)
1806   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1807   /// CHECK-DAG:      <<Mask:i\d+>>     IntConstant 98303
1808   /// CHECK-DAG:      <<And:i\d+>>      And [<<Mask>>,<<Arg>>]
1809   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<And>>]
1810   /// CHECK-DAG:                        Return [<<Short>>]
1811 
1812   /// CHECK-START: short Main.$noinline$intAnd0x17fffToShort(int) instruction_simplifier (after)
1813   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1814   /// CHECK-DAG:      <<Mask:i\d+>>     IntConstant 98303
1815   /// CHECK-DAG:      <<And:i\d+>>      And [<<Mask>>,<<Arg>>]
1816   /// CHECK-DAG:      <<Short:s\d+>>    TypeConversion [<<And>>]
1817   /// CHECK-DAG:                        Return [<<Short>>]
1818 
$noinline$intAnd0x17fffToShort(int value)1819   public static short $noinline$intAnd0x17fffToShort(int value) {
1820     if (doThrow) { throw new Error(); }
1821     // No simplification: clearing a significant bit.
1822     return (short) (value & 0x17fff);
1823   }
1824 
1825   /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (before)
1826   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1827   /// CHECK-DAG:      <<Mask:i\d+>>     IntConstant 65535
1828   /// CHECK-DAG:      <<And:i\d+>>      And [<<Mask>>,<<Arg>>]
1829   /// CHECK-DAG:      <<Same:s\d+>>     TypeConversion [<<And>>]
1830   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Same>>]
1831   /// CHECK-DAG:                        Return [<<Double>>]
1832 
1833   /// CHECK-START: double Main.$noinline$shortAnd0xffffToShortToDouble(short) instruction_simplifier (after)
1834   /// CHECK-DAG:      <<Arg:s\d+>>      ParameterValue
1835   /// CHECK-DAG:      <<Double:d\d+>>   TypeConversion [<<Arg>>]
1836   /// CHECK-DAG:                        Return [<<Double>>]
1837 
$noinline$shortAnd0xffffToShortToDouble(short value)1838   public static double $noinline$shortAnd0xffffToShortToDouble(short value) {
1839     if (doThrow) { throw new Error(); }
1840     short same = (short) (value & 0xffff);
1841     return (double) same;
1842   }
1843 
1844   /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (before)
1845   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1846   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1847   /// CHECK-DAG:      <<LE:z\d+>>       LessThanOrEqual [<<Const42>>,<<Arg>>]
1848 
1849   /// CHECK-START: int Main.$noinline$intReverseCondition(int) instruction_simplifier (after)
1850   /// CHECK-DAG:      <<Arg:i\d+>>      ParameterValue
1851   /// CHECK-DAG:      <<Const42:i\d+>>  IntConstant 42
1852   /// CHECK-DAG:      <<GE:z\d+>>       GreaterThanOrEqual [<<Arg>>,<<Const42>>]
1853 
$noinline$intReverseCondition(int i)1854   public static int $noinline$intReverseCondition(int i) {
1855     if (doThrow) { throw new Error(); }
1856     return (42 > i) ? 13 : 54;
1857   }
1858 
1859   /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (before)
1860   /// CHECK-DAG:      <<Const42:d\d+>>  DoubleConstant 42
1861   /// CHECK-DAG:      <<Result:d\d+>>   InvokeStaticOrDirect
1862   /// CHECK-DAG:      <<CMP:i\d+>>      Compare [<<Const42>>,<<Result>>]
1863 
1864   /// CHECK-START: int Main.$noinline$intReverseConditionNaN(int) instruction_simplifier (after)
1865   /// CHECK-DAG:      <<Const42:d\d+>>  DoubleConstant 42
1866   /// CHECK-DAG:      <<Result:d\d+>>   InvokeStaticOrDirect
1867   /// CHECK-DAG:      <<EQ:z\d+>>       Equal [<<Result>>,<<Const42>>]
1868 
$noinline$intReverseConditionNaN(int i)1869   public static int $noinline$intReverseConditionNaN(int i) {
1870     if (doThrow) { throw new Error(); }
1871     return (42 != Math.sqrt(i)) ? 13 : 54;
1872   }
1873 
$noinline$runSmaliTest(String name, boolean input)1874   public static int $noinline$runSmaliTest(String name, boolean input) {
1875     if (doThrow) { throw new Error(); }
1876     try {
1877       Class<?> c = Class.forName("SmaliTests");
1878       Method m = c.getMethod(name, boolean.class);
1879       return (Integer) m.invoke(null, input);
1880     } catch (Exception ex) {
1881       throw new Error(ex);
1882     }
1883   }
1884 
$noinline$runSmaliTestConst(String name, int arg)1885   public static int $noinline$runSmaliTestConst(String name, int arg) {
1886     if (doThrow) { throw new Error(); }
1887     try {
1888       Class<?> c = Class.forName("SmaliTests");
1889       Method m = c.getMethod(name, int.class);
1890       return (Integer) m.invoke(null, arg);
1891     } catch (Exception ex) {
1892       throw new Error(ex);
1893     }
1894   }
1895 
1896   /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1897   /// CHECK:          <<Value:i\d+>>    ParameterValue
1898   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1899   /// CHECK-DAG:      <<Const31:i\d+>>  IntConstant 31
1900   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const31>>]
1901   /// CHECK-DAG:      <<Shl:i\d+>>      Shl [<<Value>>,<<And>>]
1902   /// CHECK-DAG:                        Return [<<Shl>>]
1903 
1904   /// CHECK-START: int Main.$noinline$intUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1905   /// CHECK:          <<Value:i\d+>>    ParameterValue
1906   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1907   /// CHECK-DAG:      <<Shl:i\d+>>      Shl [<<Value>>,<<Shift>>]
1908   /// CHECK-DAG:                        Return [<<Shl>>]
1909 
$noinline$intUnnecessaryShiftMasking(int value, int shift)1910   public static int $noinline$intUnnecessaryShiftMasking(int value, int shift) {
1911     if (doThrow) { throw new Error(); }
1912     return value << (shift & 31);
1913   }
1914 
1915   /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (before)
1916   /// CHECK:          <<Value:j\d+>>    ParameterValue
1917   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1918   /// CHECK-DAG:      <<Const63:i\d+>>  IntConstant 63
1919   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const63>>]
1920   /// CHECK-DAG:      <<Shr:j\d+>>      Shr [<<Value>>,<<And>>]
1921   /// CHECK-DAG:                        Return [<<Shr>>]
1922 
1923   /// CHECK-START: long Main.$noinline$longUnnecessaryShiftMasking(long, int) instruction_simplifier (after)
1924   /// CHECK:          <<Value:j\d+>>    ParameterValue
1925   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1926   /// CHECK-DAG:      <<Shr:j\d+>>      Shr [<<Value>>,<<Shift>>]
1927   /// CHECK-DAG:                        Return [<<Shr>>]
1928 
$noinline$longUnnecessaryShiftMasking(long value, int shift)1929   public static long $noinline$longUnnecessaryShiftMasking(long value, int shift) {
1930     if (doThrow) { throw new Error(); }
1931     return value >> (shift & 63);
1932   }
1933 
1934   /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (before)
1935   /// CHECK:          <<Value:i\d+>>    ParameterValue
1936   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1937   /// CHECK-DAG:      <<Const255:i\d+>> IntConstant 255
1938   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const255>>]
1939   /// CHECK-DAG:      <<UShr:i\d+>>     UShr [<<Value>>,<<And>>]
1940   /// CHECK-DAG:                        Return [<<UShr>>]
1941 
1942   /// CHECK-START: int Main.$noinline$intUnnecessaryWiderShiftMasking(int, int) instruction_simplifier (after)
1943   /// CHECK:          <<Value:i\d+>>    ParameterValue
1944   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1945   /// CHECK-DAG:      <<UShr:i\d+>>     UShr [<<Value>>,<<Shift>>]
1946   /// CHECK-DAG:                        Return [<<UShr>>]
1947 
$noinline$intUnnecessaryWiderShiftMasking(int value, int shift)1948   public static int $noinline$intUnnecessaryWiderShiftMasking(int value, int shift) {
1949     if (doThrow) { throw new Error(); }
1950     return value >>> (shift & 0xff);
1951   }
1952 
1953   /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (before)
1954   /// CHECK:          <<Value:j\d+>>    ParameterValue
1955   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1956   /// CHECK-DAG:      <<Const3:i\d+>>   IntConstant 3
1957   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const3>>]
1958   /// CHECK-DAG:      <<Shl:j\d+>>      Shl [<<Value>>,<<And>>]
1959   /// CHECK-DAG:                        Return [<<Shl>>]
1960 
1961   /// CHECK-START: long Main.$noinline$longSmallerShiftMasking(long, int) instruction_simplifier (after)
1962   /// CHECK:          <<Value:j\d+>>    ParameterValue
1963   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1964   /// CHECK-DAG:      <<Const3:i\d+>>   IntConstant 3
1965   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const3>>]
1966   /// CHECK-DAG:      <<Shl:j\d+>>      Shl [<<Value>>,<<And>>]
1967   /// CHECK-DAG:                        Return [<<Shl>>]
1968 
$noinline$longSmallerShiftMasking(long value, int shift)1969   public static long $noinline$longSmallerShiftMasking(long value, int shift) {
1970     if (doThrow) { throw new Error(); }
1971     return value << (shift & 3);
1972   }
1973 
1974   /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (before)
1975   /// CHECK:          <<Value:i\d+>>    ParameterValue
1976   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1977   /// CHECK-DAG:      <<Const31:i\d+>>  IntConstant 31
1978   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const31>>]
1979   /// CHECK-DAG:      <<Shr:i\d+>>      Shr [<<Value>>,<<And>>]
1980   /// CHECK-DAG:      <<Add:i\d+>>      Add [<<Shr>>,<<And>>]
1981   /// CHECK-DAG:                        Return [<<Add>>]
1982 
1983   /// CHECK-START: int Main.$noinline$otherUseOfUnnecessaryShiftMasking(int, int) instruction_simplifier (after)
1984   /// CHECK:          <<Value:i\d+>>    ParameterValue
1985   /// CHECK:          <<Shift:i\d+>>    ParameterValue
1986   /// CHECK-DAG:      <<Const31:i\d+>>  IntConstant 31
1987   /// CHECK-DAG:      <<And:i\d+>>      And [<<Shift>>,<<Const31>>]
1988   /// CHECK-DAG:      <<Shr:i\d+>>      Shr [<<Value>>,<<Shift>>]
1989   /// CHECK-DAG:      <<Add:i\d+>>      Add [<<Shr>>,<<And>>]
1990   /// CHECK-DAG:                        Return [<<Add>>]
1991 
$noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift)1992   public static int $noinline$otherUseOfUnnecessaryShiftMasking(int value, int shift) {
1993     if (doThrow) { throw new Error(); }
1994     int temp = shift & 31;
1995     return (value >> temp) + temp;
1996   }
1997 
1998   /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (before)
1999   /// CHECK:          <<X:i\d+>>        ParameterValue
2000   /// CHECK:          <<Y:i\d+>>        ParameterValue
2001   /// CHECK-DAG:      <<Sum:i\d+>>      Add [<<X>>,<<Y>>]
2002   /// CHECK-DAG:      <<Res:i\d+>>      Sub [<<Sum>>,<<X>>]
2003   /// CHECK-DAG:                        Return [<<Res>>]
2004 
2005   /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg1(int, int) instruction_simplifier (after)
2006   /// CHECK:          <<X:i\d+>>        ParameterValue
2007   /// CHECK:          <<Y:i\d+>>        ParameterValue
2008   /// CHECK-DAG:      <<Sum:i\d+>>      Add [<<X>>,<<Y>>]
2009   /// CHECK-DAG:                        Return [<<Y>>]
2010 
$noinline$intAddSubSimplifyArg1(int x, int y)2011   public static int $noinline$intAddSubSimplifyArg1(int x, int y) {
2012     if (doThrow) { throw new Error(); }
2013     int sum = x + y;
2014     return sum - x;
2015   }
2016 
2017   /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (before)
2018   /// CHECK:          <<X:i\d+>>        ParameterValue
2019   /// CHECK:          <<Y:i\d+>>        ParameterValue
2020   /// CHECK-DAG:      <<Sum:i\d+>>      Add [<<X>>,<<Y>>]
2021   /// CHECK-DAG:      <<Res:i\d+>>      Sub [<<Sum>>,<<Y>>]
2022   /// CHECK-DAG:                        Return [<<Res>>]
2023 
2024   /// CHECK-START: int Main.$noinline$intAddSubSimplifyArg2(int, int) instruction_simplifier (after)
2025   /// CHECK:          <<X:i\d+>>        ParameterValue
2026   /// CHECK:          <<Y:i\d+>>        ParameterValue
2027   /// CHECK-DAG:      <<Sum:i\d+>>      Add [<<X>>,<<Y>>]
2028   /// CHECK-DAG:                        Return [<<X>>]
2029 
$noinline$intAddSubSimplifyArg2(int x, int y)2030   public static int $noinline$intAddSubSimplifyArg2(int x, int y) {
2031     if (doThrow) { throw new Error(); }
2032     int sum = x + y;
2033     return sum - y;
2034   }
2035 
2036   /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (before)
2037   /// CHECK:          <<X:i\d+>>        ParameterValue
2038   /// CHECK:          <<Y:i\d+>>        ParameterValue
2039   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<X>>,<<Y>>]
2040   /// CHECK-DAG:      <<Res:i\d+>>      Add [<<Sub>>,<<Y>>]
2041   /// CHECK-DAG:                        Return [<<Res>>]
2042 
2043   /// CHECK-START: int Main.$noinline$intSubAddSimplifyLeft(int, int) instruction_simplifier (after)
2044   /// CHECK:          <<X:i\d+>>        ParameterValue
2045   /// CHECK:          <<Y:i\d+>>        ParameterValue
2046   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<X>>,<<Y>>]
2047   /// CHECK-DAG:                        Return [<<X>>]
2048 
$noinline$intSubAddSimplifyLeft(int x, int y)2049   public static int $noinline$intSubAddSimplifyLeft(int x, int y) {
2050     if (doThrow) { throw new Error(); }
2051     int sub = x - y;
2052     return sub + y;
2053   }
2054 
2055   /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (before)
2056   /// CHECK:          <<X:i\d+>>        ParameterValue
2057   /// CHECK:          <<Y:i\d+>>        ParameterValue
2058   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<X>>,<<Y>>]
2059   /// CHECK-DAG:      <<Res:i\d+>>      Add [<<Y>>,<<Sub>>]
2060   /// CHECK-DAG:                        Return [<<Res>>]
2061 
2062   /// CHECK-START: int Main.$noinline$intSubAddSimplifyRight(int, int) instruction_simplifier (after)
2063   /// CHECK:          <<X:i\d+>>        ParameterValue
2064   /// CHECK:          <<Y:i\d+>>        ParameterValue
2065   /// CHECK-DAG:      <<Sub:i\d+>>      Sub [<<X>>,<<Y>>]
2066   /// CHECK-DAG:                        Return [<<X>>]
2067 
$noinline$intSubAddSimplifyRight(int x, int y)2068   public static int $noinline$intSubAddSimplifyRight(int x, int y) {
2069     if (doThrow) { throw new Error(); }
2070     int sub = x - y;
2071     return y + sub;
2072   }
2073 
2074   /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (before)
2075   /// CHECK:          <<X:f\d+>>        ParameterValue
2076   /// CHECK:          <<Y:f\d+>>        ParameterValue
2077   /// CHECK-DAG:      <<Sum:f\d+>>      Add [<<X>>,<<Y>>]
2078   /// CHECK-DAG:      <<Res:f\d+>>      Sub [<<Sum>>,<<X>>]
2079   /// CHECK-DAG:                        Return [<<Res>>]
2080 
2081   /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg1(float, float) instruction_simplifier (after)
2082   /// CHECK:          <<X:f\d+>>        ParameterValue
2083   /// CHECK:          <<Y:f\d+>>        ParameterValue
2084   /// CHECK-DAG:      <<Sum:f\d+>>      Add [<<X>>,<<Y>>]
2085   /// CHECK-DAG:      <<Res:f\d+>>      Sub [<<Sum>>,<<X>>]
2086   /// CHECK-DAG:                        Return [<<Res>>]
2087 
$noinline$floatAddSubSimplifyArg1(float x, float y)2088   public static float $noinline$floatAddSubSimplifyArg1(float x, float y) {
2089     if (doThrow) { throw new Error(); }
2090     float sum = x + y;
2091     return sum - x;
2092   }
2093 
2094   /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (before)
2095   /// CHECK:          <<X:f\d+>>        ParameterValue
2096   /// CHECK:          <<Y:f\d+>>        ParameterValue
2097   /// CHECK-DAG:      <<Sum:f\d+>>      Add [<<X>>,<<Y>>]
2098   /// CHECK-DAG:      <<Res:f\d+>>      Sub [<<Sum>>,<<Y>>]
2099   /// CHECK-DAG:                        Return [<<Res>>]
2100 
2101   /// CHECK-START: float Main.$noinline$floatAddSubSimplifyArg2(float, float) instruction_simplifier (after)
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 
$noinline$floatAddSubSimplifyArg2(float x, float y)2108   public static float $noinline$floatAddSubSimplifyArg2(float x, float y) {
2109     if (doThrow) { throw new Error(); }
2110     float sum = x + y;
2111     return sum - y;
2112   }
2113 
2114   /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (before)
2115   /// CHECK:          <<X:f\d+>>        ParameterValue
2116   /// CHECK:          <<Y:f\d+>>        ParameterValue
2117   /// CHECK-DAG:      <<Sub:f\d+>>      Sub [<<X>>,<<Y>>]
2118   /// CHECK-DAG:      <<Res:f\d+>>      Add [<<Sub>>,<<Y>>]
2119   /// CHECK-DAG:                        Return [<<Res>>]
2120 
2121   /// CHECK-START: float Main.$noinline$floatSubAddSimplifyLeft(float, float) instruction_simplifier (after)
2122   /// CHECK:          <<X:f\d+>>        ParameterValue
2123   /// CHECK:          <<Y:f\d+>>        ParameterValue
2124   /// CHECK-DAG:      <<Sub:f\d+>>      Sub [<<X>>,<<Y>>]
2125   /// CHECK-DAG:      <<Res:f\d+>>      Add [<<Sub>>,<<Y>>]
2126   /// CHECK-DAG:                        Return [<<Res>>]
2127 
$noinline$floatSubAddSimplifyLeft(float x, float y)2128   public static float $noinline$floatSubAddSimplifyLeft(float x, float y) {
2129     if (doThrow) { throw new Error(); }
2130     float sub = x - y;
2131     return sub + y;
2132   }
2133 
2134   /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (before)
2135   /// CHECK:          <<X:f\d+>>        ParameterValue
2136   /// CHECK:          <<Y:f\d+>>        ParameterValue
2137   /// CHECK-DAG:      <<Sub:f\d+>>      Sub [<<X>>,<<Y>>]
2138   /// CHECK-DAG:      <<Res:f\d+>>      Add [<<Y>>,<<Sub>>]
2139   /// CHECK-DAG:                        Return [<<Res>>]
2140 
2141   /// CHECK-START: float Main.$noinline$floatSubAddSimplifyRight(float, float) instruction_simplifier (after)
2142   /// CHECK:          <<X:f\d+>>        ParameterValue
2143   /// CHECK:          <<Y:f\d+>>        ParameterValue
2144   /// CHECK-DAG:      <<Sub:f\d+>>      Sub [<<X>>,<<Y>>]
2145   /// CHECK-DAG:      <<Res:f\d+>>      Add [<<Y>>,<<Sub>>]
2146   /// CHECK-DAG:                        Return [<<Res>>]
2147 
$noinline$floatSubAddSimplifyRight(float x, float y)2148   public static float $noinline$floatSubAddSimplifyRight(float x, float y) {
2149     if (doThrow) { throw new Error(); }
2150     float sub = x - y;
2151     return y + sub;
2152   }
2153 
main(String[] args)2154  public static void main(String[] args) {
2155     int arg = 123456;
2156     float floatArg = 123456.125f;
2157 
2158     assertLongEquals(arg, $noinline$Add0(arg));
2159     assertIntEquals(5, $noinline$AddAddSubAddConst(1));
2160     assertIntEquals(arg, $noinline$AndAllOnes(arg));
2161     assertLongEquals(arg, $noinline$Div1(arg));
2162     assertIntEquals(-arg, $noinline$DivN1(arg));
2163     assertLongEquals(arg, $noinline$Mul1(arg));
2164     assertIntEquals(-arg, $noinline$MulN1(arg));
2165     assertLongEquals((128 * arg), $noinline$MulPowerOfTwo128(arg));
2166     assertLongEquals(2640, $noinline$MulMulMulConst(2));
2167     assertIntEquals(arg, $noinline$Or0(arg));
2168     assertLongEquals(arg, $noinline$OrSame(arg));
2169     assertIntEquals(arg, $noinline$Shl0(arg));
2170     assertLongEquals(arg, $noinline$Shr0(arg));
2171     assertLongEquals(arg, $noinline$Shr64(arg));
2172     assertLongEquals(arg, $noinline$Sub0(arg));
2173     assertIntEquals(-arg, $noinline$SubAliasNeg(arg));
2174     assertIntEquals(9, $noinline$SubAddConst1(2));
2175     assertIntEquals(-2, $noinline$SubAddConst2(3));
2176     assertLongEquals(3, $noinline$SubSubConst(4));
2177     assertLongEquals(arg, $noinline$UShr0(arg));
2178     assertIntEquals(arg, $noinline$Xor0(arg));
2179     assertIntEquals(~arg, $noinline$XorAllOnes(arg));
2180     assertIntEquals(-(arg + arg + 1), $noinline$AddNegs1(arg, arg + 1));
2181     assertIntEquals(-(arg + arg + 1), $noinline$AddNegs2(arg, arg + 1));
2182     assertLongEquals(-(2 * arg + 1), $noinline$AddNegs3(arg, arg + 1));
2183     assertLongEquals(1, $noinline$AddNeg1(arg, arg + 1));
2184     assertLongEquals(-1, $noinline$AddNeg2(arg, arg + 1));
2185     assertLongEquals(arg, $noinline$NegNeg1(arg));
2186     assertIntEquals(0, $noinline$NegNeg2(arg));
2187     assertLongEquals(arg, $noinline$NegNeg3(arg));
2188     assertIntEquals(1, $noinline$NegSub1(arg, arg + 1));
2189     assertIntEquals(1, $noinline$NegSub2(arg, arg + 1));
2190     assertLongEquals(arg, $noinline$NotNot1(arg));
2191     assertIntEquals(-1, $noinline$NotNot2(arg));
2192     assertIntEquals(-(arg + arg + 1), $noinline$SubNeg1(arg, arg + 1));
2193     assertIntEquals(-(arg + arg + 1), $noinline$SubNeg2(arg, arg + 1));
2194     assertLongEquals(-(2 * arg + 1), $noinline$SubNeg3(arg, arg + 1));
2195     assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2196     assertBooleanEquals(true, $noinline$EqualBoolVsIntConst(true));
2197     assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2198     assertBooleanEquals(false, $noinline$NotEqualBoolVsIntConst(false));
2199     assertBooleanEquals(true, $noinline$NotNotBool(true));
2200     assertBooleanEquals(false, $noinline$NotNotBool(false));
2201     assertFloatEquals(50.0f, $noinline$Div2(100.0f));
2202     assertDoubleEquals(75.0, $noinline$Div2(150.0));
2203     assertFloatEquals(-400.0f, $noinline$DivMP25(100.0f));
2204     assertDoubleEquals(-600.0, $noinline$DivMP25(150.0));
2205     assertIntEquals(0xc, $noinline$UShr28And15(0xc1234567));
2206     assertLongEquals(0xcL, $noinline$UShr60And15(0xc123456787654321L));
2207     assertIntEquals(0x4, $noinline$UShr28And7(0xc1234567));
2208     assertLongEquals(0x4L, $noinline$UShr60And7(0xc123456787654321L));
2209     assertIntEquals(0xc1, $noinline$Shr24And255(0xc1234567));
2210     assertLongEquals(0xc1L, $noinline$Shr56And255(0xc123456787654321L));
2211     assertIntEquals(0x41, $noinline$Shr24And127(0xc1234567));
2212     assertLongEquals(0x41L, $noinline$Shr56And127(0xc123456787654321L));
2213     assertIntEquals(0, $noinline$mulPow2Plus1(0));
2214     assertIntEquals(9, $noinline$mulPow2Plus1(1));
2215     assertIntEquals(18, $noinline$mulPow2Plus1(2));
2216     assertIntEquals(900, $noinline$mulPow2Plus1(100));
2217     assertIntEquals(111105, $noinline$mulPow2Plus1(12345));
2218     assertLongEquals(0, $noinline$mulPow2Minus1(0));
2219     assertLongEquals(31, $noinline$mulPow2Minus1(1));
2220     assertLongEquals(62, $noinline$mulPow2Minus1(2));
2221     assertLongEquals(3100, $noinline$mulPow2Minus1(100));
2222     assertLongEquals(382695, $noinline$mulPow2Minus1(12345));
2223 
2224     booleanField = false;
2225     assertIntEquals($noinline$booleanFieldNotEqualOne(), 54);
2226     assertIntEquals($noinline$booleanFieldEqualZero(), 54);
2227     booleanField = true;
2228     assertIntEquals(13, $noinline$booleanFieldNotEqualOne());
2229     assertIntEquals(13, $noinline$booleanFieldEqualZero());
2230     assertIntEquals(54, $noinline$intConditionNotEqualOne(6));
2231     assertIntEquals(13, $noinline$intConditionNotEqualOne(43));
2232     assertIntEquals(54, $noinline$intConditionEqualZero(6));
2233     assertIntEquals(13, $noinline$intConditionEqualZero(43));
2234     assertIntEquals(54, $noinline$floatConditionNotEqualOne(6.0f));
2235     assertIntEquals(13, $noinline$floatConditionNotEqualOne(43.0f));
2236     assertIntEquals(54, $noinline$doubleConditionEqualZero(6.0));
2237     assertIntEquals(13, $noinline$doubleConditionEqualZero(43.0));
2238 
2239     assertIntEquals(1234567, $noinline$intToDoubleToInt(1234567));
2240     assertIntEquals(Integer.MIN_VALUE, $noinline$intToDoubleToInt(Integer.MIN_VALUE));
2241     assertIntEquals(Integer.MAX_VALUE, $noinline$intToDoubleToInt(Integer.MAX_VALUE));
2242     assertStringEquals("d=7654321.0, i=7654321", $noinline$intToDoubleToIntPrint(7654321));
2243     assertIntEquals(12, $noinline$byteToDoubleToInt((byte) 12));
2244     assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToInt(Byte.MIN_VALUE));
2245     assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToInt(Byte.MAX_VALUE));
2246     assertIntEquals(11, $noinline$floatToDoubleToInt(11.3f));
2247     assertStringEquals("d=12.25, i=12", $noinline$floatToDoubleToIntPrint(12.25f));
2248     assertIntEquals(123, $noinline$byteToDoubleToShort((byte) 123));
2249     assertIntEquals(Byte.MIN_VALUE, $noinline$byteToDoubleToShort(Byte.MIN_VALUE));
2250     assertIntEquals(Byte.MAX_VALUE, $noinline$byteToDoubleToShort(Byte.MAX_VALUE));
2251     assertIntEquals(1234, $noinline$charToDoubleToShort((char) 1234));
2252     assertIntEquals(Character.MIN_VALUE, $noinline$charToDoubleToShort(Character.MIN_VALUE));
2253     assertIntEquals(/* sign-extended */ -1, $noinline$charToDoubleToShort(Character.MAX_VALUE));
2254     assertIntEquals(12345, $noinline$floatToIntToShort(12345.75f));
2255     assertIntEquals(Short.MAX_VALUE, $noinline$floatToIntToShort((float)(Short.MIN_VALUE - 1)));
2256     assertIntEquals(Short.MIN_VALUE, $noinline$floatToIntToShort((float)(Short.MAX_VALUE + 1)));
2257     assertIntEquals(-54321, $noinline$intToFloatToInt(-54321));
2258     assertDoubleEquals((double) 0x12345678, $noinline$longToIntToDouble(0x1234567812345678L));
2259     assertDoubleEquals(0.0, $noinline$longToIntToDouble(Long.MIN_VALUE));
2260     assertDoubleEquals(-1.0, $noinline$longToIntToDouble(Long.MAX_VALUE));
2261     assertLongEquals(0x0000000012345678L, $noinline$longToIntToLong(0x1234567812345678L));
2262     assertLongEquals(0xffffffff87654321L, $noinline$longToIntToLong(0x1234567887654321L));
2263     assertLongEquals(0L, $noinline$longToIntToLong(Long.MIN_VALUE));
2264     assertLongEquals(-1L, $noinline$longToIntToLong(Long.MAX_VALUE));
2265     assertIntEquals((short) -5678, $noinline$shortToCharToShort((short) -5678));
2266     assertIntEquals(Short.MIN_VALUE, $noinline$shortToCharToShort(Short.MIN_VALUE));
2267     assertIntEquals(Short.MAX_VALUE, $noinline$shortToCharToShort(Short.MAX_VALUE));
2268     assertIntEquals(5678, $noinline$shortToLongToInt((short) 5678));
2269     assertIntEquals(Short.MIN_VALUE, $noinline$shortToLongToInt(Short.MIN_VALUE));
2270     assertIntEquals(Short.MAX_VALUE, $noinline$shortToLongToInt(Short.MAX_VALUE));
2271     assertIntEquals(0x34, $noinline$shortToCharToByte((short) 0x1234));
2272     assertIntEquals(-0x10, $noinline$shortToCharToByte((short) 0x12f0));
2273     assertIntEquals(0, $noinline$shortToCharToByte(Short.MIN_VALUE));
2274     assertIntEquals(-1, $noinline$shortToCharToByte(Short.MAX_VALUE));
2275     assertStringEquals("c=1025, b=1", $noinline$shortToCharToBytePrint((short) 1025));
2276     assertStringEquals("c=1023, b=-1", $noinline$shortToCharToBytePrint((short) 1023));
2277     assertStringEquals("c=65535, b=-1", $noinline$shortToCharToBytePrint((short) -1));
2278 
2279     assertIntEquals(0x21, $noinline$longAnd0xffToByte(0x1234432112344321L));
2280     assertIntEquals(0, $noinline$longAnd0xffToByte(Long.MIN_VALUE));
2281     assertIntEquals(-1, $noinline$longAnd0xffToByte(Long.MAX_VALUE));
2282     assertIntEquals(0x1234, $noinline$intAnd0x1ffffToChar(0x43211234));
2283     assertIntEquals(0, $noinline$intAnd0x1ffffToChar(Integer.MIN_VALUE));
2284     assertIntEquals(Character.MAX_VALUE, $noinline$intAnd0x1ffffToChar(Integer.MAX_VALUE));
2285     assertIntEquals(0x4321, $noinline$intAnd0x17fffToShort(0x87654321));
2286     assertIntEquals(0x0888, $noinline$intAnd0x17fffToShort(0x88888888));
2287     assertIntEquals(0, $noinline$intAnd0x17fffToShort(Integer.MIN_VALUE));
2288     assertIntEquals(Short.MAX_VALUE, $noinline$intAnd0x17fffToShort(Integer.MAX_VALUE));
2289 
2290     assertDoubleEquals(0.0, $noinline$shortAnd0xffffToShortToDouble((short) 0));
2291     assertDoubleEquals(1.0, $noinline$shortAnd0xffffToShortToDouble((short) 1));
2292     assertDoubleEquals(-2.0, $noinline$shortAnd0xffffToShortToDouble((short) -2));
2293     assertDoubleEquals(12345.0, $noinline$shortAnd0xffffToShortToDouble((short) 12345));
2294     assertDoubleEquals((double)Short.MAX_VALUE,
2295                        $noinline$shortAnd0xffffToShortToDouble(Short.MAX_VALUE));
2296     assertDoubleEquals((double)Short.MIN_VALUE,
2297                        $noinline$shortAnd0xffffToShortToDouble(Short.MIN_VALUE));
2298 
2299     assertIntEquals(13, $noinline$intReverseCondition(41));
2300     assertIntEquals(13, $noinline$intReverseConditionNaN(-5));
2301 
2302     for (String condition : new String[] { "Equal", "NotEqual" }) {
2303       for (String constant : new String[] { "True", "False" }) {
2304         for (String side : new String[] { "Rhs", "Lhs" }) {
2305           String name = condition + constant + side;
2306           assertIntEquals(5, $noinline$runSmaliTest(name, true));
2307           assertIntEquals(3, $noinline$runSmaliTest(name, false));
2308         }
2309       }
2310     }
2311 
2312     assertIntEquals(0, $noinline$runSmaliTestConst("AddSubConst", 1));
2313     assertIntEquals(3, $noinline$runSmaliTestConst("SubAddConst", 2));
2314     assertIntEquals(-16, $noinline$runSmaliTestConst("SubSubConst1", 3));
2315     assertIntEquals(-5, $noinline$runSmaliTestConst("SubSubConst2", 4));
2316     assertIntEquals(26, $noinline$runSmaliTestConst("SubSubConst3", 5));
2317     assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3));
2318     assertIntEquals(0x5e6f7808, $noinline$intUnnecessaryShiftMasking(0xabcdef01, 3 + 32));
2319     assertLongEquals(0xffffffffffffeaf3L, $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50));
2320     assertLongEquals(0xffffffffffffeaf3L, $noinline$longUnnecessaryShiftMasking(0xabcdef0123456789L, 50 + 64));
2321     assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10));
2322     assertIntEquals(0x2af37b, $noinline$intUnnecessaryWiderShiftMasking(0xabcdef01, 10 + 128));
2323     assertLongEquals(0xaf37bc048d159e24L, $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2));
2324     assertLongEquals(0xaf37bc048d159e24L, $noinline$longSmallerShiftMasking(0xabcdef0123456789L, 2 + 256));
2325     assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13));
2326     assertIntEquals(0xfffd5e7c, $noinline$otherUseOfUnnecessaryShiftMasking(0xabcdef01, 13 + 512));
2327 
2328     assertIntEquals(654321, $noinline$intAddSubSimplifyArg1(arg, 654321));
2329     assertIntEquals(arg, $noinline$intAddSubSimplifyArg2(arg, 654321));
2330     assertIntEquals(arg, $noinline$intSubAddSimplifyLeft(arg, 654321));
2331     assertIntEquals(arg, $noinline$intSubAddSimplifyRight(arg, 654321));
2332     assertFloatEquals(654321.125f, $noinline$floatAddSubSimplifyArg1(floatArg, 654321.125f));
2333     assertFloatEquals(floatArg, $noinline$floatAddSubSimplifyArg2(floatArg, 654321.125f));
2334     assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyLeft(floatArg, 654321.125f));
2335     assertFloatEquals(floatArg, $noinline$floatSubAddSimplifyRight(floatArg, 654321.125f));
2336   }
2337 
$inline$true()2338   private static boolean $inline$true() { return true; }
$inline$false()2339   private static boolean $inline$false() { return false; }
2340 
2341   public static boolean booleanField;
2342 }
2343