blob: 5ab9571a0caadf21097d5c2f43c8fec0760b54c4 [file] [log] [blame]
Eric Christophercee313d2019-04-17 04:52:47 +00001; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
2
3target datalayout = "e-p:64:64"
4target triple = "x86_64-unknown-linux-gnu"
5
Peter Collingbourneef5cfc22019-07-22 18:50:45 +00006; CHECK: [[VT1DATA:@[^ ]*]] = private constant { [0 x i8], [4 x i8*], [5 x i8] } { [0 x i8] zeroinitializer, [4 x i8*] [i8* null, i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i32 (i8*)* @vf1i32 to i8*)], [5 x i8] c"\01\00\00\00\01" }, !type [[T8:![0-9]+]]
Eric Christophercee313d2019-04-17 04:52:47 +00007@vt1 = constant [4 x i8*] [
8i8* null,
9i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
10i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
11i8* bitcast (i32 (i8*)* @vf1i32 to i8*)
12], !type !1
13
Peter Collingbourneef5cfc22019-07-22 18:50:45 +000014; CHECK: [[VT2DATA:@[^ ]*]] = private constant { [0 x i8], [3 x i8*], [5 x i8] } { [0 x i8] zeroinitializer, [3 x i8*] [i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i32 (i8*)* @vf2i32 to i8*)], [5 x i8] c"\02\00\00\00\02" }, !type [[T0:![0-9]+]]
Eric Christophercee313d2019-04-17 04:52:47 +000015@vt2 = constant [3 x i8*] [
16i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
17i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
18i8* bitcast (i32 (i8*)* @vf2i32 to i8*)
19], !type !0
20
Peter Collingbourneef5cfc22019-07-22 18:50:45 +000021; CHECK: [[VT3DATA:@[^ ]*]] = private constant { [0 x i8], [4 x i8*], [5 x i8] } { [0 x i8] zeroinitializer, [4 x i8*] [i8* null, i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i32 (i8*)* @vf3i32 to i8*)], [5 x i8] c"\03\00\00\00\01" }, !type [[T8]]
Eric Christophercee313d2019-04-17 04:52:47 +000022@vt3 = constant [4 x i8*] [
23i8* null,
24i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
25i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
26i8* bitcast (i32 (i8*)* @vf3i32 to i8*)
27], !type !1
28
Peter Collingbourneef5cfc22019-07-22 18:50:45 +000029; CHECK: [[VT4DATA:@[^ ]*]] = private constant { [0 x i8], [3 x i8*], [5 x i8] } { [0 x i8] zeroinitializer, [3 x i8*] [i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i32 (i8*)* @vf4i32 to i8*)], [5 x i8] c"\04\00\00\00\02" }, !type [[T0]]
Eric Christophercee313d2019-04-17 04:52:47 +000030@vt4 = constant [3 x i8*] [
31i8* bitcast (i1 (i8*)* @vf1i1 to i8*),
32i8* bitcast (i1 (i8*)* @vf0i1 to i8*),
33i8* bitcast (i32 (i8*)* @vf4i32 to i8*)
34], !type !0
35
Peter Collingbourneef5cfc22019-07-22 18:50:45 +000036; CHECK: @vt1 = alias [4 x i8*], getelementptr inbounds ({ [0 x i8], [4 x i8*], [5 x i8] }, { [0 x i8], [4 x i8*], [5 x i8] }* [[VT1DATA]], i32 0, i32 1)
37; CHECK: @vt2 = alias [3 x i8*], getelementptr inbounds ({ [0 x i8], [3 x i8*], [5 x i8] }, { [0 x i8], [3 x i8*], [5 x i8] }* [[VT2DATA]], i32 0, i32 1)
38; CHECK: @vt3 = alias [4 x i8*], getelementptr inbounds ({ [0 x i8], [4 x i8*], [5 x i8] }, { [0 x i8], [4 x i8*], [5 x i8] }* [[VT3DATA]], i32 0, i32 1)
39; CHECK: @vt4 = alias [3 x i8*], getelementptr inbounds ({ [0 x i8], [3 x i8*], [5 x i8] }, { [0 x i8], [3 x i8*], [5 x i8] }* [[VT4DATA]], i32 0, i32 1)
Eric Christophercee313d2019-04-17 04:52:47 +000040
41define i1 @vf0i1(i8* %this) readnone {
42 ret i1 0
43}
44
45define i1 @vf1i1(i8* %this) readnone {
46 ret i1 1
47}
48
49define i32 @vf1i32(i8* %this) readnone {
50 ret i32 1
51}
52
53define i32 @vf2i32(i8* %this) readnone {
54 ret i32 2
55}
56
57define i32 @vf3i32(i8* %this) readnone {
58 ret i32 3
59}
60
61define i32 @vf4i32(i8* %this) readnone {
62 ret i32 4
63}
64
65; CHECK: define i1 @call1(
66define i1 @call1(i8* %obj) {
67 %vtableptr = bitcast i8* %obj to [3 x i8*]**
68 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
69 ; CHECK: {{.*}} = bitcast [3 x i8*]* {{.*}} to i8*
70 ; CHECK: [[VT1:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8*
71 %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
72 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
73 call void @llvm.assume(i1 %p)
74 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 0
75 %fptr = load i8*, i8** %fptrptr
76 %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
77 ; CHECK: [[VTGEP1:%[^ ]*]] = getelementptr i8, i8* [[VT1]], i32 28
78 ; CHECK: [[VTLOAD1:%[^ ]*]] = load i8, i8* [[VTGEP1]]
79 ; CHECK: [[VTAND1:%[^ ]*]] = and i8 [[VTLOAD1]], 2
80 ; CHECK: [[VTCMP1:%[^ ]*]] = icmp ne i8 [[VTAND1]], 0
81 %result = call i1 %fptr_casted(i8* %obj)
82 ; CHECK: ret i1 [[VTCMP1]]
83 ret i1 %result
84}
85
86; CHECK: define i1 @call2(
87define i1 @call2(i8* %obj) {
88 %vtableptr = bitcast i8* %obj to [3 x i8*]**
89 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
90 ; CHECK: {{.*}} = bitcast [3 x i8*]* {{.*}} to i8*
91 ; CHECK: [[VT2:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8*
92 %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
93 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
94 call void @llvm.assume(i1 %p)
95 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 1
96 %fptr = load i8*, i8** %fptrptr
97 %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
98 ; CHECK: [[VTGEP2:%[^ ]*]] = getelementptr i8, i8* [[VT2]], i32 28
99 ; CHECK: [[VTLOAD2:%[^ ]*]] = load i8, i8* [[VTGEP2]]
100 ; CHECK: [[VTAND2:%[^ ]*]] = and i8 [[VTLOAD2]], 1
101 ; CHECK: [[VTCMP2:%[^ ]*]] = icmp ne i8 [[VTAND2]], 0
102 %result = call i1 %fptr_casted(i8* %obj)
103 ; CHECK: ret i1 [[VTCMP2]]
104 ret i1 %result
105}
106
107; CHECK: define i32 @call3(
108define i32 @call3(i8* %obj) {
109 %vtableptr = bitcast i8* %obj to [3 x i8*]**
110 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
111 ; CHECK: {{.*}} = bitcast [3 x i8*]* {{.*}} to i8*
112 ; CHECK: [[VT3:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8*
113 %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
114 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
115 call void @llvm.assume(i1 %p)
116 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 2
117 %fptr = load i8*, i8** %fptrptr
118 %fptr_casted = bitcast i8* %fptr to i32 (i8*)*
119 ; CHECK: [[VTGEP3:%[^ ]*]] = getelementptr i8, i8* [[VT3]], i32 24
120 ; CHECK: [[VTBC3:%[^ ]*]] = bitcast i8* [[VTGEP3]] to i32*
121 ; CHECK: [[VTLOAD3:%[^ ]*]] = load i32, i32* [[VTBC3]]
122 %result = call i32 %fptr_casted(i8* %obj)
123 ; CHECK: ret i32 [[VTLOAD3]]
124 ret i32 %result
125}
126
127declare i1 @llvm.type.test(i8*, metadata)
128declare void @llvm.assume(i1)
129
130; CHECK: [[T8]] = !{i32 8, !"typeid"}
131; CHECK: [[T0]] = !{i32 0, !"typeid"}
132
133!0 = !{i32 0, !"typeid"}
134!1 = !{i32 8, !"typeid"}