• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 \
11; RUN: 	 --export-dynamic 2>&1 | FileCheck %s --check-prefix=REMARK
12; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
13
14; Hybrid WPD
15; Generate split module with summary for hybrid Thin/Regular LTO WPD.
16; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s
17; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
18; RUN:   --plugin-opt=whole-program-visibility \
19; RUN:   --plugin-opt=save-temps \
20; RUN:   --plugin-opt=-pass-remarks=. \
21; RUN:   %t.o -o %t3 \
22; RUN: 	 --export-dynamic 2>&1 | FileCheck %s --check-prefix=REMARK
23; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
24
25; Regular LTO WPD
26; RUN: opt -o %t4.o %s
27; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
28; RUN:   --plugin-opt=whole-program-visibility \
29; RUN:   --plugin-opt=save-temps \
30; RUN:   --plugin-opt=-pass-remarks=. \
31; RUN:   %t4.o -o %t3 \
32; RUN: 	 --export-dynamic 2>&1 | FileCheck %s --check-prefix=REMARK
33; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
34
35; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi
36; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi
37
38; Try everything again but without -whole-program-visibility to confirm
39; WPD fails
40
41; Index based WPD
42; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
43; RUN:   --plugin-opt=save-temps \
44; RUN:   --plugin-opt=-pass-remarks=. \
45; RUN:   %t2.o -o %t3 \
46; RUN: 	 --export-dynamic 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty
47; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR
48
49; Hybrid WPD
50; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
51; RUN:   --plugin-opt=save-temps \
52; RUN:   --plugin-opt=-pass-remarks=. \
53; RUN:   %t.o -o %t3 \
54; RUN: 	 --export-dynamic 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty
55; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR
56
57; Regular LTO WPD
58; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \
59; RUN:   --plugin-opt=save-temps \
60; RUN:   --plugin-opt=-pass-remarks=. \
61; RUN:   %t4.o -o %t3 \
62; RUN: 	 --export-dynamic 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty
63; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR
64
65target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
66target triple = "x86_64-grtev4-linux-gnu"
67
68%struct.A = type { i32 (...)** }
69%struct.B = type { %struct.A }
70%struct.C = type { %struct.A }
71%struct.D = type { i32 (...)** }
72
73@_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
74@_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
75@_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
76
77
78; CHECK-IR-LABEL: define dso_local i32 @_start
79define i32 @_start(%struct.A* %obj, %struct.D* %obj2, i32 %a) {
80entry:
81  %0 = bitcast %struct.A* %obj to i8***
82  %vtable = load i8**, i8*** %0
83  %1 = bitcast i8** %vtable to i8*
84  %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A")
85  call void @llvm.assume(i1 %p)
86  %fptrptr = getelementptr i8*, i8** %vtable, i32 1
87  %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)**
88  %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8
89
90  ; Check that the call was devirtualized.
91  ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
92  ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1
93  %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a)
94
95  %3 = bitcast i8** %vtable to i32 (%struct.A*, i32)**
96  %fptr22 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %3, align 8
97
98  ; We still have to call it as virtual.
99  ; CHECK-IR: %call3 = tail call i32 %fptr22
100  ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr22
101  %call3 = tail call i32 %fptr22(%struct.A* nonnull %obj, i32 %call)
102
103  %4 = bitcast %struct.D* %obj2 to i8***
104  %vtable2 = load i8**, i8*** %4
105  %5 = bitcast i8** %vtable2 to i8*
106  %p2 = call i1 @llvm.type.test(i8* %5, metadata !4)
107  call void @llvm.assume(i1 %p2)
108
109  %6 = bitcast i8** %vtable2 to i32 (%struct.D*, i32)**
110  %fptr33 = load i32 (%struct.D*, i32)*, i32 (%struct.D*, i32)** %6, align 8
111
112  ; Check that the call was devirtualized.
113  ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi
114  ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33
115  %call4 = tail call i32 %fptr33(%struct.D* nonnull %obj2, i32 %call3)
116  ret i32 %call4
117}
118; CHECK-IR-LABEL: ret i32
119; CHECK-IR-LABEL: }
120
121declare i1 @llvm.type.test(i8*, metadata)
122declare void @llvm.assume(i1)
123
124define i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) #0 {
125   ret i32 0;
126}
127
128define i32 @_ZN1A1nEi(%struct.A* %this, i32 %a) #0 {
129   ret i32 0;
130}
131
132define i32 @_ZN1C1fEi(%struct.C* %this, i32 %a) #0 {
133   ret i32 0;
134}
135
136define i32 @_ZN1D1mEi(%struct.D* %this, i32 %a) #0 {
137   ret i32 0;
138}
139
140; Make sure we don't inline or otherwise optimize out the direct calls.
141attributes #0 = { noinline optnone }
142
143!0 = !{i64 16, !"_ZTS1A"}
144!1 = !{i64 16, !"_ZTS1B"}
145!2 = !{i64 16, !"_ZTS1C"}
146!3 = !{i64 16, !4}
147!4 = distinct !{}
148!5 = !{i64 0}
149