1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2 ; RUN: opt -attributor -enable-new-pm=0 -S %s | FileCheck %s
3 ; RUN: opt -passes=attributor -S %s | FileCheck %s
5 @var1 = internal global [1 x i32] undef
6 @var2 = internal global i32 0
9 ; CHECK: @[[VAR1:[a-zA-Z0-9_$"\\.-]+]] = internal global [1 x i32] undef
10 ; CHECK: @[[VAR2:[a-zA-Z0-9_$"\\.-]+]] = internal global i32 0
12 define i32 addrspace(1)* @foo(i32 addrspace(4)* %arg) {
13 ; CHECK: Function Attrs: nofree nosync nounwind readnone willreturn
14 ; CHECK-LABEL: define {{[^@]+}}@foo
15 ; CHECK-SAME: (i32 addrspace(4)* nofree readnone [[ARG:%.*]]) #[[ATTR0:[0-9]+]] {
17 ; CHECK-NEXT: [[TMP0:%.*]] = addrspacecast i32 addrspace(4)* [[ARG]] to i32 addrspace(1)*
18 ; CHECK-NEXT: ret i32 addrspace(1)* [[TMP0]]
21 %0 = addrspacecast i32 addrspace(4)* %arg to i32 addrspace(1)*
22 ret i32 addrspace(1)* %0
25 define i32* @func1() {
26 ; CHECK: Function Attrs: nofree nosync nounwind readnone willreturn
27 ; CHECK-LABEL: define {{[^@]+}}@func1
28 ; CHECK-SAME: () #[[ATTR0]] {
29 ; CHECK-NEXT: ret i32* getelementptr inbounds ([1 x i32], [1 x i32]* @var1, i32 0, i32 0)
31 %ptr = call i32* @func1a([1 x i32]* @var1)
35 define internal i32* @func1a([1 x i32]* %arg) {
36 %ptr = getelementptr inbounds [1 x i32], [1 x i32]* %arg, i64 0, i64 0
40 define internal void @func2a(i32* %0) {
41 ; CHECK: Function Attrs: nofree nosync nounwind willreturn writeonly
42 ; CHECK-LABEL: define {{[^@]+}}@func2a
43 ; CHECK-SAME: (i32* nocapture nofree nonnull writeonly align 4 dereferenceable(4) [[TMP0:%.*]]) #[[ATTR1:[0-9]+]] {
44 ; CHECK-NEXT: store i32 0, i32* @var2, align 4
45 ; CHECK-NEXT: ret void
52 ; CHECK-LABEL: define {{[^@]+}}@func2() {
53 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i32 (i32*, ...) bitcast (void (i32*)* @func2a to i32 (i32*, ...)*)(i32* nonnull align 4 dereferenceable(4) @var2)
54 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* @var2, align 4
55 ; CHECK-NEXT: ret i32 [[TMP2]]
57 %1 = tail call i32 (i32*, ...) bitcast (void (i32*)* @func2a to i32 (i32*, ...)*)(i32* @var2)
58 %2 = load i32, i32* @var2
62 define i32 @func3(i1 %false) {
63 ; CHECK-LABEL: define {{[^@]+}}@func3
64 ; CHECK-SAME: (i1 [[FALSE:%.*]]) {
65 ; CHECK-NEXT: [[TMP1:%.*]] = tail call i32 (i32*, ...) bitcast (void (i32*)* @func2a to i32 (i32*, ...)*)(i32* nonnull align 4 dereferenceable(4) @var2)
66 ; CHECK-NEXT: br i1 [[FALSE]], label [[USE_BB:%.*]], label [[RET_BB:%.*]]
68 ; CHECK-NEXT: ret i32 [[TMP1]]
70 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, i32* @var2, align 4
71 ; CHECK-NEXT: ret i32 [[TMP2]]
73 %1 = tail call i32 (i32*, ...) bitcast (void (i32*)* @func2a to i32 (i32*, ...)*)(i32* @var2)
74 br i1 %false, label %use_bb, label %ret_bb
78 %2 = load i32, i32* @var2
82 define void @func4() {
83 ; CHECK-LABEL: define {{[^@]+}}@func4() {
84 ; CHECK-NEXT: call void @func5()
85 ; CHECK-NEXT: ret void
87 call void @func5(i32 0)
91 define internal void @func5(i32 %0) {
92 ; CHECK-LABEL: define {{[^@]+}}@func5() {
93 ; CHECK-NEXT: br label [[BLOCK:%.*]]
95 ; CHECK-NEXT: call void @func6(i8* blockaddress(@func5, [[BLOCK]]))
96 ; CHECK-NEXT: ret void
102 store i8* blockaddress(@func5, %block), i8** %tmp
103 %addr = load i8*, i8** %tmp
104 call void @func6(i8* %addr)
109 ; CHECK-LABEL: define {{[^@]+}}@foo3() {
110 ; CHECK-NEXT: [[CALL:%.*]] = call i16 bitcast (i16 (i16*, i16)* @bar3 to i16 ()*)()
111 ; CHECK-NEXT: ret i16 [[CALL]]
113 %call = call i16 bitcast (i16 (i16*, i16) * @bar3 to i16 () *)()
116 define internal i16 @bar3(i16* %p1, i16 %p2) {
117 ; CHECK: Function Attrs: nofree nosync nounwind readnone willreturn
118 ; CHECK-LABEL: define {{[^@]+}}@bar3
119 ; CHECK-SAME: (i16* nocapture nofree readnone [[P1:%.*]], i16 returned [[P2:%.*]]) #[[ATTR0]] {
120 ; CHECK-NEXT: ret i16 [[P2]]
125 ; CHECK-LABEL: declare {{[^@]+}}@func6
127 declare void @func6(i8*)
129 ; CHECK: attributes #[[ATTR0]] = { nofree nosync nounwind readnone willreturn }
130 ; CHECK: attributes #[[ATTR1]] = { nofree nosync nounwind willreturn writeonly }