blob: d2eff163a8405fe06e8af4532e987e1a4b8b14c3 [file] [log] [blame]
Ivan Krasin54746452016-07-12 02:38:37 +00001; RUN: opt -S -wholeprogramdevirt -pass-remarks=wholeprogramdevirt %s 2>&1 | FileCheck %s
Peter Collingbourne0312f612016-06-25 00:23:04 +00002
3target datalayout = "e-p:64:64"
4target triple = "x86_64-unknown-linux-gnu"
5
Ivan Krasin54746452016-07-12 02:38:37 +00006; CHECK: remark: <unknown>:0:0: devirtualized call
7; CHECK: remark: <unknown>:0:0: devirtualized call
8; CHECK: remark: <unknown>:0:0: devirtualized call
9; CHECK-NOT: devirtualized call
10
Peter Collingbourne0312f612016-06-25 00:23:04 +000011; CHECK: [[VT1DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\01\01\00\00\00", [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]+]]
12@vt1 = constant [3 x i8*] [
13i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
14i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
15i8* bitcast (i32 (i8*)* @vf1i32 to i8*)
16], section "vt1sec", !type !0
17
18; CHECK: [[VT2DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\02\02\00\00\00", [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]]
19@vt2 = constant [3 x i8*] [
20i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
21i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
22i8* bitcast (i32 (i8*)* @vf2i32 to i8*)
23], !type !0
24
25; CHECK: [[VT3DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\01\03\00\00\00", [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]]
26@vt3 = constant [3 x i8*] [
27i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
28i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
29i8* bitcast (i32 (i8*)* @vf3i32 to i8*)
30], !type !0
31
32; CHECK: [[VT4DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\02\04\00\00\00", [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]]
33@vt4 = constant [3 x i8*] [
34i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
35i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
36i8* bitcast (i32 (i8*)* @vf4i32 to i8*)
37], !type !0
38
39; CHECK: @vt5 = {{.*}}, !type [[T0:![0-9]+]]
40@vt5 = constant [3 x i8*] [
41i8* bitcast (void ()* @__cxa_pure_virtual to i8*),
42i8* bitcast (void ()* @__cxa_pure_virtual to i8*),
43i8* bitcast (void ()* @__cxa_pure_virtual to i8*)
44], !type !0
45
46; 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)
47; 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)
48; 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)
49; 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)
50
51define i1 @vf0i1(i8* %this) readnone {
52 ret i1 0
53}
54
55define i1 @vf1i1(i8* %this) readnone {
56 ret i1 1
57}
58
59define i32 @vf1i32(i8* %this) readnone {
60 ret i32 1
61}
62
63define i32 @vf2i32(i8* %this) readnone {
64 ret i32 2
65}
66
67define i32 @vf3i32(i8* %this) readnone {
68 ret i32 3
69}
70
71define i32 @vf4i32(i8* %this) readnone {
72 ret i32 4
73}
74
75; CHECK: define i1 @call1(
76define i1 @call1(i8* %obj) {
77 %vtableptr = bitcast i8* %obj to [3 x i8*]**
78 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
79 ; CHECK: [[VT1:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8*
80 %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
81 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 0, metadata !"typeid")
82 %fptr = extractvalue {i8*, i1} %pair, 0
83 %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
84 ; CHECK: [[VTGEP1:%[^ ]*]] = getelementptr i8, i8* [[VT1]], i64 -5
85 ; CHECK: [[VTLOAD1:%[^ ]*]] = load i8, i8* [[VTGEP1]]
86 ; CHECK: [[VTAND1:%[^ ]*]] = and i8 [[VTLOAD1]], 2
87 ; CHECK: [[VTCMP1:%[^ ]*]] = icmp ne i8 [[VTAND1]], 0
88 %result = call i1 %fptr_casted(i8* %obj)
89 ; CHECK: [[AND1:%[^ ]*]] = and i1 [[VTCMP1]], true
90 %p = extractvalue {i8*, i1} %pair, 1
91 %and = and i1 %result, %p
92 ; CHECK: ret i1 [[AND1]]
93 ret i1 %and
94}
95
96; CHECK: define i1 @call2(
97define i1 @call2(i8* %obj) {
98 %vtableptr = bitcast i8* %obj to [3 x i8*]**
99 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
100 ; CHECK: [[VT2:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8*
101 %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
102 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid")
103 %fptr = extractvalue {i8*, i1} %pair, 0
104 %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
105 ; CHECK: [[VTGEP2:%[^ ]*]] = getelementptr i8, i8* [[VT2]], i64 -5
106 ; CHECK: [[VTLOAD2:%[^ ]*]] = load i8, i8* [[VTGEP2]]
107 ; CHECK: [[VTAND2:%[^ ]*]] = and i8 [[VTLOAD2]], 1
108 ; CHECK: [[VTCMP2:%[^ ]*]] = icmp ne i8 [[VTAND2]], 0
109 %result = call i1 %fptr_casted(i8* %obj)
110 ; CHECK: [[AND2:%[^ ]*]] = and i1 [[VTCMP2]], true
111 %p = extractvalue {i8*, i1} %pair, 1
112 %and = and i1 %result, %p
113 ; CHECK: ret i1 [[AND2]]
114 ret i1 %and
115}
116
117; CHECK: define i32 @call3(
118define i32 @call3(i8* %obj) {
119 %vtableptr = bitcast i8* %obj to [3 x i8*]**
120 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
121 ; CHECK: [[VT3:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8*
122 %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
123 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 16, metadata !"typeid")
124 %fptr = extractvalue {i8*, i1} %pair, 0
125 %fptr_casted = bitcast i8* %fptr to i32 (i8*)*
126 ; CHECK: [[VTGEP3:%[^ ]*]] = getelementptr i8, i8* [[VT3]], i64 -4
127 ; CHECK: [[VTBC3:%[^ ]*]] = bitcast i8* [[VTGEP3]] to i32*
128 ; CHECK: [[VTLOAD3:%[^ ]*]] = load i32, i32* [[VTBC3]]
129 %result = call i32 %fptr_casted(i8* %obj)
130 ; CHECK: ret i32 [[VTLOAD3]]
131 ret i32 %result
132}
133
134declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata)
135declare void @llvm.assume(i1)
136declare void @__cxa_pure_virtual()
137
138; CHECK: [[T8]] = !{i32 8, !"typeid"}
139; CHECK: [[T0]] = !{i32 0, !"typeid"}
140
141!0 = !{i32 0, !"typeid"}