1 ; REQUIRES: x86-registered-target
3 ; Test devirtualization requiring promotion of local targets.
5 ; Generate split module with summary for hybrid Thin/Regular LTO WPD.
6 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t1.o %s
7 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t2.o %p/Inputs/devirt2.ll
9 ; Check that we have module flag showing splitting enabled, and that we don't
10 ; generate summary information needed for index-based WPD.
11 ; RUN: llvm-modextract -b -n=0 %t2.o -o %t2.o.0
12 ; RUN: llvm-dis -o - %t2.o.0 | FileCheck %s --check-prefix=ENABLESPLITFLAG --implicit-check-not=vTableFuncs --implicit-check-not=typeidCompatibleVTable
13 ; RUN: llvm-modextract -b -n=1 %t2.o -o %t2.o.1
14 ; RUN: llvm-dis -o - %t2.o.1 | FileCheck %s --check-prefix=ENABLESPLITFLAG --implicit-check-not=vTableFuncs --implicit-check-not=typeidCompatibleVTable
15 ; ENABLESPLITFLAG: !{i32 1, !"EnableSplitLTOUnit", i32 1}
17 ; Generate unsplit module with summary for ThinLTO index-based WPD.
18 ; Force generation of the bitcode index so that we also test lazy metadata
19 ; loader handling of the type metadata.
20 ; RUN: opt -bitcode-mdindex-threshold=0 -thinlto-bc -o %t3.o %s
21 ; RUN: opt -bitcode-mdindex-threshold=0 -thinlto-bc -o %t4.o %p/Inputs/devirt2.ll
23 ; Check that we don't have module flag when splitting not enabled for ThinLTO,
24 ; and that we generate summary information needed for index-based WPD.
25 ; RUN: llvm-dis -o - %t4.o | FileCheck %s --check-prefix=NOENABLESPLITFLAG
26 ; NOENABLESPLITFLAG-DAG: !{i32 1, !"EnableSplitLTOUnit", i32 0}
27 ; NOENABLESPLITFLAG-DAG: [[An:\^[0-9]+]] = gv: (name: "_ZN1A1nEi"
28 ; NOENABLESPLITFLAG-DAG: [[Bf:\^[0-9]+]] = gv: (name: "_ZN1B1fEi"
29 ; NOENABLESPLITFLAG-DAG: [[Cf:\^[0-9]+]] = gv: (name: "_ZN1C1fEi"
30 ; NOENABLESPLITFLAG-DAG: [[Dm:\^[0-9]+]] = gv: (name: "_ZN1D1mEi"
31 ; NOENABLESPLITFLAG-DAG: [[B:\^[0-9]+]] = gv: (name: "_ZTV1B", {{.*}} vTableFuncs: ((virtFunc: [[Bf]], offset: 16), (virtFunc: [[An]], offset: 24)), refs: ([[Bf]], [[An]])
32 ; NOENABLESPLITFLAG-DAG: [[C:\^[0-9]+]] = gv: (name: "_ZTV1C", {{.*}} vTableFuncs: ((virtFunc: [[Cf]], offset: 16), (virtFunc: [[An]], offset: 24)), refs: ([[An]], [[Cf]])
33 ; NOENABLESPLITFLAG-DAG: [[D:\^[0-9]+]] = gv: (name: "_ZTV1D", {{.*}} vTableFuncs: ((virtFunc: [[Dm]], offset: 16)), refs: ([[Dm]])
34 ; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS1A", summary: ((offset: 16, [[B]]), (offset: 16, [[C]])))
35 ; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS1B", summary: ((offset: 16, [[B]])))
36 ; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS1C", summary: ((offset: 16, [[C]])))
37 ; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS1D", summary: ((offset: 16, [[D]])))
39 ; Legacy PM, Index based WPD
40 ; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -pass-remarks=. \
41 ; RUN: -whole-program-visibility \
42 ; RUN: -wholeprogramdevirt-print-index-based \
44 ; RUN: -r=%t3.o,test,px \
45 ; RUN: -r=%t3.o,_ZTV1B, \
46 ; RUN: -r=%t3.o,_ZTV1C, \
47 ; RUN: -r=%t3.o,_ZTV1D, \
48 ; RUN: -r=%t3.o,_ZN1D1mEi, \
49 ; RUN: -r=%t3.o,test2, \
50 ; RUN: -r=%t4.o,_ZN1B1fEi,p \
51 ; RUN: -r=%t4.o,_ZN1C1fEi,p \
52 ; RUN: -r=%t4.o,_ZN1D1mEi,p \
53 ; RUN: -r=%t4.o,test2,px \
54 ; RUN: -r=%t4.o,_ZTV1B,px \
55 ; RUN: -r=%t4.o,_ZTV1C,px \
56 ; RUN: -r=%t4.o,_ZTV1D,px \
57 ; RUN: -r=%t4.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT
58 ; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1
59 ; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2
60 ; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-INDEX1
61 ; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-INDEX2
63 ; New PM, Index based WPD
64 ; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -use-new-pm -pass-remarks=. \
65 ; RUN: -whole-program-visibility \
66 ; RUN: -wholeprogramdevirt-print-index-based \
68 ; RUN: -r=%t3.o,test,px \
69 ; RUN: -r=%t3.o,_ZTV1B, \
70 ; RUN: -r=%t3.o,_ZTV1C, \
71 ; RUN: -r=%t3.o,_ZTV1D, \
72 ; RUN: -r=%t3.o,_ZN1D1mEi, \
73 ; RUN: -r=%t3.o,test2, \
74 ; RUN: -r=%t4.o,_ZN1B1fEi,p \
75 ; RUN: -r=%t4.o,_ZN1C1fEi,p \
76 ; RUN: -r=%t4.o,_ZN1D1mEi,p \
77 ; RUN: -r=%t4.o,test2,px \
78 ; RUN: -r=%t4.o,_ZTV1B,px \
79 ; RUN: -r=%t4.o,_ZTV1C,px \
80 ; RUN: -r=%t4.o,_ZTV1D,px \
81 ; RUN: -r=%t4.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT
82 ; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1
83 ; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2
84 ; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-INDEX1
85 ; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-INDEX2
87 ; NM-INDEX1-DAG: U _ZN1A1nEi.llvm.
88 ; NM-INDEX1-DAG: U _ZN1E1mEi.llvm.
89 ; NM-INDEX1-DAG: U _ZN1D1mEi
91 ; NM-INDEX2-DAG: T _ZN1A1nEi.llvm.
92 ; NM-INDEX2-DAG: T _ZN1E1mEi.llvm.
93 ; NM-INDEX2-DAG: W _ZN1D1mEi
94 ; NM-INDEX2-DAG: t _ZN1B1fEi
95 ; NM-INDEX2-DAG: t _ZN1C1fEi
97 ; Index based WPD, distributed backends
98 ; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -use-new-pm \
99 ; RUN: -whole-program-visibility \
100 ; RUN: -thinlto-distributed-indexes -wholeprogramdevirt-print-index-based \
102 ; RUN: -r=%t3.o,test,px \
103 ; RUN: -r=%t3.o,_ZTV1B, \
104 ; RUN: -r=%t3.o,_ZTV1C, \
105 ; RUN: -r=%t3.o,_ZTV1D, \
106 ; RUN: -r=%t3.o,_ZN1D1mEi, \
107 ; RUN: -r=%t3.o,test2, \
108 ; RUN: -r=%t4.o,_ZN1B1fEi,p \
109 ; RUN: -r=%t4.o,_ZN1C1fEi,p \
110 ; RUN: -r=%t4.o,_ZN1D1mEi,p \
111 ; RUN: -r=%t4.o,test2,px \
112 ; RUN: -r=%t4.o,_ZTV1B,px \
113 ; RUN: -r=%t4.o,_ZTV1C,px \
114 ; RUN: -r=%t4.o,_ZTV1D,px \
115 ; RUN: -r=%t4.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=PRINT
117 ; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1A1nEi)
118 ; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1E1mEi)
119 ; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1D1mEi)
122 ; RUN: llvm-lto2 run %t1.o %t2.o -save-temps -pass-remarks=. \
123 ; RUN: -whole-program-visibility \
125 ; RUN: -r=%t1.o,test,px \
126 ; RUN: -r=%t1.o,_ZTV1B, \
127 ; RUN: -r=%t1.o,_ZTV1C, \
128 ; RUN: -r=%t1.o,_ZTV1D, \
129 ; RUN: -r=%t1.o,_ZTV1D, \
130 ; RUN: -r=%t1.o,_ZN1D1mEi, \
131 ; RUN: -r=%t1.o,_ZN1D1mEi, \
132 ; RUN: -r=%t1.o,test2, \
133 ; RUN: -r=%t2.o,_ZN1A1nEi,p \
134 ; RUN: -r=%t2.o,_ZN1A1nEi, \
135 ; RUN: -r=%t2.o,_ZN1B1fEi,p \
136 ; RUN: -r=%t2.o,_ZN1C1fEi,p \
137 ; RUN: -r=%t2.o,_ZN1D1mEi,p \
138 ; RUN: -r=%t2.o,_ZN1E1mEi,p \
139 ; RUN: -r=%t2.o,_ZN1E1mEi, \
140 ; RUN: -r=%t2.o,_ZTV1B, \
141 ; RUN: -r=%t2.o,_ZTV1C, \
142 ; RUN: -r=%t2.o,_ZTV1D, \
143 ; RUN: -r=%t2.o,_ZTV1E, \
144 ; RUN: -r=%t2.o,test2,px \
145 ; RUN: -r=%t2.o,_ZN1A1nEi, \
146 ; RUN: -r=%t2.o,_ZN1B1fEi, \
147 ; RUN: -r=%t2.o,_ZN1C1fEi, \
148 ; RUN: -r=%t2.o,_ZN1D1mEi, \
149 ; RUN: -r=%t2.o,_ZN1E1mEi, \
150 ; RUN: -r=%t2.o,_ZTV1B,px \
151 ; RUN: -r=%t2.o,_ZTV1C,px \
152 ; RUN: -r=%t2.o,_ZTV1D,px \
153 ; RUN: -r=%t2.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=REMARK
154 ; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1
155 ; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2
156 ; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-HYBRID1
157 ; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-HYBRID2
160 ; RUN: llvm-lto2 run %t1.o %t2.o -save-temps -use-new-pm -pass-remarks=. \
161 ; RUN: -whole-program-visibility \
163 ; RUN: -r=%t1.o,test,px \
164 ; RUN: -r=%t1.o,_ZTV1B, \
165 ; RUN: -r=%t1.o,_ZTV1C, \
166 ; RUN: -r=%t1.o,_ZTV1D, \
167 ; RUN: -r=%t1.o,_ZTV1D, \
168 ; RUN: -r=%t1.o,_ZN1D1mEi, \
169 ; RUN: -r=%t1.o,_ZN1D1mEi, \
170 ; RUN: -r=%t1.o,test2, \
171 ; RUN: -r=%t2.o,_ZN1A1nEi,p \
172 ; RUN: -r=%t2.o,_ZN1A1nEi, \
173 ; RUN: -r=%t2.o,_ZN1B1fEi,p \
174 ; RUN: -r=%t2.o,_ZN1C1fEi,p \
175 ; RUN: -r=%t2.o,_ZN1D1mEi,p \
176 ; RUN: -r=%t2.o,_ZN1E1mEi,p \
177 ; RUN: -r=%t2.o,_ZN1E1mEi, \
178 ; RUN: -r=%t2.o,_ZTV1B, \
179 ; RUN: -r=%t2.o,_ZTV1C, \
180 ; RUN: -r=%t2.o,_ZTV1D, \
181 ; RUN: -r=%t2.o,_ZTV1E, \
182 ; RUN: -r=%t2.o,test2,px \
183 ; RUN: -r=%t2.o,_ZN1A1nEi, \
184 ; RUN: -r=%t2.o,_ZN1B1fEi, \
185 ; RUN: -r=%t2.o,_ZN1C1fEi, \
186 ; RUN: -r=%t2.o,_ZN1D1mEi, \
187 ; RUN: -r=%t2.o,_ZN1E1mEi, \
188 ; RUN: -r=%t2.o,_ZTV1B,px \
189 ; RUN: -r=%t2.o,_ZTV1C,px \
190 ; RUN: -r=%t2.o,_ZTV1D,px \
191 ; RUN: -r=%t2.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=REMARK
192 ; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1
193 ; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2
194 ; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-HYBRID1
195 ; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-HYBRID2
197 ; NM-HYBRID1-DAG: U _ZN1A1nEi.{{[0-9a-f]*}}
198 ; NM-HYBRID1-DAG: U _ZN1E1mEi.{{[0-9a-f]*}}
199 ; NM-HYBRID1-DAG: U _ZN1D1mEi
201 ; NM-HYBRID2-DAG: T _ZN1A1nEi.{{[0-9a-f]*}}
202 ; NM-HYBRID2-DAG: T _ZN1E1mEi.{{[0-9a-f]*}}
203 ; NM-HYBRID2-DAG: W _ZN1D1mEi
204 ; NM-HYBRID2-DAG: T _ZN1B1fEi
205 ; NM-HYBRID2-DAG: T _ZN1C1fEi
207 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi
208 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi
209 ; We should devirt call to _ZN1E1mEi once in importing module and once
210 ; in original (exporting) module.
211 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1E1mEi
212 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1E1mEi
214 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
215 target triple = "x86_64-grtev4-linux-gnu"
217 %struct.A = type { i32 (...)** }
218 %struct.B = type { %struct.A }
219 %struct.C = type { %struct.A }
220 %struct.D = type { i32 (...)** }
221 %struct.E = type { i32 (...)** }
223 @_ZTV1B = external constant [4 x i8*]
224 @_ZTV1C = external constant [4 x i8*]
225 ;@_ZTV1D = external constant [3 x i8*]
226 @_ZTV1D = linkonce_odr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.D*, i32)* @_ZN1D1mEi to i8*)] }, !type !3
228 define linkonce_odr i32 @_ZN1D1mEi(%struct.D* %this, i32 %a) #0 {
232 ; CHECK-IR1-LABEL: define i32 @test
233 define i32 @test(%struct.A* %obj, %struct.D* %obj2, %struct.E* %obj3, i32 %a) {
235 %0 = bitcast %struct.A* %obj to i8***
236 %vtable = load i8**, i8*** %0
237 %1 = bitcast i8** %vtable to i8*
238 %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A")
239 call void @llvm.assume(i1 %p)
240 %fptrptr = getelementptr i8*, i8** %vtable, i32 1
241 %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)**
242 %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8
244 ; Check that the call was devirtualized. Ignore extra character before
245 ; symbol name which would happen if it was promoted during module
246 ; splitting for hybrid WPD.
247 ; CHECK-IR1: %call = tail call i32 bitcast (void ()* @{{.*}}_ZN1A1nEi
248 %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a)
250 %3 = bitcast i8** %vtable to i32 (%struct.A*, i32)**
251 %fptr22 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %3, align 8
253 ; We still have to call it as virtual.
254 ; CHECK-IR1: %call3 = tail call i32 %fptr22
255 %call3 = tail call i32 %fptr22(%struct.A* nonnull %obj, i32 %call)
257 %4 = bitcast %struct.D* %obj2 to i8***
258 %vtable2 = load i8**, i8*** %4
259 %5 = bitcast i8** %vtable2 to i8*
260 %p2 = call i1 @llvm.type.test(i8* %5, metadata !"_ZTS1D")
261 call void @llvm.assume(i1 %p2)
263 %6 = bitcast i8** %vtable2 to i32 (%struct.D*, i32)**
264 %fptr33 = load i32 (%struct.D*, i32)*, i32 (%struct.D*, i32)** %6, align 8
266 ; Check that the call was devirtualized.
267 ; CHECK-IR1: %call4 = tail call i32 @_ZN1D1mEi
268 %call4 = tail call i32 %fptr33(%struct.D* nonnull %obj2, i32 %call3)
270 %call5 = tail call i32 @test2(%struct.E* nonnull %obj3, i32 %call4)
273 ; CHECK-IR1-LABEL: ret i32
276 ; CHECK-IR2: define i32 @test2
277 ; CHECK-IR2-NEXT: entry:
278 ; Check that the call was devirtualized. Ignore extra character before
279 ; symbol name which would happen if it was promoted during module
280 ; splitting for hybrid WPD.
281 ; CHECK-IR2-NEXT: %call4 = tail call i32 @{{.*}}_ZN1E1mEi
283 declare i1 @llvm.type.test(i8*, metadata)
284 declare void @llvm.assume(i1)
285 declare i32 @test2(%struct.E* %obj, i32 %a)
287 attributes #0 = { noinline optnone }
289 !3 = !{i64 16, !"_ZTS1D"}