1 ; Test the behavior of GlobalDCE in conjunction with comdats.
3 ; RUN: opt < %s -globaldce -S | FileCheck %s
5 ; First test checks that if one function in a comdat group is used, both other
6 ; functions and other globals even if unused will be preserved.
8 ; CHECK: $test1_c = comdat any
10 ; Second test checks that if one function in a comdat group is used, both other
11 ; functions and other globals even if unused will be preserved.
13 ; CHECK: $test2_c = comdat any
15 ; Third test checks that calling a function in a comdat group with an alias
16 ; preserves the alias.
18 ; CHECK: $test3_c = comdat any
20 ; Fourth test checks that calling an alias in a comdat group with a function
21 ; preserves the function. (This is the trivial case as the alias uses the
24 ; CHECK: $test4_c = comdat any
26 ; Fifth test checks that calling a function in a comdat group that is used as
27 ; the resolver of an ifunc doesn't preserve that ifunc. ifunc symbols don't
28 ; participate in the comdat group of their resolver function as they are
29 ; considered separate objects.
31 ; CHECK: $test5_c = comdat any
33 ; Sixth test checks that calling an ifunc whose resolver is in a comdat group
34 ; preserves the resolver. This is the trivial case as the ifunc uses the
37 ; CHECK: $test6_c = comdat any
39 ; Seventh test checks that we can eliminate a comdat when it has only one dead function participant.
41 ; CHECK-NOT: $test7_c = comdat any
43 ; Eighth test checks that we can eliminate a comdat when it has only one dead global participant.
45 ; CHECK-NOT: $test8_c = comdat any
47 ; Ninth test checks that we can eliminate a comdat when there are multiple
50 ; CHECK-NOT: $test9_c = comdat any
52 ; Tenth test checks that we can eliminate a comdat when it has multiple
53 ; participants that form internal cyclic uses but are never used externally and
54 ; thus the entire ifunc can safely be eliminated.
55 $test10_c = comdat any
56 ; CHECK-NOT: $test10_c = comdat any
58 @test1_gv = linkonce_odr unnamed_addr global i32 42, comdat($test1_c)
59 ; CHECK: @test1_gv = linkonce_odr unnamed_addr global
61 @test2_used = linkonce_odr unnamed_addr global i32 42, comdat($test2_c)
62 ; CHECK: @test2_used = linkonce_odr unnamed_addr global
64 @test2_gv = linkonce_odr unnamed_addr global i32 42, comdat($test2_c)
65 ; CHECK: @test2_gv = linkonce_odr unnamed_addr global
67 @test8_gv = linkonce_odr unnamed_addr global i32 42, comdat($test8_c)
68 ; CHECK-NOT: @test8_gv
70 @test9_gv = linkonce_odr unnamed_addr global i32 42, comdat($test9_c)
71 ; CHECK-NOT: @test9_gv
73 @test10_gv = linkonce_odr unnamed_addr global void ()* @test10_f, comdat($test10_c)
74 ; CHECK-NOT: @test10_gv
76 @test3_a = linkonce_odr unnamed_addr alias void (), void ()* @test3_f
77 ; CHECK: @test3_a = linkonce_odr unnamed_addr alias
79 @test4_a = linkonce_odr unnamed_addr alias void (), void ()* @test4_f
80 ; CHECK: @test4_a = linkonce_odr unnamed_addr alias
82 @test10_a = linkonce_odr unnamed_addr alias void (), void ()* @test10_g
83 ; CHECK-NOT: @test10_a
85 @test5_if = linkonce_odr ifunc void (), void ()* ()* @test5_f
86 ; CHECK-NOT: @test5_if
88 @test6_if = linkonce_odr ifunc void (), void ()* ()* @test6_f
89 ; CHECK: @test6_if = linkonce_odr ifunc
91 ; This function is directly used and so cannot be eliminated.
92 define linkonce_odr void @test1_used() comdat($test1_c) {
93 ; CHECK: define linkonce_odr void @test1_used()
98 define linkonce_odr void @test1_f() comdat($test1_c) {
99 ; CHECK: define linkonce_odr void @test1_f()
104 ; Now test that a function, global variable, alias, and ifunc in the same
106 define linkonce_odr void @test2_f() comdat($test2_c) {
107 ; CHECK: define linkonce_odr void @test2_f()
112 define linkonce_odr void @test3_f() comdat($test3_c) {
113 ; CHECK: define linkonce_odr void @test3_f()
118 define linkonce_odr void @test4_f() comdat($test4_c) {
119 ; CHECK: define linkonce_odr void @test4_f()
124 declare void @test_external()
126 define linkonce_odr void ()* @test5_f() comdat($test5_c) {
127 ; CHECK: define linkonce_odr void ()* @test5_f()
129 ret void ()* @test_external
132 define linkonce_odr void ()* @test6_f() comdat($test6_c) {
133 ; CHECK: define linkonce_odr void ()* @test6_f()
135 ret void ()* @test_external
138 define linkonce_odr void @test7_f() comdat($test7_c) {
139 ; CHECK-NOT: @test7_f
144 define linkonce_odr void @test9_f() comdat($test9_c) {
145 ; CHECK-NOT: @test9_f
150 define linkonce_odr void @test10_f() comdat($test10_c) {
151 ; CHECK-NOT: @test10_f
153 %gv = load void ()*, void ()** @test10_gv
154 call void @test10_a()
158 define linkonce_odr void @test10_g() comdat($test10_c) {
159 ; CHECK-NOT: @test10_g
161 call void @test10_f()
166 ; An external function to pin as "used" various things above that shouldn't be
168 define void @external_user() {
169 call void @test1_used()
170 %gv = load i32, i32* @test2_used
175 %fptr = call void() *@test5_f()
176 call void @test6_if()