blob: b3181687134917450efe07a0397b101a9b7c6e51 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class Main {
/// CHECK-START: int Main.bar(Main) inliner (before)
/// CHECK: InvokeVirtual
/// CHECK: InvokeVirtual
/// CHECK-START: int Main.bar(Main) inliner (after)
/// CHECK-NOT: InvokeVirtual
public static int bar(Main m) {
if (m.getClass() == Main.class) {
return m.foo();
}
return 4;
}
public int foo() {
return 42;
}
/// CHECK-START: boolean Main.classEquality1() instruction_simplifier$after_inlining (before)
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
/// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
/// CHECK-DAG: <<Eq:z\d+>> {{Equal|NotEqual}}
/// CHECK-DAG: If [<<Eq>>]
/// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>]
/// CHECK-DAG: Return [<<Phi>>]
/// CHECK-START: boolean Main.classEquality1() dead_code_elimination$after_inlining (after)
/// CHECK-DAG: <<Constant:i\d+>> IntConstant 1
/// CHECK-DAG: Return [<<Constant>>]
public static boolean classEquality1() {
return new Main().getClass() == Main.class;
}
/// CHECK-START: boolean Main.classEquality2() instruction_simplifier$after_inlining (before)
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
/// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
/// CHECK-DAG: <<Eq:z\d+>> {{Equal|NotEqual}}
/// CHECK-DAG: If [<<Eq>>]
/// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>]
/// CHECK-DAG: Return [<<Phi>>]
/// CHECK-START: boolean Main.classEquality2() dead_code_elimination$after_inlining (after)
/// CHECK-DAG: <<Constant:i\d+>> IntConstant 0
/// CHECK-DAG: Return [<<Constant>>]
public static boolean classEquality2() {
Object o = new SubMain();
return o.getClass() == Main.class;
}
/// CHECK-START: boolean Main.classEquality3() instruction_simplifier$after_inlining (before)
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
/// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
/// CHECK-DAG: <<Eq:z\d+>> {{Equal|NotEqual}}
/// CHECK-DAG: If [<<Eq>>]
/// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>]
/// CHECK-DAG: Return [<<Phi>>]
/// CHECK-START: boolean Main.classEquality3() dead_code_elimination$after_inlining (after)
/// CHECK-DAG: <<Constant:i\d+>> IntConstant 0
/// CHECK-DAG: Return [<<Constant>>]
public static boolean classEquality3() {
return new Main().getClass() != Main.class;
}
/// CHECK-START: boolean Main.classEquality4() instruction_simplifier$after_inlining (before)
/// CHECK-DAG: <<Const0:i\d+>> IntConstant 0
/// CHECK-DAG: <<Const1:i\d+>> IntConstant 1
/// CHECK-DAG: <<Eq:z\d+>> {{Equal|NotEqual}}
/// CHECK-DAG: If [<<Eq>>]
/// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const1>>,<<Const0>>]
/// CHECK-DAG: Return [<<Phi>>]
/// CHECK-START: boolean Main.classEquality4() dead_code_elimination$after_inlining (after)
/// CHECK-DAG: <<Constant:i\d+>> IntConstant 1
/// CHECK-DAG: Return [<<Constant>>]
public static boolean classEquality4() {
Object o = new SubMain();
return o.getClass() != Main.class;
}
public static void main(String[] args) {
int actual = bar(new Main());
if (actual != 42) {
throw new Error("Expected 42, got " + actual);
}
actual = bar(new SubMain());
if (actual != 4) {
throw new Error("Expected 4, got " + actual);
}
}
}
class SubMain extends Main {
}
|