1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
2 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,TUNIT
3 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC
6 ; Don't promote arguments of musttail callee
8 %T = type { i32, i32, i32, i32 }
10 define internal i32 @test(ptr %p) {
11 ; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
12 ; CHECK-LABEL: define {{[^@]+}}@test
13 ; CHECK-SAME: (ptr nocapture nofree readonly [[P:%.*]]) #[[ATTR0:[0-9]+]] {
14 ; CHECK-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], ptr [[P]], i64 0, i32 3
15 ; CHECK-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], ptr [[P]], i64 0, i32 2
16 ; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[A_GEP]], align 4
17 ; CHECK-NEXT: [[B:%.*]] = load i32, ptr [[B_GEP]], align 4
18 ; CHECK-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
19 ; CHECK-NEXT: ret i32 [[V]]
21 %a.gep = getelementptr %T, ptr %p, i64 0, i32 3
22 %b.gep = getelementptr %T, ptr %p, i64 0, i32 2
23 %a = load i32, ptr %a.gep
24 %b = load i32, ptr %b.gep
29 define i32 @caller(ptr %p) {
30 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
31 ; TUNIT-LABEL: define {{[^@]+}}@caller
32 ; TUNIT-SAME: (ptr nocapture nofree readonly [[P:%.*]]) #[[ATTR0]] {
33 ; TUNIT-NEXT: [[V:%.*]] = musttail call i32 @test(ptr nocapture nofree readonly [[P]]) #[[ATTR4:[0-9]+]]
34 ; TUNIT-NEXT: ret i32 [[V]]
36 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(argmem: read)
37 ; CGSCC-LABEL: define {{[^@]+}}@caller
38 ; CGSCC-SAME: (ptr nocapture nofree readonly [[P:%.*]]) #[[ATTR1:[0-9]+]] {
39 ; CGSCC-NEXT: [[V:%.*]] = musttail call i32 @test(ptr nocapture nofree readonly [[P]]) #[[ATTR5:[0-9]+]]
40 ; CGSCC-NEXT: ret i32 [[V]]
42 %v = musttail call i32 @test(ptr %p)
46 ; Don't promote arguments of musttail caller
48 define i32 @foo(ptr %p, i32 %v) {
49 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
50 ; TUNIT-LABEL: define {{[^@]+}}@foo
51 ; TUNIT-SAME: (ptr nocapture nofree readnone [[P:%.*]], i32 [[V:%.*]]) #[[ATTR1:[0-9]+]] {
52 ; TUNIT-NEXT: ret i32 0
54 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
55 ; CGSCC-LABEL: define {{[^@]+}}@foo
56 ; CGSCC-SAME: (ptr nocapture nofree readnone [[P:%.*]], i32 [[V:%.*]]) #[[ATTR2:[0-9]+]] {
57 ; CGSCC-NEXT: ret i32 0
62 define internal i32 @test2(ptr %p, i32 %p2) {
63 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(argmem: read)
64 ; CGSCC-LABEL: define {{[^@]+}}@test2
65 ; CGSCC-SAME: (ptr nocapture nofree readonly [[P:%.*]], i32 [[P2:%.*]]) #[[ATTR1]] {
66 ; CGSCC-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], ptr [[P]], i64 0, i32 3
67 ; CGSCC-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], ptr [[P]], i64 0, i32 2
68 ; CGSCC-NEXT: [[A:%.*]] = load i32, ptr [[A_GEP]], align 4
69 ; CGSCC-NEXT: [[B:%.*]] = load i32, ptr [[B_GEP]], align 4
70 ; CGSCC-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
71 ; CGSCC-NEXT: [[CA:%.*]] = musttail call noundef i32 @foo(ptr nofree undef, i32 [[V]]) #[[ATTR6:[0-9]+]]
72 ; CGSCC-NEXT: ret i32 [[CA]]
74 %a.gep = getelementptr %T, ptr %p, i64 0, i32 3
75 %b.gep = getelementptr %T, ptr %p, i64 0, i32 2
76 %a = load i32, ptr %a.gep
77 %b = load i32, ptr %b.gep
79 %ca = musttail call i32 @foo(ptr undef, i32 %v)
83 define i32 @caller2(ptr %g) {
84 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
85 ; TUNIT-LABEL: define {{[^@]+}}@caller2
86 ; TUNIT-SAME: (ptr nocapture nofree readnone [[G:%.*]]) #[[ATTR1]] {
87 ; TUNIT-NEXT: ret i32 0
89 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(argmem: read)
90 ; CGSCC-LABEL: define {{[^@]+}}@caller2
91 ; CGSCC-SAME: (ptr nocapture nofree readonly align 4 [[G:%.*]]) #[[ATTR1]] {
92 ; CGSCC-NEXT: [[V:%.*]] = call noundef i32 @test2(ptr nocapture nofree readonly [[G]], i32 noundef 0) #[[ATTR5]]
93 ; CGSCC-NEXT: ret i32 [[V]]
95 %v = call i32 @test2(ptr %g, i32 0)
99 ; In the version above we can remove the call to foo completely.
100 ; In the version below we keep the call and verify the return value
103 define i32 @bar(ptr %p, i32 %v) {
104 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
105 ; TUNIT-LABEL: define {{[^@]+}}@bar
106 ; TUNIT-SAME: (ptr nocapture nofree nonnull writeonly dereferenceable(4) [[P:%.*]], i32 [[V:%.*]]) #[[ATTR2:[0-9]+]] {
107 ; TUNIT-NEXT: store i32 [[V]], ptr [[P]], align 4
108 ; TUNIT-NEXT: ret i32 0
110 ; CGSCC: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write)
111 ; CGSCC-LABEL: define {{[^@]+}}@bar
112 ; CGSCC-SAME: (ptr nocapture nofree nonnull writeonly dereferenceable(4) [[P:%.*]], i32 [[V:%.*]]) #[[ATTR3:[0-9]+]] {
113 ; CGSCC-NEXT: store i32 [[V]], ptr [[P]], align 4
114 ; CGSCC-NEXT: ret i32 0
116 %i32ptr = getelementptr %T, ptr %p, i64 0, i32 0
117 store i32 %v, ptr %i32ptr
121 define internal i32 @test2b(ptr %p, i32 %p2) {
122 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite)
123 ; TUNIT-LABEL: define {{[^@]+}}@test2b
124 ; TUNIT-SAME: (ptr nocapture nofree readonly [[P:%.*]], i32 [[P2:%.*]]) #[[ATTR3:[0-9]+]] {
125 ; TUNIT-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], ptr [[P]], i64 0, i32 3
126 ; TUNIT-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], ptr [[P]], i64 0, i32 2
127 ; TUNIT-NEXT: [[A:%.*]] = load i32, ptr [[A_GEP]], align 4
128 ; TUNIT-NEXT: [[B:%.*]] = load i32, ptr [[B_GEP]], align 4
129 ; TUNIT-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
130 ; TUNIT-NEXT: [[CA:%.*]] = musttail call i32 @bar(ptr undef, i32 [[V]]) #[[ATTR5:[0-9]+]]
131 ; TUNIT-NEXT: ret i32 [[CA]]
133 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(argmem: readwrite)
134 ; CGSCC-LABEL: define {{[^@]+}}@test2b
135 ; CGSCC-SAME: (ptr nocapture nofree readonly [[P:%.*]], i32 [[P2:%.*]]) #[[ATTR4:[0-9]+]] {
136 ; CGSCC-NEXT: [[A_GEP:%.*]] = getelementptr [[T:%.*]], ptr [[P]], i64 0, i32 3
137 ; CGSCC-NEXT: [[B_GEP:%.*]] = getelementptr [[T]], ptr [[P]], i64 0, i32 2
138 ; CGSCC-NEXT: [[A:%.*]] = load i32, ptr [[A_GEP]], align 4
139 ; CGSCC-NEXT: [[B:%.*]] = load i32, ptr [[B_GEP]], align 4
140 ; CGSCC-NEXT: [[V:%.*]] = add i32 [[A]], [[B]]
141 ; CGSCC-NEXT: [[CA:%.*]] = musttail call noundef i32 @bar(ptr nofree nonnull undef, i32 [[V]]) #[[ATTR7:[0-9]+]]
142 ; CGSCC-NEXT: ret i32 [[CA]]
144 %a.gep = getelementptr %T, ptr %p, i64 0, i32 3
145 %b.gep = getelementptr %T, ptr %p, i64 0, i32 2
146 %a = load i32, ptr %a.gep
147 %b = load i32, ptr %b.gep
149 %ca = musttail call i32 @bar(ptr undef, i32 %v)
153 define i32 @caller2b(ptr %g) {
154 ; TUNIT: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite)
155 ; TUNIT-LABEL: define {{[^@]+}}@caller2b
156 ; TUNIT-SAME: (ptr nocapture nofree readonly [[G:%.*]]) #[[ATTR3]] {
157 ; TUNIT-NEXT: [[V:%.*]] = call i32 @test2b(ptr nocapture nofree readonly [[G]], i32 undef) #[[ATTR6:[0-9]+]]
158 ; TUNIT-NEXT: ret i32 0
160 ; CGSCC: Function Attrs: mustprogress nofree nosync nounwind willreturn memory(argmem: readwrite)
161 ; CGSCC-LABEL: define {{[^@]+}}@caller2b
162 ; CGSCC-SAME: (ptr nocapture nofree readonly align 4 [[G:%.*]]) #[[ATTR4]] {
163 ; CGSCC-NEXT: [[V:%.*]] = call noundef i32 @test2b(ptr nocapture nofree readonly [[G]], i32 noundef 0) #[[ATTR8:[0-9]+]]
164 ; CGSCC-NEXT: ret i32 [[V]]
166 %v = call i32 @test2b(ptr %g, i32 0)
170 ; TUNIT: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) }
171 ; TUNIT: attributes #[[ATTR1]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
172 ; TUNIT: attributes #[[ATTR2]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
173 ; TUNIT: attributes #[[ATTR3]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) }
174 ; TUNIT: attributes #[[ATTR4]] = { nofree nosync nounwind willreturn memory(read) }
175 ; TUNIT: attributes #[[ATTR5]] = { nofree nosync nounwind willreturn memory(write) }
176 ; TUNIT: attributes #[[ATTR6]] = { nofree nosync nounwind willreturn }
178 ; CGSCC: attributes #[[ATTR0]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) }
179 ; CGSCC: attributes #[[ATTR1]] = { mustprogress nofree nosync nounwind willreturn memory(argmem: read) }
180 ; CGSCC: attributes #[[ATTR2]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
181 ; CGSCC: attributes #[[ATTR3]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
182 ; CGSCC: attributes #[[ATTR4]] = { mustprogress nofree nosync nounwind willreturn memory(argmem: readwrite) }
183 ; CGSCC: attributes #[[ATTR5]] = { nofree willreturn memory(read) }
184 ; CGSCC: attributes #[[ATTR6]] = { nofree nosync willreturn }
185 ; CGSCC: attributes #[[ATTR7]] = { nofree nounwind willreturn memory(write) }
186 ; CGSCC: attributes #[[ATTR8]] = { nofree nounwind willreturn }