Debian Codegraph @

llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll

raw
1 ;; Test that plugin option whole-program-visibility enables devirtualization.
2
3 ;; Index based WPD
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
12
13 ;; Hybrid WPD
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
22
23 ;; Regular LTO WPD
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
31
32 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi
33 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi
34
35 ;; Try everything again but without -whole-program-visibility to confirm
36 ;; WPD fails
37
38 ;; Index based WPD
39 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
40 ; RUN: --plugin-opt=save-temps \
41 ; RUN: --plugin-opt=-pass-remarks=. \
42 ; RUN: %t2.o -o %t3 \
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
45
46 ;; Hybrid WPD
47 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
48 ; RUN: --plugin-opt=save-temps \
49 ; RUN: --plugin-opt=-pass-remarks=. \
50 ; RUN: %t.o -o %t3 \
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
53
54 ;; Regular LTO WPD
55 ; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
56 ; RUN: --plugin-opt=save-temps \
57 ; RUN: --plugin-opt=-pass-remarks=. \
58 ; RUN: %t4.o -o %t3 \
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
61
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"
64
65 %struct.A = type { ptr }
66 %struct.B = type { %struct.A }
67 %struct.C = type { %struct.A }
68 %struct.D = type { ptr }
69
70 @_ZTV1B = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !5
71 @_ZTV1C = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1C1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !2, !vcall_visibility !5
72 @_ZTV1D = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEi] }, !type !3, !vcall_visibility !5
73
74 ; Prevent the vtables from being dead code eliminated.
75 @llvm.used = appending global [3 x ptr] [ ptr @_ZTV1B, ptr @_ZTV1C, ptr @_ZTV1D]
76
77 ; CHECK-IR-LABEL: define dso_local {{(noundef )?}}i32 @_start
78 define i32 @_start(ptr %obj, ptr %obj2, i32 %a) {
79 entry:
80 %vtable = load ptr, ptr %obj
81 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")
82 call void @llvm.assume(i1 %p)
83 %fptrptr = getelementptr ptr, ptr %vtable, i32 1
84 %fptr1 = load ptr, ptr %fptrptr, align 8
85
86 ;; Check that the call was devirtualized.
87 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
88 ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1
89 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)
90
91 %fptr22 = load ptr, ptr %vtable, align 8
92
93 ;; We still have to call it as virtual.
94 ; CHECK-IR: %call3 = tail call i32 %fptr22
95 ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr22
96 %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call)
97
98 %vtable2 = load ptr, ptr %obj2
99 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !4)
100 call void @llvm.assume(i1 %p2)
101
102 %fptr33 = load ptr, ptr %vtable2, align 8
103
104 ;; Check that the call was devirtualized.
105 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi
106 ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33
107 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3)
108 ret i32 %call4
109 }
110 ; CHECK-IR-LABEL: ret i32
111 ; CHECK-IR-LABEL: }
112
113 declare i1 @llvm.type.test(ptr, metadata)
114 declare void @llvm.assume(i1)
115
116 define i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {
117 ret i32 0;
118 }
119
120 define i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {
121 ret i32 0;
122 }
123
124 define i32 @_ZN1C1fEi(ptr %this, i32 %a) #0 {
125 ret i32 0;
126 }
127
128 define i32 @_ZN1D1mEi(ptr %this, i32 %a) #0 {
129 ret i32 0;
130 }
131
132 ;; Make sure we don't inline or otherwise optimize out the direct calls.
133 attributes #0 = { noinline optnone }
134
135 !0 = !{i64 16, !"_ZTS1A"}
136 !1 = !{i64 16, !"_ZTS1B"}
137 !2 = !{i64 16, !"_ZTS1C"}
138 !3 = !{i64 16, !4}
139 !4 = distinct !{}
140 !5 = !{i64 0}