1 ; RUN: opt -function-attrs -S < %s | FileCheck %s
2 ; RUN: opt -passes=function-attrs -S < %s | FileCheck %s
4 ; CHECK: Function Attrs
5 ; CHECK-NOT: convergent
6 ; CHECK-NEXT: define i32 @nonleaf()
7 define i32 @nonleaf() convergent {
12 ; CHECK: Function Attrs
13 ; CHECK-NOT: convergent
14 ; CHECK-NEXT: define i32 @leaf()
15 define i32 @leaf() convergent {
19 ; CHECK: Function Attrs
20 ; CHECK-SAME: convergent
21 ; CHECK-NEXT: declare i32 @k()
22 declare i32 @k() convergent
24 ; CHECK: Function Attrs
25 ; CHECK-SAME: convergent
26 ; CHECK-NEXT: define i32 @extern()
27 define i32 @extern() convergent {
28 %a = call i32 @k() convergent
32 ; Convergent should not be removed on the function here. Although the call is
33 ; not explicitly convergent, it picks up the convergent attr from the callee.
35 ; CHECK: Function Attrs
36 ; CHECK-SAME: convergent
37 ; CHECK-NEXT: define i32 @extern_non_convergent_call()
38 define i32 @extern_non_convergent_call() convergent {
43 ; CHECK: Function Attrs
44 ; CHECK-SAME: convergent
45 ; CHECK-NEXT: define i32 @indirect_convergent_call(
46 define i32 @indirect_convergent_call(i32 ()* %f) convergent {
47 %a = call i32 %f() convergent
50 ; Give indirect_non_convergent_call the norecurse attribute so we get a
51 ; "Function Attrs" comment in the output.
53 ; CHECK: Function Attrs
54 ; CHECK-NOT: convergent
55 ; CHECK-NEXT: define i32 @indirect_non_convergent_call(
56 define i32 @indirect_non_convergent_call(i32 ()* %f) convergent norecurse {
61 ; CHECK: Function Attrs
62 ; CHECK-SAME: convergent
63 ; CHECK-NEXT: declare void @llvm.nvvm.barrier0()
64 declare void @llvm.nvvm.barrier0() convergent
66 ; CHECK: Function Attrs
67 ; CHECK-SAME: convergent
68 ; CHECK-NEXT: define i32 @intrinsic()
69 define i32 @intrinsic() convergent {
70 ; Implicitly convergent, because the intrinsic is convergent.
71 call void @llvm.nvvm.barrier0()
75 ; CHECK: Function Attrs
76 ; CHECK-NOT: convergent
77 ; CHECK-NEXT: define i32 @recursive1()
78 define i32 @recursive1() convergent {
79 %a = call i32 @recursive2() convergent
83 ; CHECK: Function Attrs
84 ; CHECK-NOT: convergent
85 ; CHECK-NEXT: define i32 @recursive2()
86 define i32 @recursive2() convergent {
87 %a = call i32 @recursive1() convergent
91 ; CHECK: Function Attrs
92 ; CHECK-SAME: convergent
93 ; CHECK-NEXT: define i32 @noopt()
94 define i32 @noopt() convergent optnone noinline {
95 %a = call i32 @noopt_friend() convergent
99 ; A function which is mutually-recursive with a convergent, optnone function
100 ; shouldn't have its convergent attribute stripped.
101 ; CHECK: Function Attrs
102 ; CHECK-SAME: convergent
103 ; CHECK-NEXT: define i32 @noopt_friend()
104 define i32 @noopt_friend() convergent {
105 %a = call i32 @noopt()