]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/ThinLTO/X86/deadstrip.ll
Vendor import of llvm trunk r291274:
[FreeBSD/FreeBSD.git] / test / ThinLTO / X86 / deadstrip.ll
1 ; RUN: opt -module-summary %s -o %t1.bc
2 ; RUN: opt -module-summary %p/Inputs/deadstrip.ll -o %t2.bc
3 ; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t1.bc %t2.bc
4
5 ; RUN: llvm-lto -exported-symbol=_main -thinlto-action=promote %t1.bc -thinlto-index=%t.index.bc -o - | llvm-lto -exported-symbol=_main -thinlto-action=internalize -thinlto-index %t.index.bc -thinlto-module-id=%t1.bc - -o - | llvm-dis -o - | FileCheck %s
6 ; RUN: llvm-lto -exported-symbol=_main -thinlto-action=promote %t2.bc -thinlto-index=%t.index.bc -o - | llvm-lto -exported-symbol=_main -thinlto-action=internalize -thinlto-index %t.index.bc -thinlto-module-id=%t2.bc - -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK2
7
8 ; RUN: llvm-lto -exported-symbol=_main -thinlto-action=run %t1.bc %t2.bc
9 ; RUN: llvm-nm %t1.bc.thinlto.o | FileCheck %s --check-prefix=CHECK-NM
10
11 ; RUN: llvm-lto2 %t1.bc %t2.bc -o %t.out -save-temps \
12 ; RUN:   -r %t1.bc,_main,plx \
13 ; RUN:   -r %t1.bc,_bar,pl \
14 ; RUN:   -r %t1.bc,_dead_func,pl \
15 ; RUN:   -r %t1.bc,_baz,l \
16 ; RUN:   -r %t1.bc,_boo,l \
17 ; RUN:   -r %t2.bc,_baz,pl \
18 ; RUN:   -r %t2.bc,_boo,pl \
19 ; RUN:   -r %t2.bc,_dead_func,pl \
20 ; RUN:   -r %t2.bc,_another_dead_func,pl
21 ; RUN: llvm-dis < %t.out.0.3.import.bc | FileCheck %s
22 ; RUN: llvm-dis < %t.out.1.3.import.bc | FileCheck %s --check-prefix=CHECK2
23 ; RUN: llvm-nm %t.out.1 | FileCheck %s --check-prefix=CHECK2-NM
24
25 ; Dead-stripping on the index allows to internalize these,
26 ; and limit the import of @baz thanks to early pruning.
27 ; CHECK-NOT: available_externally {{.*}} @baz()
28 ; CHECK: @llvm.global_ctors =
29 ; CHECK: define internal void @_GLOBAL__I_a()
30 ; CHECK: define internal void @bar() {
31 ; CHECK: define internal void @bar_internal()
32 ; CHECK: define internal void @dead_func() {
33 ; CHECK-NOT: available_externally {{.*}} @baz()
34
35 ; Make sure we didn't internalize @boo, which is reachable via
36 ; llvm.global_ctors
37 ; CHECK2: define void @boo()
38 ; We should have eventually revoved @baz since it was internalized and unused
39 ; CHECK2-NM-NOT: _baz
40
41 ; The final binary should not contain any of the dead functions,
42 ; only main is expected because bar is expected to be inlined and stripped out.
43 ; CHECK-NM-NOT: bar
44 ; CHECK-NM-NOT: dead
45 ; CHECK-NM: T _main
46 ; CHECK-NM-NOT: bar
47 ; CHECK-NM-NOT: dead
48
49 ; Next test the case where Inputs/deadstrip.ll does not get a module index,
50 ; which will cause it to be handled by regular LTO in the new LTO API.
51 ; In that case there are uses of @dead_func in the regular LTO partition
52 ; and it shouldn't be internalized.
53 ; RUN: opt %p/Inputs/deadstrip.ll -o %t3.bc
54 ; RUN: llvm-lto2 %t1.bc %t3.bc -o %t4.out -save-temps \
55 ; RUN:   -r %t1.bc,_main,plx \
56 ; RUN:   -r %t1.bc,_bar,pl \
57 ; RUN:   -r %t1.bc,_dead_func,pl \
58 ; RUN:   -r %t1.bc,_baz,l \
59 ; RUN:   -r %t1.bc,_boo,l \
60 ; RUN:   -r %t3.bc,_baz,pl \
61 ; RUN:   -r %t3.bc,_boo,pl \
62 ; RUN:   -r %t3.bc,_dead_func,pl \
63 ; RUN:   -r %t3.bc,_another_dead_func,pl
64 ; RUN: llvm-dis < %t4.out.1.3.import.bc | FileCheck %s --check-prefix=CHECK-NOTDEAD
65 ; RUN: llvm-nm %t4.out.0 | FileCheck %s --check-prefix=CHECK-NM-NOTDEAD
66
67 ; We can't internalize @dead_func because of the use in the regular LTO
68 ; partition.
69 ; CHECK-NOTDEAD: define void @dead_func()
70 ; We also can't eliminate @baz because it is in the regular LTO partition
71 ; and called from @dead_func.
72 ; CHECK-NM-NOTDEAD: T _baz
73
74 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
75 target triple = "x86_64-apple-macosx10.11.0"
76
77
78 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @_GLOBAL__I_a }]
79
80 declare void @baz()
81
82 declare void @boo()
83
84 define internal void @_GLOBAL__I_a() #1 section "__TEXT,__StaticInit,regular,pure_instructions" {
85 entry:
86     call void @boo()
87     ret void
88 }
89
90 define void @bar() {
91     ret void
92 }
93
94 define internal void @bar_internal() {
95     ret void
96 }
97
98 define void @dead_func() {
99     call void @bar()
100     call void @baz()
101     call void @bar_internal()
102     ret void
103 }
104
105 define void @main() {
106     call void @bar()
107     call void @bar_internal()
108     ret void
109 }