blob: 91e8d4f9df8403292e9496bf9f9b2efc757d2524 [file] [log] [blame]
David Brazdil13b47182015-04-15 16:29:32 +01001/*
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
17public class Main {
18
19 public static void assertBoolEquals(boolean expected, boolean result) {
20 if (expected != result) {
21 throw new Error("Expected: " + expected + ", found: " + result);
22 }
23 }
24
25 /*
26 * Test that zero/one constants are accepted as boolean inputs.
27 */
28
29 // CHECK-START: boolean Main.TestIntAsBoolean() inliner (before)
30 // CHECK-DAG: [[Invoke:z\d+]] InvokeStaticOrDirect
31 // CHECK-DAG: BooleanNot [ [[Invoke]] ]
32
33 // CHECK-START: boolean Main.TestIntAsBoolean() inliner (after)
34 // CHECK-DAG: [[Const:i\d+]] IntConstant 1
35 // CHECK-DAG: BooleanNot [ [[Const]] ]
36
37 public static boolean InlineConst() {
38 return true;
39 }
40
41 public static boolean TestIntAsBoolean() {
42 return InlineConst() != true ? true : false;
43 }
44
45 /*
46 * Test that integer Phis are accepted as boolean inputs until we implement
47 * a suitable type analysis.
48 */
49
50 // CHECK-START: boolean Main.TestPhiAsBoolean(int) inliner (before)
51 // CHECK-DAG: [[Invoke:z\d+]] InvokeStaticOrDirect
52 // CHECK-DAG: BooleanNot [ [[Invoke]] ]
53
54 // CHECK-START: boolean Main.TestPhiAsBoolean(int) inliner (after)
55 // CHECK-DAG: [[Phi:i\d+]] Phi
56 // CHECK-DAG: BooleanNot [ [[Phi]] ]
57
58 public static boolean f1;
59 public static boolean f2;
60
61 public static boolean InlinePhi(int x) {
62 return (x == 42) ? f1 : f2;
63 }
64
65 public static boolean TestPhiAsBoolean(int x) {
66 return InlinePhi(x) != true ? true : false;
67 }
68
69 public static void main(String[] args) {
70 f1 = true;
71 f2 = false;
72 assertBoolEquals(true, TestPhiAsBoolean(0));
73 assertBoolEquals(false, TestPhiAsBoolean(42));
74 }
75}