1 ; RUN: opt < %s -aa-pipeline=basic-aa -passes='cgscc(function-attrs,inline)' -S | FileCheck %s
2 ; This test runs the inliner and the function attribute deduction. It ensures
3 ; that when the inliner mutates the call graph it correctly updates the CGSCC
4 ; iteration so that we can compute refined function attributes. In this way it
5 ; is leveraging function attribute computation to observe correct call graph
8 ; Boring unknown external function call.
9 ; CHECK: declare void @unknown()
10 declare void @unknown()
12 ; Sanity check: this should get annotated as readnone.
13 ; CHECK: Function Attrs: nounwind readnone
14 ; CHECK-NEXT: declare void @readnone()
15 declare void @readnone() readnone nounwind
17 ; The 'test1_' prefixed functions are designed to trigger forming a new direct
18 ; call in the inlined body of the function. After that, we form a new SCC and
19 ; using that can deduce precise function attrs.
21 ; This function should no longer exist.
22 ; CHECK-NOT: @test1_f()
23 define internal void @test1_f(void()* %p) {
29 ; This function should have had 'readnone' deduced for its SCC.
30 ; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
31 ; CHECK-NEXT: define void @test1_g()
32 define void @test1_g() noinline {
34 call void @test1_f(void()* @test1_h)
38 ; This function should have had 'readnone' deduced for its SCC.
39 ; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
40 ; CHECK-NEXT: define void @test1_h()
41 define void @test1_h() noinline {
49 ; The 'test2_' prefixed functions are designed to trigger forming a new direct
50 ; call due to RAUW-ing the returned value of a called function into the caller.
51 ; This too should form a new SCC which can then be reasoned about to compute
52 ; precise function attrs.
54 ; This function should no longer exist.
55 ; CHECK-NOT: @test2_f()
56 define internal void()* @test2_f() {
61 ; This function should have had 'readnone' deduced for its SCC.
62 ; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
63 ; CHECK-NEXT: define void @test2_g()
64 define void @test2_g() noinline {
66 %p = call void()* @test2_f()
71 ; This function should have had 'readnone' deduced for its SCC.
72 ; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
73 ; CHECK-NEXT: define void @test2_h()
74 define void @test2_h() noinline {
82 ; The 'test3_' prefixed functions are designed to inline in a way that causes
83 ; call sites to become trivially dead during the middle of inlining callsites of
84 ; a single function to make sure that the inliner does not get confused by this
87 ; CHECK-NOT: @test3_maybe_unknown(
88 define internal void @test3_maybe_unknown(i1 %b) {
90 br i1 %b, label %then, label %exit
100 ; CHECK-NOT: @test3_f(
101 define internal i1 @test3_f() {
106 ; CHECK-NOT: @test3_g(
107 define internal i1 @test3_g(i1 %b) {
109 br i1 %b, label %then1, label %if2
112 call void @test3_maybe_unknown(i1 true)
116 %f = call i1 @test3_f()
117 br i1 %f, label %then2, label %exit
120 call void @test3_maybe_unknown(i1 true)
127 ; FIXME: Currently the inliner doesn't successfully mark this as readnone
128 ; because while it simplifies trivially dead CFGs when inlining callees it
129 ; doesn't simplify the caller's trivially dead CFG and so we end with a dead
130 ; block calling @unknown.
131 ; CHECK-NOT: Function Attrs: readnone
132 ; CHECK: define void @test3_h()
133 define void @test3_h() {
135 %g = call i1 @test3_g(i1 false)
136 br i1 %g, label %then, label %exit
139 call void @test3_maybe_unknown(i1 true)
143 call void @test3_maybe_unknown(i1 false)
148 ; The 'test4_' prefixed functions are designed to trigger forming a new direct
149 ; call in the inlined body of the function similar to 'test1_'. However, after
150 ; that we continue to inline another edge of the graph forcing us to do a more
151 ; interesting call graph update for the new call edge. Eventually, we still
152 ; form a new SCC and should use that can deduce precise function attrs.
154 ; This function should have had 'readnone' deduced for its SCC.
155 ; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
156 ; CHECK-NEXT: define void @test4_f1()
157 define void @test4_f1() noinline {
163 ; CHECK-NOT: @test4_f2
164 define internal void @test4_f2() {
166 call void @test4_f1()
170 ; CHECK-NOT: @test4_g
171 define internal void @test4_g(void()* %p) {
177 ; This function should have had 'readnone' deduced for its SCC.
178 ; CHECK: Function Attrs: nofree noinline nosync nounwind readnone
179 ; CHECK-NEXT: define void @test4_h()
180 define void @test4_h() noinline {
182 call void @test4_g(void()* @test4_f2)