1; RUN: opt -S -wholeprogramdevirt -whole-program-visibility -pass-remarks=wholeprogramdevirt %s 2>&1 | FileCheck %s
2; Skipping vf0i1 is identical to setting public LTO visibility. We don't devirtualize vf0i1 and all other
3; virtual call targets.
4; RUN: opt -S -wholeprogramdevirt -whole-program-visibility -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-skip=vf0i1 %s 2>&1 | FileCheck %s --check-prefix=SKIP
5; We have two set of call targets {vf0i1, vf1i1} and {vf1i32, vf2i32, vf3i32, vf4i32}.
6; The command below prevents both of them from devirtualization.
7; RUN: opt -S -wholeprogramdevirt -whole-program-visibility -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-skip=vf0i1,vf1i32 %s 2>&1 | FileCheck %s --check-prefix=SKIP-ALL
8; Check wildcard
9; RUN: opt -S -wholeprogramdevirt -whole-program-visibility -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-skip=vf?i1 %s 2>&1 | FileCheck %s --check-prefix=SKIP
10
11target datalayout = "e-p:64:64"
12target triple = "x86_64-unknown-linux-gnu"
13
14; CHECK: remark: <unknown>:0:0: virtual-const-prop-1-bit: devirtualized a call to vf0i1
15; CHECK: remark: <unknown>:0:0: virtual-const-prop-1-bit: devirtualized a call to vf1i1
16; CHECK: remark: <unknown>:0:0: virtual-const-prop: devirtualized a call to vf1i32
17; CHECK: remark: <unknown>:0:0: devirtualized vf0i1
18; CHECK: remark: <unknown>:0:0: devirtualized vf1i1
19; CHECK: remark: <unknown>:0:0: devirtualized vf1i32
20; CHECK: remark: <unknown>:0:0: devirtualized vf2i32
21; CHECK: remark: <unknown>:0:0: devirtualized vf3i32
22; CHECK: remark: <unknown>:0:0: devirtualized vf4i32
23; CHECK-NOT: devirtualized
24
25; SKIP: remark: <unknown>:0:0: virtual-const-prop: devirtualized a call to vf1i32
26; SKIP: remark: <unknown>:0:0: devirtualized vf1i32
27; SKIP: remark: <unknown>:0:0: devirtualized vf2i32
28; SKIP: remark: <unknown>:0:0: devirtualized vf3i32
29; SKIP: remark: <unknown>:0:0: devirtualized vf4i32
30; SKIP-NOT: devirtualized
31
32; SKIP-ALL-NOT: devirtualized
33
34; CHECK: [[VT1DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\01\00\00\00\02", [3 x i8*] [i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i32 (i8*)* @vf1i32 to i8*)], [0 x i8] zeroinitializer }, section "vt1sec", !type [[T8:![0-9]+]]
35@vt1 = constant [3 x i8*] [
36i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
37i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
38i8* bitcast (i32 (i8*)* @vf1i32 to i8*)
39], section "vt1sec", !type !0
40
41; CHECK: [[VT2DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\02\00\00\00\01", [3 x i8*] [i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i32 (i8*)* @vf2i32 to i8*)], [0 x i8] zeroinitializer }, !type [[T8]]
42@vt2 = constant [3 x i8*] [
43i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
44i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
45i8* bitcast (i32 (i8*)* @vf2i32 to i8*)
46], !type !0
47
48; CHECK: [[VT3DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\03\00\00\00\02", [3 x i8*] [i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i32 (i8*)* @vf3i32 to i8*)], [0 x i8] zeroinitializer }, !type [[T8]]
49@vt3 = constant [3 x i8*] [
50i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
51i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
52i8* bitcast (i32 (i8*)* @vf3i32 to i8*)
53], !type !0
54
55; CHECK: [[VT4DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\04\00\00\00\01", [3 x i8*] [i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i32 (i8*)* @vf4i32 to i8*)], [0 x i8] zeroinitializer }, !type [[T8]]
56@vt4 = constant [3 x i8*] [
57i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
58i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
59i8* bitcast (i32 (i8*)* @vf4i32 to i8*)
60], !type !0
61
62; CHECK: @vt5 = {{.*}}, !type [[T0:![0-9]+]]
63@vt5 = constant [3 x i8*] [
64i8* bitcast (void ()* @__cxa_pure_virtual to i8*),
65i8* bitcast (void ()* @__cxa_pure_virtual to i8*),
66i8* bitcast (void ()* @__cxa_pure_virtual to i8*)
67], !type !0
68
69; CHECK: @vt1 = alias [3 x i8*], getelementptr inbounds ({ [8 x i8], [3 x i8*], [0 x i8] }, { [8 x i8], [3 x i8*], [0 x i8] }* [[VT1DATA]], i32 0, i32 1)
70; CHECK: @vt2 = alias [3 x i8*], getelementptr inbounds ({ [8 x i8], [3 x i8*], [0 x i8] }, { [8 x i8], [3 x i8*], [0 x i8] }* [[VT2DATA]], i32 0, i32 1)
71; CHECK: @vt3 = alias [3 x i8*], getelementptr inbounds ({ [8 x i8], [3 x i8*], [0 x i8] }, { [8 x i8], [3 x i8*], [0 x i8] }* [[VT3DATA]], i32 0, i32 1)
72; CHECK: @vt4 = alias [3 x i8*], getelementptr inbounds ({ [8 x i8], [3 x i8*], [0 x i8] }, { [8 x i8], [3 x i8*], [0 x i8] }* [[VT4DATA]], i32 0, i32 1)
73
74define i1 @vf0i1(i8* %this) readnone {
75  ret i1 0
76}
77
78define i1 @vf1i1(i8* %this) readnone {
79  ret i1 1
80}
81
82define i32 @vf1i32(i8* %this) readnone {
83  ret i32 1
84}
85
86define i32 @vf2i32(i8* %this) readnone {
87  ret i32 2
88}
89
90define i32 @vf3i32(i8* %this) readnone {
91  ret i32 3
92}
93
94define i32 @vf4i32(i8* %this) readnone {
95  ret i32 4
96}
97
98; CHECK: define i1 @call1(
99define i1 @call1(i8* %obj) {
100  %vtableptr = bitcast i8* %obj to [3 x i8*]**
101  %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
102  ; CHECK: [[VT1:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8*
103  %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
104  %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 0, metadata !"typeid")
105  %fptr = extractvalue {i8*, i1} %pair, 0
106  %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
107  ; CHECK: [[VTGEP1:%[^ ]*]] = getelementptr i8, i8* [[VT1]], i32 -1
108  ; CHECK: [[VTLOAD1:%[^ ]*]] = load i8, i8* [[VTGEP1]]
109  ; CHECK: [[VTAND1:%[^ ]*]] = and i8 [[VTLOAD1]], 1
110  ; CHECK: [[VTCMP1:%[^ ]*]] = icmp ne i8 [[VTAND1]], 0
111  %result = call i1 %fptr_casted(i8* %obj)
112  ; CHECK: [[AND1:%[^ ]*]] = and i1 [[VTCMP1]], true
113  %p = extractvalue {i8*, i1} %pair, 1
114  %and = and i1 %result, %p
115  ; CHECK: ret i1 [[AND1]]
116  ret i1 %and
117}
118
119; CHECK: define i1 @call2(
120define i1 @call2(i8* %obj) {
121  %vtableptr = bitcast i8* %obj to [3 x i8*]**
122  %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
123  ; CHECK: [[VT2:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8*
124  %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
125  %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid")
126  %fptr = extractvalue {i8*, i1} %pair, 0
127  %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
128  ; CHECK: [[VTGEP2:%[^ ]*]] = getelementptr i8, i8* [[VT2]], i32 -1
129  ; CHECK: [[VTLOAD2:%[^ ]*]] = load i8, i8* [[VTGEP2]]
130  ; CHECK: [[VTAND2:%[^ ]*]] = and i8 [[VTLOAD2]], 2
131  ; CHECK: [[VTCMP2:%[^ ]*]] = icmp ne i8 [[VTAND2]], 0
132  %result = call i1 %fptr_casted(i8* %obj)
133  ; CHECK: [[AND2:%[^ ]*]] = and i1 [[VTCMP2]], true
134  %p = extractvalue {i8*, i1} %pair, 1
135  %and = and i1 %result, %p
136  ; CHECK: ret i1 [[AND2]]
137  ret i1 %and
138}
139
140; CHECK: define i32 @call3(
141define i32 @call3(i8* %obj) {
142  %vtableptr = bitcast i8* %obj to [3 x i8*]**
143  %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
144  ; CHECK: [[VT3:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8*
145  %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
146  %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 16, metadata !"typeid")
147  %fptr = extractvalue {i8*, i1} %pair, 0
148  %fptr_casted = bitcast i8* %fptr to i32 (i8*)*
149  ; CHECK: [[VTGEP3:%[^ ]*]] = getelementptr i8, i8* [[VT3]], i32 -5
150  ; CHECK: [[VTBC3:%[^ ]*]] = bitcast i8* [[VTGEP3]] to i32*
151  ; CHECK: [[VTLOAD3:%[^ ]*]] = load i32, i32* [[VTBC3]]
152  %result = call i32 %fptr_casted(i8* %obj)
153  ; CHECK: ret i32 [[VTLOAD3]]
154  ret i32 %result
155}
156
157declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata)
158declare void @llvm.assume(i1)
159declare void @__cxa_pure_virtual()
160
161; CHECK: [[T8]] = !{i32 8, !"typeid"}
162; CHECK: [[T0]] = !{i32 0, !"typeid"}
163
164!0 = !{i32 0, !"typeid"}
165