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