blob: f0fe1b172f4d945ae37382e6017bae9418f6b733 [file] [log] [blame]
David Brazdil46e2a392015-03-16 17:31:52 +00001/*
Roland Levillain6a92a032015-07-23 12:15:01 +01002 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
David Brazdil46e2a392015-03-16 17:31:52 +000016
17public class Main {
18
19 // Note #1: `javac` flips the conditions of If statements.
20 // Note #2: In the optimizing compiler, the first input of Phi is always
21 // the fall-through path, i.e. the false branch.
22
23 public static void assertBoolEquals(boolean expected, boolean result) {
24 if (expected != result) {
25 throw new Error("Expected: " + expected + ", found: " + result);
26 }
27 }
28
David Brazdil769c9e52015-04-27 13:54:09 +010029 public static void assertIntEquals(int expected, int result) {
30 if (expected != result) {
31 throw new Error("Expected: " + expected + ", found: " + result);
32 }
33 }
34
David Brazdil46e2a392015-03-16 17:31:52 +000035 /*
David Brazdil0d13fee2015-04-17 14:52:19 +010036 * Elementary test negating a boolean. Verifies that blocks are merged and
37 * empty branches removed.
David Brazdil46e2a392015-03-16 17:31:52 +000038 */
39
David Brazdil74eb1b22015-12-14 11:44:01 +000040 /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (before)
David Brazdila06d66a2015-05-28 11:14:54 +010041 /// CHECK-DAG: <<Param:z\d+>> ParameterValue
42 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
43 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
44 /// CHECK-DAG: If [<<Param>>]
David Brazdilf02c3cf2016-02-29 09:14:51 +000045 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const0>>,<<Const1>>]
David Brazdila06d66a2015-05-28 11:14:54 +010046 /// CHECK-DAG: Return [<<Phi>>]
David Brazdil46e2a392015-03-16 17:31:52 +000047
David Brazdil74eb1b22015-12-14 11:44:01 +000048 /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (before)
David Brazdila06d66a2015-05-28 11:14:54 +010049 /// CHECK: Goto
50 /// CHECK: Goto
51 /// CHECK: Goto
52 /// CHECK-NOT: Goto
David Brazdil46e2a392015-03-16 17:31:52 +000053
David Brazdil74eb1b22015-12-14 11:44:01 +000054 /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +010055 /// CHECK-DAG: <<Param:z\d+>> ParameterValue
56 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
David Brazdil74eb1b22015-12-14 11:44:01 +000057 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
58 /// CHECK-DAG: <<NotParam:i\d+>> Select [<<Const1>>,<<Const0>>,<<Param>>]
David Brazdila06d66a2015-05-28 11:14:54 +010059 /// CHECK-DAG: Return [<<NotParam>>]
David Brazdil46e2a392015-03-16 17:31:52 +000060
David Brazdil74eb1b22015-12-14 11:44:01 +000061 /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +010062 /// CHECK-NOT: If
63 /// CHECK-NOT: Phi
David Brazdil46e2a392015-03-16 17:31:52 +000064
David Brazdil74eb1b22015-12-14 11:44:01 +000065 /// CHECK-START: boolean Main.BooleanNot(boolean) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +010066 /// CHECK: Goto
67 /// CHECK-NOT: Goto
David Brazdil46e2a392015-03-16 17:31:52 +000068
69 public static boolean BooleanNot(boolean x) {
70 return !x;
71 }
72
73 /*
74 * Program which only delegates the condition, i.e. returns 1 when True
75 * and 0 when False.
76 */
77
David Brazdil74eb1b22015-12-14 11:44:01 +000078 /// CHECK-START: boolean Main.GreaterThan(int, int) select_generator (before)
David Brazdila06d66a2015-05-28 11:14:54 +010079 /// CHECK-DAG: <<ParamX:i\d+>> ParameterValue
80 /// CHECK-DAG: <<ParamY:i\d+>> ParameterValue
81 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
82 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
83 /// CHECK-DAG: <<Cond:z\d+>> GreaterThan [<<ParamX>>,<<ParamY>>]
84 /// CHECK-DAG: If [<<Cond>>]
85 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const0>>,<<Const1>>]
86 /// CHECK-DAG: Return [<<Phi>>]
David Brazdil46e2a392015-03-16 17:31:52 +000087
David Brazdil74eb1b22015-12-14 11:44:01 +000088 /// CHECK-START: boolean Main.GreaterThan(int, int) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +010089 /// CHECK-DAG: <<ParamX:i\d+>> ParameterValue
90 /// CHECK-DAG: <<ParamY:i\d+>> ParameterValue
91 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
92 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
93 /// CHECK-DAG: <<Cond:z\d+>> GreaterThan [<<ParamX>>,<<ParamY>>]
David Brazdil74eb1b22015-12-14 11:44:01 +000094 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const0>>,<<Const1>>,<<Cond>>]
95 /// CHECK-DAG: Return [<<Select>>]
David Brazdil46e2a392015-03-16 17:31:52 +000096
97 public static boolean GreaterThan(int x, int y) {
98 return (x <= y) ? false : true;
99 }
100
101 /*
102 * Program which negates a condition, i.e. returns 0 when True
103 * and 1 when False.
104 */
105
David Brazdil74eb1b22015-12-14 11:44:01 +0000106 /// CHECK-START: boolean Main.LessThan(int, int) select_generator (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100107 /// CHECK-DAG: <<ParamX:i\d+>> ParameterValue
108 /// CHECK-DAG: <<ParamY:i\d+>> ParameterValue
109 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
110 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
111 /// CHECK-DAG: <<Cond:z\d+>> GreaterThanOrEqual [<<ParamX>>,<<ParamY>>]
112 /// CHECK-DAG: If [<<Cond>>]
113 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>]
114 /// CHECK-DAG: Return [<<Phi>>]
David Brazdil46e2a392015-03-16 17:31:52 +0000115
David Brazdil74eb1b22015-12-14 11:44:01 +0000116 /// CHECK-START: boolean Main.LessThan(int, int) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100117 /// CHECK-DAG: <<ParamX:i\d+>> ParameterValue
118 /// CHECK-DAG: <<ParamY:i\d+>> ParameterValue
119 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
120 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
David Brazdil74eb1b22015-12-14 11:44:01 +0000121 /// CHECK-DAG: <<Cond:z\d+>> GreaterThanOrEqual [<<ParamX>>,<<ParamY>>]
122 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const1>>,<<Const0>>,<<Cond>>]
123 /// CHECK-DAG: Return [<<Select>>]
David Brazdil46e2a392015-03-16 17:31:52 +0000124
125 public static boolean LessThan(int x, int y) {
David Brazdilb2bd1c52015-03-25 11:17:37 +0000126 return (x < y) ? true : false;
David Brazdil46e2a392015-03-16 17:31:52 +0000127 }
128
129 /*
130 * Program which further uses negated conditions.
131 * Note that Phis are discovered retrospectively.
132 */
133
David Brazdil74eb1b22015-12-14 11:44:01 +0000134 /// CHECK-START: boolean Main.ValuesOrdered(int, int, int) select_generator (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100135 /// CHECK-DAG: <<ParamX:i\d+>> ParameterValue
136 /// CHECK-DAG: <<ParamY:i\d+>> ParameterValue
137 /// CHECK-DAG: <<ParamZ:i\d+>> ParameterValue
138 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
139 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
140 /// CHECK-DAG: <<CondXY:z\d+>> GreaterThan [<<ParamX>>,<<ParamY>>]
141 /// CHECK-DAG: If [<<CondXY>>]
142 /// CHECK-DAG: <<CondYZ:z\d+>> GreaterThan [<<ParamY>>,<<ParamZ>>]
143 /// CHECK-DAG: If [<<CondYZ>>]
144 /// CHECK-DAG: <<CondXYZ:z\d+>> NotEqual [<<PhiXY:i\d+>>,<<PhiYZ:i\d+>>]
145 /// CHECK-DAG: If [<<CondXYZ>>]
146 /// CHECK-DAG: Return [<<PhiXYZ:i\d+>>]
147 /// CHECK-DAG: <<PhiXY>> Phi [<<Const1>>,<<Const0>>]
148 /// CHECK-DAG: <<PhiYZ>> Phi [<<Const1>>,<<Const0>>]
149 /// CHECK-DAG: <<PhiXYZ>> Phi [<<Const1>>,<<Const0>>]
David Brazdil46e2a392015-03-16 17:31:52 +0000150
David Brazdil74eb1b22015-12-14 11:44:01 +0000151 /// CHECK-START: boolean Main.ValuesOrdered(int, int, int) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100152 /// CHECK-DAG: <<ParamX:i\d+>> ParameterValue
153 /// CHECK-DAG: <<ParamY:i\d+>> ParameterValue
154 /// CHECK-DAG: <<ParamZ:i\d+>> ParameterValue
David Brazdil74eb1b22015-12-14 11:44:01 +0000155 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
156 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
157 /// CHECK-DAG: <<CmpXY:z\d+>> GreaterThan [<<ParamX>>,<<ParamY>>]
158 /// CHECK-DAG: <<SelXY:i\d+>> Select [<<Const1>>,<<Const0>>,<<CmpXY>>]
159 /// CHECK-DAG: <<CmpYZ:z\d+>> GreaterThan [<<ParamY>>,<<ParamZ>>]
160 /// CHECK-DAG: <<SelYZ:i\d+>> Select [<<Const1>>,<<Const0>>,<<CmpYZ>>]
161 /// CHECK-DAG: <<CmpXYZ:z\d+>> NotEqual [<<SelXY>>,<<SelYZ>>]
162 /// CHECK-DAG: <<SelXYZ:i\d+>> Select [<<Const1>>,<<Const0>>,<<CmpXYZ>>]
163 /// CHECK-DAG: Return [<<SelXYZ>>]
David Brazdil46e2a392015-03-16 17:31:52 +0000164
165 public static boolean ValuesOrdered(int x, int y, int z) {
166 return (x <= y) == (y <= z);
167 }
168
David Brazdil74eb1b22015-12-14 11:44:01 +0000169 /// CHECK-START: int Main.NegatedCondition(boolean) select_generator (before)
David Brazdila06d66a2015-05-28 11:14:54 +0100170 /// CHECK-DAG: <<Param:z\d+>> ParameterValue
171 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
172 /// CHECK-DAG: <<Const43:i\d+>> IntConstant 43
173 /// CHECK-DAG: If [<<Param>>]
174 /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const42>>,<<Const43>>]
175 /// CHECK-DAG: Return [<<Phi>>]
David Brazdil769c9e52015-04-27 13:54:09 +0100176
David Brazdil74eb1b22015-12-14 11:44:01 +0000177 /// CHECK-START: int Main.NegatedCondition(boolean) select_generator (after)
178 /// CHECK-DAG: <<Param:z\d+>> ParameterValue
179 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
180 /// CHECK-DAG: <<Const43:i\d+>> IntConstant 43
181 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const43>>,<<Const42>>,<<Param>>]
182 /// CHECK-DAG: Return [<<Select>>]
David Brazdil769c9e52015-04-27 13:54:09 +0100183
David Brazdil74eb1b22015-12-14 11:44:01 +0000184 /// CHECK-START: int Main.NegatedCondition(boolean) select_generator (after)
David Brazdila06d66a2015-05-28 11:14:54 +0100185 /// CHECK-NOT: BooleanNot
David Brazdil769c9e52015-04-27 13:54:09 +0100186
187 public static int NegatedCondition(boolean x) {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000188 return (x != false) ? 42 : 43;
David Brazdil769c9e52015-04-27 13:54:09 +0100189 }
190
David Brazdil74eb1b22015-12-14 11:44:01 +0000191 /// CHECK-START: int Main.SimpleTrueBlock(boolean, int) select_generator (after)
192 /// CHECK-DAG: <<ParamX:z\d+>> ParameterValue
193 /// CHECK-DAG: <<ParamY:i\d+>> ParameterValue
194 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
195 /// CHECK-DAG: <<Const43:i\d+>> IntConstant 43
196 /// CHECK-DAG: <<Add:i\d+>> Add [<<ParamY>>,<<Const42>>]
197 /// CHECK-DAG: <<Select:i\d+>> Select [<<Const43>>,<<Add>>,<<ParamX>>]
198 /// CHECK-DAG: Return [<<Select>>]
199
200 /// CHECK-START: int Main.SimpleTrueBlock(boolean, int) select_generator (after)
201 /// CHECK-NOT: If
202
203 public static int SimpleTrueBlock(boolean x, int y) {
204 return x ? y + 42 : 43;
205 }
206
207 /// CHECK-START: int Main.SimpleFalseBlock(boolean, int) select_generator (after)
208 /// CHECK-DAG: <<ParamX:z\d+>> ParameterValue
209 /// CHECK-DAG: <<ParamY:i\d+>> ParameterValue
210 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
211 /// CHECK-DAG: <<Const43:i\d+>> IntConstant 43
212 /// CHECK-DAG: <<Add:i\d+>> Add [<<ParamY>>,<<Const43>>]
213 /// CHECK-DAG: <<Select:i\d+>> Select [<<Add>>,<<Const42>>,<<ParamX>>]
214 /// CHECK-DAG: Return [<<Select>>]
215
216 /// CHECK-START: int Main.SimpleFalseBlock(boolean, int) select_generator (after)
217 /// CHECK-NOT: If
218
219 public static int SimpleFalseBlock(boolean x, int y) {
220 return x ? 42 : y + 43;
221 }
222
223 /// CHECK-START: int Main.SimpleBothBlocks(boolean, int, int) select_generator (after)
224 /// CHECK-DAG: <<ParamX:z\d+>> ParameterValue
225 /// CHECK-DAG: <<ParamY:i\d+>> ParameterValue
226 /// CHECK-DAG: <<ParamZ:i\d+>> ParameterValue
227 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
228 /// CHECK-DAG: <<Const43:i\d+>> IntConstant 43
229 /// CHECK-DAG: <<AddTrue:i\d+>> Add [<<ParamY>>,<<Const42>>]
230 /// CHECK-DAG: <<AddFalse:i\d+>> Add [<<ParamZ>>,<<Const43>>]
231 /// CHECK-DAG: <<Select:i\d+>> Select [<<AddFalse>>,<<AddTrue>>,<<ParamX>>]
232 /// CHECK-DAG: Return [<<Select>>]
233
234 /// CHECK-START: int Main.SimpleBothBlocks(boolean, int, int) select_generator (after)
235 /// CHECK-NOT: If
236
237 public static int SimpleBothBlocks(boolean x, int y, int z) {
238 return x ? y + 42 : z + 43;
239 }
240
241 /// CHECK-START: int Main.ThreeBlocks(boolean, boolean) select_generator (after)
242 /// CHECK-DAG: <<ParamX:z\d+>> ParameterValue
243 /// CHECK-DAG: <<ParamY:z\d+>> ParameterValue
244 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
245 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
246 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
247 /// CHECK-DAG: <<Select23:i\d+>> Select [<<Const3>>,<<Const2>>,<<ParamY>>]
248 /// CHECK-DAG: <<Select123:i\d+>> Select [<<Select23>>,<<Const1>>,<<ParamX>>]
249 /// CHECK-DAG: Return [<<Select123>>]
250
251 public static int ThreeBlocks(boolean x, boolean y) {
David Brazdilf02c3cf2016-02-29 09:14:51 +0000252 return x ? 1 : (y ? 2 : 3);
David Brazdil74eb1b22015-12-14 11:44:01 +0000253 }
254
255 /// CHECK-START: int Main.MultiplePhis() select_generator (before)
256 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
257 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
258 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
259 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
260 /// CHECK-DAG: <<PhiX:i\d+>> Phi [<<Const0>>,<<Const13>>,<<Const42>>]
261 /// CHECK-DAG: <<PhiY:i\d+>> Phi [<<Const1>>,<<Add:i\d+>>,<<Add>>]
262 /// CHECK-DAG: <<Add>> Add [<<PhiY>>,<<Const1>>]
263 /// CHECK-DAG: <<Cond:z\d+>> LessThanOrEqual [<<Add>>,<<Const1>>]
264 /// CHECK-DAG: If [<<Cond>>]
265 /// CHECK-DAG: Return [<<PhiX>>]
266
267 /// CHECK-START: int Main.MultiplePhis() select_generator (after)
268 /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
269 /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
270 /// CHECK-DAG: <<Const13:i\d+>> IntConstant 13
271 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
272 /// CHECK-DAG: <<PhiX:i\d+>> Phi [<<Const0>>,<<Select:i\d+>>]
273 /// CHECK-DAG: <<PhiY:i\d+>> Phi [<<Const1>>,<<Add:i\d+>>]
274 /// CHECK-DAG: <<Add>> Add [<<PhiY>>,<<Const1>>]
275 /// CHECK-DAG: <<Cond:z\d+>> LessThanOrEqual [<<Add>>,<<Const1>>]
276 /// CHECK-DAG: <<Select>> Select [<<Const13>>,<<Const42>>,<<Cond>>]
277 /// CHECK-DAG: Return [<<PhiX>>]
278
279 public static int MultiplePhis() {
280 int x = 0;
281 int y = 1;
282 while (y++ < 10) {
283 if (y > 1) {
284 x = 13;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000285 continue;
David Brazdil74eb1b22015-12-14 11:44:01 +0000286 } else {
287 x = 42;
David Brazdilf02c3cf2016-02-29 09:14:51 +0000288 continue;
David Brazdil74eb1b22015-12-14 11:44:01 +0000289 }
290 }
291 return x;
292 }
293
294 /// CHECK-START: int Main.TrueBlockWithTooManyInstructions(boolean) select_generator (before)
295 /// CHECK-DAG: <<This:l\d+>> ParameterValue
296 /// CHECK-DAG: <<Cond:z\d+>> ParameterValue
297 /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2
298 /// CHECK-DAG: <<Const43:i\d+>> IntConstant 43
299 /// CHECK-DAG: If [<<Cond>>]
300 /// CHECK-DAG: <<Iget:i\d+>> InstanceFieldGet [<<This>>]
301 /// CHECK-DAG: <<Add:i\d+>> Add [<<Iget>>,<<Const2>>]
302 /// CHECK-DAG: Phi [<<Add>>,<<Const43>>]
303
304 /// CHECK-START: int Main.TrueBlockWithTooManyInstructions(boolean) select_generator (after)
305 /// CHECK-NOT: Select
306
307 public int TrueBlockWithTooManyInstructions(boolean x) {
308 return x ? (read_field + 2) : 43;
309 }
310
311 /// CHECK-START: int Main.FalseBlockWithTooManyInstructions(boolean) select_generator (before)
312 /// CHECK-DAG: <<This:l\d+>> ParameterValue
313 /// CHECK-DAG: <<Cond:z\d+>> ParameterValue
314 /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3
315 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
316 /// CHECK-DAG: If [<<Cond>>]
317 /// CHECK-DAG: <<Iget:i\d+>> InstanceFieldGet [<<This>>]
318 /// CHECK-DAG: <<Add:i\d+>> Add [<<Iget>>,<<Const3>>]
319 /// CHECK-DAG: Phi [<<Const42>>,<<Add>>]
320
321 /// CHECK-START: int Main.FalseBlockWithTooManyInstructions(boolean) select_generator (after)
322 /// CHECK-NOT: Select
323
324 public int FalseBlockWithTooManyInstructions(boolean x) {
325 return x ? 42 : (read_field + 3);
326 }
327
328 /// CHECK-START: int Main.TrueBlockWithSideEffects(boolean) select_generator (before)
329 /// CHECK-DAG: <<This:l\d+>> ParameterValue
330 /// CHECK-DAG: <<Cond:z\d+>> ParameterValue
331 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
332 /// CHECK-DAG: <<Const43:i\d+>> IntConstant 43
333 /// CHECK-DAG: If [<<Cond>>]
334 /// CHECK-DAG: InstanceFieldSet [<<This>>,<<Const42>>]
335 /// CHECK-DAG: Phi [<<Const42>>,<<Const43>>]
336
337 /// CHECK-START: int Main.TrueBlockWithSideEffects(boolean) select_generator (after)
338 /// CHECK-NOT: Select
339
340 public int TrueBlockWithSideEffects(boolean x) {
341 return x ? (write_field = 42) : 43;
342 }
343
344 /// CHECK-START: int Main.FalseBlockWithSideEffects(boolean) select_generator (before)
345 /// CHECK-DAG: <<This:l\d+>> ParameterValue
346 /// CHECK-DAG: <<Cond:z\d+>> ParameterValue
347 /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42
348 /// CHECK-DAG: <<Const43:i\d+>> IntConstant 43
349 /// CHECK-DAG: If [<<Cond>>]
350 /// CHECK-DAG: InstanceFieldSet [<<This>>,<<Const43>>]
351 /// CHECK-DAG: Phi [<<Const42>>,<<Const43>>]
352
353 /// CHECK-START: int Main.FalseBlockWithSideEffects(boolean) select_generator (after)
354 /// CHECK-NOT: Select
355
356 public int FalseBlockWithSideEffects(boolean x) {
357 return x ? 42 : (write_field = 43);
358 }
359
David Brazdil46e2a392015-03-16 17:31:52 +0000360 public static void main(String[] args) {
361 assertBoolEquals(false, BooleanNot(true));
362 assertBoolEquals(true, BooleanNot(false));
363 assertBoolEquals(true, GreaterThan(10, 5));
364 assertBoolEquals(false, GreaterThan(10, 10));
365 assertBoolEquals(false, GreaterThan(5, 10));
366 assertBoolEquals(true, LessThan(5, 10));
367 assertBoolEquals(false, LessThan(10, 10));
368 assertBoolEquals(false, LessThan(10, 5));
369 assertBoolEquals(true, ValuesOrdered(1, 3, 5));
370 assertBoolEquals(true, ValuesOrdered(5, 3, 1));
371 assertBoolEquals(false, ValuesOrdered(1, 3, 2));
372 assertBoolEquals(false, ValuesOrdered(2, 3, 1));
373 assertBoolEquals(true, ValuesOrdered(3, 3, 3));
374 assertBoolEquals(true, ValuesOrdered(3, 3, 5));
375 assertBoolEquals(false, ValuesOrdered(5, 5, 3));
David Brazdil769c9e52015-04-27 13:54:09 +0100376 assertIntEquals(42, NegatedCondition(true));
377 assertIntEquals(43, NegatedCondition(false));
David Brazdil74eb1b22015-12-14 11:44:01 +0000378 assertIntEquals(46, SimpleTrueBlock(true, 4));
379 assertIntEquals(43, SimpleTrueBlock(false, 4));
380 assertIntEquals(42, SimpleFalseBlock(true, 7));
381 assertIntEquals(50, SimpleFalseBlock(false, 7));
382 assertIntEquals(48, SimpleBothBlocks(true, 6, 2));
383 assertIntEquals(45, SimpleBothBlocks(false, 6, 2));
384 assertIntEquals(1, ThreeBlocks(true, true));
385 assertIntEquals(1, ThreeBlocks(true, false));
386 assertIntEquals(2, ThreeBlocks(false, true));
387 assertIntEquals(3, ThreeBlocks(false, false));
388 assertIntEquals(13, MultiplePhis());
389
390 Main m = new Main();
391 assertIntEquals(42, m.TrueBlockWithTooManyInstructions(true));
392 assertIntEquals(43, m.TrueBlockWithTooManyInstructions(false));
393 assertIntEquals(42, m.FalseBlockWithTooManyInstructions(true));
394 assertIntEquals(43, m.FalseBlockWithTooManyInstructions(false));
395 assertIntEquals(42, m.TrueBlockWithSideEffects(true));
396 assertIntEquals(43, m.TrueBlockWithSideEffects(false));
397 assertIntEquals(42, m.FalseBlockWithSideEffects(true));
398 assertIntEquals(43, m.FalseBlockWithSideEffects(false));
David Brazdil46e2a392015-03-16 17:31:52 +0000399 }
David Brazdil74eb1b22015-12-14 11:44:01 +0000400
401 // These need to be instance fields so as to not generate a LoadClass for iget/iput.
402 public int read_field = 40;
403 public int write_field = 42;
David Brazdil46e2a392015-03-16 17:31:52 +0000404}