2 ;; Test that symbols defined in shared libraries prevent devirtualization.
4 ;; First check that we get devirtualization when the defs are in the
8 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
9 ; RUN: opt --thinlto-bc -o %t1a.o %s
10 ; RUN: opt --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll
11 ; RUN: ld.lld %t1a.o %t2a.o -o %t3a -save-temps --lto-whole-program-visibility \
12 ; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
13 ; RUN: llvm-dis %t1a.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
16 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
17 ; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s
18 ; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll
19 ; RUN: ld.lld %t1b.o %t2b.o -o %t3b -save-temps --lto-whole-program-visibility \
20 ; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
21 ; RUN: llvm-dis %t1b.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
24 ; RUN: opt -o %t1c.o %s
25 ; RUN: opt -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll
26 ; RUN: ld.lld %t1c.o %t2c.o -o %t3c -save-temps --lto-whole-program-visibility \
27 ; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK
28 ; RUN: llvm-dis %t3c.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
30 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi
32 ;; Check that WPD fails with when linking against a shared library
33 ;; containing the strong defs of the vtables.
34 ; RUN: ld.lld %t2c.o -o %t.so -shared
37 ; RUN: ld.lld %t1a.o %t.so -o %t4a --lto-whole-program-visibility \
38 ; RUN: -mllvm -pass-remarks=. 2>&1 | count 0
41 ; RUN: ld.lld %t1b.o %t.so -o %t4b --lto-whole-program-visibility \
42 ; RUN: -mllvm -pass-remarks=. 2>&1 | count 0
45 ; RUN: ld.lld %t1c.o %t.so -o %t4c --lto-whole-program-visibility \
46 ; RUN: -mllvm -pass-remarks=. 2>&1 | count 0
48 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
49 target triple = "x86_64-grtev4-linux-gnu"
51 %struct.A = type { ptr }
52 %struct.B = type { %struct.A }
54 @_ZTV1A = available_externally unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1A1fEi, ptr @_ZN1A1nEi] }, !type !0, !vcall_visibility !2
55 @_ZTV1B = linkonce_odr unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !2
57 ;; Prevent the vtables from being dead code eliminated.
58 @llvm.used = appending global [2 x ptr] [ ptr @_ZTV1A, ptr @_ZTV1B]
60 ; CHECK-IR-LABEL: define dso_local i32 @_start
61 define i32 @_start(ptr %obj, i32 %a) {
63 %vtable = load ptr, ptr %obj
64 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")
65 call void @llvm.assume(i1 %p)
66 %fptrptr = getelementptr ptr, ptr %vtable, i32 1
67 %fptr1 = load ptr, ptr %fptrptr, align 8
69 ;; Check that the call was devirtualized.
70 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
71 ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1
72 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)
76 ; CHECK-IR-LABEL: ret i32
79 declare i1 @llvm.type.test(ptr, metadata)
80 declare void @llvm.assume(i1)
82 define available_externally i32 @_ZN1A1fEi(ptr %this, i32 %a) #0 {
86 define available_externally i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {
90 define linkonce_odr i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {
94 ;; Make sure we don't inline or otherwise optimize out the direct calls.
95 attributes #0 = { noinline optnone }
97 !0 = !{i64 16, !"_ZTS1A"}
98 !1 = !{i64 16, !"_ZTS1B"}