xref: /aosp_15_r20/art/test/463-checker-boolean-simplifier/src-art/Main.java (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker import java.lang.reflect.Method;
18*795d594fSAndroid Build Coastguard Worker 
19*795d594fSAndroid Build Coastguard Worker public class Main {
20*795d594fSAndroid Build Coastguard Worker 
21*795d594fSAndroid Build Coastguard Worker   // Note #1: `javac` flips the conditions of If statements.
22*795d594fSAndroid Build Coastguard Worker   // Note #2: In the optimizing compiler, the first input of Phi is always
23*795d594fSAndroid Build Coastguard Worker   //          the fall-through path, i.e. the false branch.
24*795d594fSAndroid Build Coastguard Worker 
assertBoolEquals(boolean expected, boolean result)25*795d594fSAndroid Build Coastguard Worker   public static void assertBoolEquals(boolean expected, boolean result) {
26*795d594fSAndroid Build Coastguard Worker     if (expected != result) {
27*795d594fSAndroid Build Coastguard Worker       throw new Error("Expected: " + expected + ", found: " + result);
28*795d594fSAndroid Build Coastguard Worker     }
29*795d594fSAndroid Build Coastguard Worker   }
30*795d594fSAndroid Build Coastguard Worker 
assertIntEquals(int expected, int result)31*795d594fSAndroid Build Coastguard Worker   public static void assertIntEquals(int expected, int result) {
32*795d594fSAndroid Build Coastguard Worker     if (expected != result) {
33*795d594fSAndroid Build Coastguard Worker       throw new Error("Expected: " + expected + ", found: " + result);
34*795d594fSAndroid Build Coastguard Worker     }
35*795d594fSAndroid Build Coastguard Worker   }
36*795d594fSAndroid Build Coastguard Worker 
37*795d594fSAndroid Build Coastguard Worker   /*
38*795d594fSAndroid Build Coastguard Worker    * Program which only delegates the condition, i.e. returns 1 when True
39*795d594fSAndroid Build Coastguard Worker    * and 0 when False.
40*795d594fSAndroid Build Coastguard Worker    */
41*795d594fSAndroid Build Coastguard Worker 
42*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: boolean Main.GreaterThan(int, int) select_generator (before)
43*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamX:i\d+>>   ParameterValue
44*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamY:i\d+>>   ParameterValue
45*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
46*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
47*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Cond:z\d+>>     GreaterThan [<<ParamX>>,<<ParamY>>]
48*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                       If [<<Cond>>]
49*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Phi:i\d+>>      Phi [<<Const0>>,<<Const1>>]
50*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                       Return [<<Phi>>]
51*795d594fSAndroid Build Coastguard Worker 
52*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: boolean Main.GreaterThan(int, int) select_generator (after)
53*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamX:i\d+>>   ParameterValue
54*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamY:i\d+>>   ParameterValue
55*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
56*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
57*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Cond:z\d+>>     GreaterThan [<<ParamX>>,<<ParamY>>]
58*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Select:i\d+>>   Select [<<Const0>>,<<Const1>>,<<Cond>>]
59*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                       Return [<<Select>>]
60*795d594fSAndroid Build Coastguard Worker 
GreaterThan(int x, int y)61*795d594fSAndroid Build Coastguard Worker   public static boolean GreaterThan(int x, int y) {
62*795d594fSAndroid Build Coastguard Worker     return (x <= y) ? false : true;
63*795d594fSAndroid Build Coastguard Worker   }
64*795d594fSAndroid Build Coastguard Worker 
65*795d594fSAndroid Build Coastguard Worker   /*
66*795d594fSAndroid Build Coastguard Worker    * Program which negates a condition, i.e. returns 0 when True
67*795d594fSAndroid Build Coastguard Worker    * and 1 when False.
68*795d594fSAndroid Build Coastguard Worker    */
69*795d594fSAndroid Build Coastguard Worker 
70*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: boolean Main.LessThan(int, int) select_generator (before)
71*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamX:i\d+>>   ParameterValue
72*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamY:i\d+>>   ParameterValue
73*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
74*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
75*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Cond:z\d+>>     GreaterThanOrEqual [<<ParamX>>,<<ParamY>>]
76*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                       If [<<Cond>>]
77*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Phi:i\d+>>      Phi [<<Const1>>,<<Const0>>]
78*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                       Return [<<Phi>>]
79*795d594fSAndroid Build Coastguard Worker 
80*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: boolean Main.LessThan(int, int) select_generator (after)
81*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamX:i\d+>>   ParameterValue
82*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamY:i\d+>>   ParameterValue
83*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const0:i\d+>>   IntConstant 0
84*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const1:i\d+>>   IntConstant 1
85*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Cond:z\d+>>     GreaterThanOrEqual [<<ParamX>>,<<ParamY>>]
86*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Select:i\d+>>   Select [<<Const1>>,<<Const0>>,<<Cond>>]
87*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                       Return [<<Select>>]
88*795d594fSAndroid Build Coastguard Worker 
LessThan(int x, int y)89*795d594fSAndroid Build Coastguard Worker   public static boolean LessThan(int x, int y) {
90*795d594fSAndroid Build Coastguard Worker     return (x < y) ? true : false;
91*795d594fSAndroid Build Coastguard Worker   }
92*795d594fSAndroid Build Coastguard Worker 
93*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.SimpleTrueBlock(boolean, int) select_generator (after)
94*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamX:z\d+>>   ParameterValue
95*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamY:i\d+>>   ParameterValue
96*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const42:i\d+>>  IntConstant 42
97*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const43:i\d+>>  IntConstant 43
98*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<ParamY>>,<<Const42>>]
99*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Select:i\d+>>   Select [<<Const43>>,<<Add>>,<<ParamX>>]
100*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                       Return [<<Select>>]
101*795d594fSAndroid Build Coastguard Worker 
102*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.SimpleTrueBlock(boolean, int) select_generator (after)
103*795d594fSAndroid Build Coastguard Worker   /// CHECK-NOT:     If
104*795d594fSAndroid Build Coastguard Worker 
SimpleTrueBlock(boolean x, int y)105*795d594fSAndroid Build Coastguard Worker   public static int SimpleTrueBlock(boolean x, int y) {
106*795d594fSAndroid Build Coastguard Worker     return x ? y + 42 : 43;
107*795d594fSAndroid Build Coastguard Worker   }
108*795d594fSAndroid Build Coastguard Worker 
109*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.SimpleFalseBlock(boolean, int) select_generator (after)
110*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamX:z\d+>>   ParameterValue
111*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamY:i\d+>>   ParameterValue
112*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const42:i\d+>>  IntConstant 42
113*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const43:i\d+>>  IntConstant 43
114*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Add:i\d+>>      Add [<<ParamY>>,<<Const43>>]
115*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Select:i\d+>>   Select [<<Add>>,<<Const42>>,<<ParamX>>]
116*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                       Return [<<Select>>]
117*795d594fSAndroid Build Coastguard Worker 
118*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.SimpleFalseBlock(boolean, int) select_generator (after)
119*795d594fSAndroid Build Coastguard Worker   /// CHECK-NOT:     If
120*795d594fSAndroid Build Coastguard Worker 
SimpleFalseBlock(boolean x, int y)121*795d594fSAndroid Build Coastguard Worker   public static int SimpleFalseBlock(boolean x, int y) {
122*795d594fSAndroid Build Coastguard Worker     return x ? 42 : y + 43;
123*795d594fSAndroid Build Coastguard Worker   }
124*795d594fSAndroid Build Coastguard Worker 
125*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.SimpleBothBlocks(boolean, int, int) select_generator (after)
126*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamX:z\d+>>   ParameterValue
127*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamY:i\d+>>   ParameterValue
128*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamZ:i\d+>>   ParameterValue
129*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const42:i\d+>>  IntConstant 42
130*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const43:i\d+>>  IntConstant 43
131*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<AddTrue:i\d+>>  Add [<<ParamY>>,<<Const42>>]
132*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<AddFalse:i\d+>> Add [<<ParamZ>>,<<Const43>>]
133*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Select:i\d+>>   Select [<<AddFalse>>,<<AddTrue>>,<<ParamX>>]
134*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                       Return [<<Select>>]
135*795d594fSAndroid Build Coastguard Worker 
136*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.SimpleBothBlocks(boolean, int, int) select_generator (after)
137*795d594fSAndroid Build Coastguard Worker   /// CHECK-NOT:     If
138*795d594fSAndroid Build Coastguard Worker 
SimpleBothBlocks(boolean x, int y, int z)139*795d594fSAndroid Build Coastguard Worker   public static int SimpleBothBlocks(boolean x, int y, int z) {
140*795d594fSAndroid Build Coastguard Worker     return x ? y + 42 : z + 43;
141*795d594fSAndroid Build Coastguard Worker   }
142*795d594fSAndroid Build Coastguard Worker 
143*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.ThreeBlocks(boolean, boolean) select_generator (after)
144*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamX:z\d+>>    ParameterValue
145*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<ParamY:z\d+>>    ParameterValue
146*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const1:i\d+>>    IntConstant 1
147*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const2:i\d+>>    IntConstant 2
148*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const3:i\d+>>    IntConstant 3
149*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Select23:i\d+>>  Select [<<Const3>>,<<Const2>>,<<ParamY>>]
150*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Select123:i\d+>> Select [<<Select23>>,<<Const1>>,<<ParamX>>]
151*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                        Return [<<Select123>>]
152*795d594fSAndroid Build Coastguard Worker 
ThreeBlocks(boolean x, boolean y)153*795d594fSAndroid Build Coastguard Worker   public static int ThreeBlocks(boolean x, boolean y) {
154*795d594fSAndroid Build Coastguard Worker     if (x) {
155*795d594fSAndroid Build Coastguard Worker       return 1;
156*795d594fSAndroid Build Coastguard Worker     } else if (y) {
157*795d594fSAndroid Build Coastguard Worker       return 2;
158*795d594fSAndroid Build Coastguard Worker     } else {
159*795d594fSAndroid Build Coastguard Worker       return 3;
160*795d594fSAndroid Build Coastguard Worker     }
161*795d594fSAndroid Build Coastguard Worker   }
162*795d594fSAndroid Build Coastguard Worker 
163*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.TrueBlockWithTooManyInstructions(boolean) select_generator (before)
164*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<This:l\d+>>    ParameterValue
165*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Cond:z\d+>>    ParameterValue
166*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const2:i\d+>>  IntConstant 2
167*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const43:i\d+>> IntConstant 43
168*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      If [<<Cond>>]
169*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Iget:i\d+>>    InstanceFieldGet [<<This>>]
170*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Add:i\d+>>     Add [<<Iget>>,<<Const2>>]
171*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      Phi [<<Add>>,<<Const43>>]
172*795d594fSAndroid Build Coastguard Worker 
173*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.TrueBlockWithTooManyInstructions(boolean) select_generator (after)
174*795d594fSAndroid Build Coastguard Worker   /// CHECK-NOT:     Select
175*795d594fSAndroid Build Coastguard Worker 
TrueBlockWithTooManyInstructions(boolean x)176*795d594fSAndroid Build Coastguard Worker   public int TrueBlockWithTooManyInstructions(boolean x) {
177*795d594fSAndroid Build Coastguard Worker     return x ? (read_field + 2) : 43;
178*795d594fSAndroid Build Coastguard Worker   }
179*795d594fSAndroid Build Coastguard Worker 
180*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.FalseBlockWithTooManyInstructions(boolean) select_generator (before)
181*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<This:l\d+>>    ParameterValue
182*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Cond:z\d+>>    ParameterValue
183*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const3:i\d+>>  IntConstant 3
184*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const42:i\d+>> IntConstant 42
185*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      If [<<Cond>>]
186*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Iget:i\d+>>    InstanceFieldGet [<<This>>]
187*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Add:i\d+>>     Add [<<Iget>>,<<Const3>>]
188*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      Phi [<<Const42>>,<<Add>>]
189*795d594fSAndroid Build Coastguard Worker 
190*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.FalseBlockWithTooManyInstructions(boolean) select_generator (after)
191*795d594fSAndroid Build Coastguard Worker   /// CHECK-NOT:     Select
192*795d594fSAndroid Build Coastguard Worker 
FalseBlockWithTooManyInstructions(boolean x)193*795d594fSAndroid Build Coastguard Worker   public int FalseBlockWithTooManyInstructions(boolean x) {
194*795d594fSAndroid Build Coastguard Worker     return x ? 42 : (read_field + 3);
195*795d594fSAndroid Build Coastguard Worker   }
196*795d594fSAndroid Build Coastguard Worker 
197*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.TrueBlockWithSideEffects(boolean) select_generator (before)
198*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<This:l\d+>>    ParameterValue
199*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Cond:z\d+>>    ParameterValue
200*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const42:i\d+>> IntConstant 42
201*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const43:i\d+>> IntConstant 43
202*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      If [<<Cond>>]
203*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      InstanceFieldSet [<<This>>,<<Const42>>]
204*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      Phi [<<Const42>>,<<Const43>>]
205*795d594fSAndroid Build Coastguard Worker 
206*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.TrueBlockWithSideEffects(boolean) select_generator (after)
207*795d594fSAndroid Build Coastguard Worker   /// CHECK-NOT:     Select
208*795d594fSAndroid Build Coastguard Worker 
TrueBlockWithSideEffects(boolean x)209*795d594fSAndroid Build Coastguard Worker   public int TrueBlockWithSideEffects(boolean x) {
210*795d594fSAndroid Build Coastguard Worker     return x ? (write_field = 42) : 43;
211*795d594fSAndroid Build Coastguard Worker   }
212*795d594fSAndroid Build Coastguard Worker 
213*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.FalseBlockWithSideEffects(boolean) select_generator (before)
214*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<This:l\d+>>    ParameterValue
215*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Cond:z\d+>>    ParameterValue
216*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const42:i\d+>> IntConstant 42
217*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:     <<Const43:i\d+>> IntConstant 43
218*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      If [<<Cond>>]
219*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      InstanceFieldSet [<<This>>,<<Const43>>]
220*795d594fSAndroid Build Coastguard Worker   /// CHECK-DAG:                      Phi [<<Const42>>,<<Const43>>]
221*795d594fSAndroid Build Coastguard Worker 
222*795d594fSAndroid Build Coastguard Worker   /// CHECK-START: int Main.FalseBlockWithSideEffects(boolean) select_generator (after)
223*795d594fSAndroid Build Coastguard Worker   /// CHECK-NOT:     Select
224*795d594fSAndroid Build Coastguard Worker 
FalseBlockWithSideEffects(boolean x)225*795d594fSAndroid Build Coastguard Worker   public int FalseBlockWithSideEffects(boolean x) {
226*795d594fSAndroid Build Coastguard Worker     return x ? 42 : (write_field = 43);
227*795d594fSAndroid Build Coastguard Worker   }
228*795d594fSAndroid Build Coastguard Worker 
main(String[] args)229*795d594fSAndroid Build Coastguard Worker   public static void main(String[] args) throws Exception {
230*795d594fSAndroid Build Coastguard Worker     Class main2 = Class.forName("Main2");
231*795d594fSAndroid Build Coastguard Worker     Method booleanNot = main2.getMethod("BooleanNot", boolean.class);
232*795d594fSAndroid Build Coastguard Worker     Method valuesOrdered = main2.getMethod("ValuesOrdered", int.class, int.class, int.class);
233*795d594fSAndroid Build Coastguard Worker     Method negatedCondition = main2.getMethod("NegatedCondition", boolean.class);
234*795d594fSAndroid Build Coastguard Worker     Method multiplePhis = main2.getMethod("MultiplePhis");
235*795d594fSAndroid Build Coastguard Worker 
236*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(false, (boolean)booleanNot.invoke(null, true));
237*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(true, (boolean)booleanNot.invoke(null, false));
238*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(true, GreaterThan(10, 5));
239*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(false, GreaterThan(10, 10));
240*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(false, GreaterThan(5, 10));
241*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(true, LessThan(5, 10));
242*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(false, LessThan(10, 10));
243*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(false, LessThan(10, 5));
244*795d594fSAndroid Build Coastguard Worker 
245*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(true, (boolean)valuesOrdered.invoke(null, 1, 3, 5));
246*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(true, (boolean)valuesOrdered.invoke(null, 5, 3, 1));
247*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(false, (boolean)valuesOrdered.invoke(null, 1, 3, 2));
248*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(false, (boolean)valuesOrdered.invoke(null, 2, 3, 1));
249*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(true, (boolean)valuesOrdered.invoke(null, 3, 3, 3));
250*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(true, (boolean)valuesOrdered.invoke(null, 3, 3, 5));
251*795d594fSAndroid Build Coastguard Worker     assertBoolEquals(false, (boolean)valuesOrdered.invoke(null, 5, 5, 3));
252*795d594fSAndroid Build Coastguard Worker     assertIntEquals(42, (int)negatedCondition.invoke(null, true));
253*795d594fSAndroid Build Coastguard Worker     assertIntEquals(43, (int)negatedCondition.invoke(null, false));
254*795d594fSAndroid Build Coastguard Worker     assertIntEquals(46, SimpleTrueBlock(true, 4));
255*795d594fSAndroid Build Coastguard Worker     assertIntEquals(43, SimpleTrueBlock(false, 4));
256*795d594fSAndroid Build Coastguard Worker     assertIntEquals(42, SimpleFalseBlock(true, 7));
257*795d594fSAndroid Build Coastguard Worker     assertIntEquals(50, SimpleFalseBlock(false, 7));
258*795d594fSAndroid Build Coastguard Worker     assertIntEquals(48, SimpleBothBlocks(true, 6, 2));
259*795d594fSAndroid Build Coastguard Worker     assertIntEquals(45, SimpleBothBlocks(false, 6, 2));
260*795d594fSAndroid Build Coastguard Worker     assertIntEquals(1, ThreeBlocks(true, true));
261*795d594fSAndroid Build Coastguard Worker     assertIntEquals(1, ThreeBlocks(true, false));
262*795d594fSAndroid Build Coastguard Worker     assertIntEquals(2, ThreeBlocks(false, true));
263*795d594fSAndroid Build Coastguard Worker     assertIntEquals(3, ThreeBlocks(false, false));
264*795d594fSAndroid Build Coastguard Worker     assertIntEquals(13, (int)multiplePhis.invoke(null));
265*795d594fSAndroid Build Coastguard Worker 
266*795d594fSAndroid Build Coastguard Worker     Main m = new Main();
267*795d594fSAndroid Build Coastguard Worker     assertIntEquals(42, m.TrueBlockWithTooManyInstructions(true));
268*795d594fSAndroid Build Coastguard Worker     assertIntEquals(43, m.TrueBlockWithTooManyInstructions(false));
269*795d594fSAndroid Build Coastguard Worker     assertIntEquals(42, m.FalseBlockWithTooManyInstructions(true));
270*795d594fSAndroid Build Coastguard Worker     assertIntEquals(43, m.FalseBlockWithTooManyInstructions(false));
271*795d594fSAndroid Build Coastguard Worker     assertIntEquals(42, m.TrueBlockWithSideEffects(true));
272*795d594fSAndroid Build Coastguard Worker     assertIntEquals(43, m.TrueBlockWithSideEffects(false));
273*795d594fSAndroid Build Coastguard Worker     assertIntEquals(42, m.FalseBlockWithSideEffects(true));
274*795d594fSAndroid Build Coastguard Worker     assertIntEquals(43, m.FalseBlockWithSideEffects(false));
275*795d594fSAndroid Build Coastguard Worker   }
276*795d594fSAndroid Build Coastguard Worker 
277*795d594fSAndroid Build Coastguard Worker   // These need to be instance fields so as to not generate a LoadClass for iget/iput.
278*795d594fSAndroid Build Coastguard Worker   public int read_field = 40;
279*795d594fSAndroid Build Coastguard Worker   public int write_field = 42;
280*795d594fSAndroid Build Coastguard Worker }
281