1 ;; Test that plugin option whole-program-visibility enables devirtualization.
4 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
5 ; RUN: opt -thinlto-bc -o %t2.o %s
6 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
7 ; RUN: --plugin-opt=whole-program-visibility \
8 ; RUN: --plugin-opt=save-temps \
9 ; RUN: --plugin-opt=-pass-remarks=. \
10 ; RUN: %t2.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK
11 ; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
14 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
15 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s
16 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
17 ; RUN: --plugin-opt=whole-program-visibility \
18 ; RUN: --plugin-opt=save-temps \
19 ; RUN: --plugin-opt=-pass-remarks=. \
20 ; RUN: %t.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK
21 ; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
24 ; RUN: opt -o %t4.o %s
25 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
26 ; RUN: --plugin-opt=whole-program-visibility \
27 ; RUN: --plugin-opt=save-temps \
28 ; RUN: --plugin-opt=-pass-remarks=. \
29 ; RUN: %t4.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK
30 ; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
32 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi
33 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi
35 ;; Try everything again but without -whole-program-visibility to confirm
39 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
40 ; RUN: --plugin-opt=save-temps \
41 ; RUN: --plugin-opt=-pass-remarks=. \
43 ; RUN: 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
44 ; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR
47 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
48 ; RUN: --plugin-opt=save-temps \
49 ; RUN: --plugin-opt=-pass-remarks=. \
51 ; RUN: 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
52 ; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR
55 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
56 ; RUN: --plugin-opt=save-temps \
57 ; RUN: --plugin-opt=-pass-remarks=. \
59 ; RUN: 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty
60 ; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR
62 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
63 target triple = "x86_64-grtev4-linux-gnu"
65 %struct.A = type { i32 (...)** }
66 %struct.B = type { %struct.A }
67 %struct.C = type { %struct.A }
68 %struct.D = type { i32 (...)** }
70 @_ZTV1B = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !1, !vcall_visibility !5
71 @_ZTV1C = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.C*, i32)* @_ZN1C1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !2, !vcall_visibility !5
72 @_ZTV1D = constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.D*, i32)* @_ZN1D1mEi to i8*)] }, !type !3, !vcall_visibility !5
74 ; Prevent the vtables from being dead code eliminated.
75 @llvm.used = appending global [3 x i8*] [ i8* bitcast ( { [4 x i8*] }* @_ZTV1B to i8*), i8* bitcast ( { [4 x i8*] }* @_ZTV1C to i8*), i8* bitcast ( { [3 x i8*] }* @_ZTV1D to i8*)]
77 ; CHECK-IR-LABEL: define dso_local i32 @_start
78 define i32 @_start(%struct.A* %obj, %struct.D* %obj2, i32 %a) {
80 %0 = bitcast %struct.A* %obj to i8***
81 %vtable = load i8**, i8*** %0
82 %1 = bitcast i8** %vtable to i8*
83 %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A")
84 call void @llvm.assume(i1 %p)
85 %fptrptr = getelementptr i8*, i8** %vtable, i32 1
86 %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)**
87 %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8
89 ;; Check that the call was devirtualized.
90 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
91 ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1
92 %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a)
94 %3 = bitcast i8** %vtable to i32 (%struct.A*, i32)**
95 %fptr22 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %3, align 8
97 ;; We still have to call it as virtual.
98 ; CHECK-IR: %call3 = tail call i32 %fptr22
99 ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr22
100 %call3 = tail call i32 %fptr22(%struct.A* nonnull %obj, i32 %call)
102 %4 = bitcast %struct.D* %obj2 to i8***
103 %vtable2 = load i8**, i8*** %4
104 %5 = bitcast i8** %vtable2 to i8*
105 %p2 = call i1 @llvm.type.test(i8* %5, metadata !4)
106 call void @llvm.assume(i1 %p2)
108 %6 = bitcast i8** %vtable2 to i32 (%struct.D*, i32)**
109 %fptr33 = load i32 (%struct.D*, i32)*, i32 (%struct.D*, i32)** %6, align 8
111 ;; Check that the call was devirtualized.
112 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi
113 ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33
114 %call4 = tail call i32 %fptr33(%struct.D* nonnull %obj2, i32 %call3)
117 ; CHECK-IR-LABEL: ret i32
120 declare i1 @llvm.type.test(i8*, metadata)
121 declare void @llvm.assume(i1)
123 define i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) #0 {
127 define i32 @_ZN1A1nEi(%struct.A* %this, i32 %a) #0 {
131 define i32 @_ZN1C1fEi(%struct.C* %this, i32 %a) #0 {
135 define i32 @_ZN1D1mEi(%struct.D* %this, i32 %a) #0 {
139 ;; Make sure we don't inline or otherwise optimize out the direct calls.
140 attributes #0 = { noinline optnone }
142 !0 = !{i64 16, !"_ZTS1A"}
143 !1 = !{i64 16, !"_ZTS1B"}
144 !2 = !{i64 16, !"_ZTS1C"}