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 -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM
3 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=2 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM
4 ; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM
5 ; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM
10 declare void @test1_1(i8* %x1_1, i8* readonly %y1_1, ...)
12 ; NOTE: readonly for %y1_2 would be OK here but not for the similar situation in test13.
15 ; CHECK: @[[X:[a-zA-Z0-9_$"\\.-]+]] = global i32 0
16 ; CHECK: @[[CONSTANT_MEM:[a-zA-Z0-9_$"\\.-]+]] = external dso_local constant i32, align 4
18 define void @test1_2(i8* %x1_2, i8* %y1_2, i8* %z1_2) {
19 ; CHECK-LABEL: define {{[^@]+}}@test1_2
20 ; CHECK-SAME: (i8* [[X1_2:%.*]], i8* [[Y1_2:%.*]], i8* [[Z1_2:%.*]]) {
21 ; CHECK-NEXT: call void (i8*, i8*, ...) @test1_1(i8* [[X1_2]], i8* readonly [[Y1_2]], i8* [[Z1_2]])
22 ; CHECK-NEXT: store i32 0, i32* @x, align 4
23 ; CHECK-NEXT: ret void
25 call void (i8*, i8*, ...) @test1_1(i8* %x1_2, i8* %y1_2, i8* %z1_2)
30 define i8* @test2(i8* %p) {
31 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind willreturn writeonly
32 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test2
33 ; IS__TUNIT____-SAME: (i8* nofree readnone returned "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR0:[0-9]+]] {
34 ; IS__TUNIT____-NEXT: store i32 0, i32* @x, align 4
35 ; IS__TUNIT____-NEXT: ret i8* [[P]]
37 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind willreturn writeonly
38 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test2
39 ; IS__CGSCC____-SAME: (i8* nofree readnone returned "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR0:[0-9]+]] {
40 ; IS__CGSCC____-NEXT: store i32 0, i32* @x, align 4
41 ; IS__CGSCC____-NEXT: ret i8* [[P]]
47 define i1 @test3(i8* %p, i8* %q) {
48 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
49 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test3
50 ; IS__TUNIT____-SAME: (i8* nofree readnone [[P:%.*]], i8* nofree readnone [[Q:%.*]]) #[[ATTR1:[0-9]+]] {
51 ; IS__TUNIT____-NEXT: [[A:%.*]] = icmp ult i8* [[P]], [[Q]]
52 ; IS__TUNIT____-NEXT: ret i1 [[A]]
54 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
55 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test3
56 ; IS__CGSCC____-SAME: (i8* nofree readnone [[P:%.*]], i8* nofree readnone [[Q:%.*]]) #[[ATTR1:[0-9]+]] {
57 ; IS__CGSCC____-NEXT: [[A:%.*]] = icmp ult i8* [[P]], [[Q]]
58 ; IS__CGSCC____-NEXT: ret i1 [[A]]
60 %A = icmp ult i8* %p, %q
64 declare void @test4_1(i8* nocapture) readonly
66 define void @test4_2(i8* %p) {
67 ; CHECK: Function Attrs: readonly
68 ; CHECK-LABEL: define {{[^@]+}}@test4_2
69 ; CHECK-SAME: (i8* nocapture readonly [[P:%.*]]) #[[ATTR2:[0-9]+]] {
70 ; CHECK-NEXT: call void @test4_1(i8* nocapture readonly [[P]]) #[[ATTR2]]
71 ; CHECK-NEXT: ret void
73 call void @test4_1(i8* %p)
77 ; Missed optz'n: we could make %q readnone, but don't break test6!
78 define void @test5(i8** %p, i8* %q) {
79 ; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
80 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test5
81 ; IS__TUNIT____-SAME: (i8** nocapture nofree noundef nonnull writeonly align 8 dereferenceable(8) [[P:%.*]], i8* nofree writeonly [[Q:%.*]]) #[[ATTR3:[0-9]+]] {
82 ; IS__TUNIT____-NEXT: store i8* [[Q]], i8** [[P]], align 8
83 ; IS__TUNIT____-NEXT: ret void
85 ; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly
86 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test5
87 ; IS__CGSCC____-SAME: (i8** nocapture nofree noundef nonnull writeonly align 8 dereferenceable(8) [[P:%.*]], i8* nofree writeonly [[Q:%.*]]) #[[ATTR3:[0-9]+]] {
88 ; IS__CGSCC____-NEXT: store i8* [[Q]], i8** [[P]], align 8
89 ; IS__CGSCC____-NEXT: ret void
95 declare void @test6_1()
96 ; This is not a missed optz'n.
97 define void @test6_2(i8** %p, i8* %q) {
98 ; CHECK-LABEL: define {{[^@]+}}@test6_2
99 ; CHECK-SAME: (i8** nocapture nofree noundef nonnull writeonly align 8 dereferenceable(8) [[P:%.*]], i8* nofree [[Q:%.*]]) {
100 ; CHECK-NEXT: store i8* [[Q]], i8** [[P]], align 8
101 ; CHECK-NEXT: call void @test6_1()
102 ; CHECK-NEXT: ret void
104 store i8* %q, i8** %p
109 ; inalloca parameters are always considered written
110 define void @test7_1(i32* inalloca(i32) %a) {
111 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
112 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test7_1
113 ; IS__TUNIT____-SAME: (i32* nocapture nofree nonnull writeonly inalloca(i32) dereferenceable(4) [[A:%.*]]) #[[ATTR1]] {
114 ; IS__TUNIT____-NEXT: ret void
116 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
117 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test7_1
118 ; IS__CGSCC____-SAME: (i32* nocapture nofree nonnull writeonly inalloca(i32) dereferenceable(4) [[A:%.*]]) #[[ATTR1]] {
119 ; IS__CGSCC____-NEXT: ret void
124 define i32* @test8_1(i32* %p) {
125 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
126 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test8_1
127 ; IS__TUNIT____-SAME: (i32* nofree readnone returned "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR1]] {
128 ; IS__TUNIT____-NEXT: entry:
129 ; IS__TUNIT____-NEXT: ret i32* [[P]]
131 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
132 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test8_1
133 ; IS__CGSCC____-SAME: (i32* nofree readnone returned "no-capture-maybe-returned" [[P:%.*]]) #[[ATTR1]] {
134 ; IS__CGSCC____-NEXT: entry:
135 ; IS__CGSCC____-NEXT: ret i32* [[P]]
141 define void @test8_2(i32* %p) {
142 ; IS__TUNIT____: Function Attrs: argmemonly nofree nosync nounwind willreturn writeonly
143 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test8_2
144 ; IS__TUNIT____-SAME: (i32* nocapture nofree writeonly [[P:%.*]]) #[[ATTR3]] {
145 ; IS__TUNIT____-NEXT: entry:
146 ; IS__TUNIT____-NEXT: store i32 10, i32* [[P]], align 4
147 ; IS__TUNIT____-NEXT: ret void
149 ; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nosync nounwind willreturn writeonly
150 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test8_2
151 ; IS__CGSCC____-SAME: (i32* nocapture nofree writeonly [[P:%.*]]) #[[ATTR3]] {
152 ; IS__CGSCC____-NEXT: entry:
153 ; IS__CGSCC____-NEXT: store i32 10, i32* [[P]], align 4
154 ; IS__CGSCC____-NEXT: ret void
157 %call = call i32* @test8_1(i32* %p)
158 store i32 10, i32* %call, align 4
162 ; CHECK: declare void @llvm.masked.scatter
163 declare void @llvm.masked.scatter.v4i32.v4p0i32(<4 x i32>%val, <4 x i32*>, i32, <4 x i1>)
165 ; CHECK-NOT: readnone
166 ; CHECK-NOT: readonly
167 define void @test9(<4 x i32*> %ptrs, <4 x i32>%val) {
168 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind willreturn writeonly
169 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test9
170 ; IS__TUNIT____-SAME: (<4 x i32*> [[PTRS:%.*]], <4 x i32> [[VAL:%.*]]) #[[ATTR0]] {
171 ; IS__TUNIT____-NEXT: call void @llvm.masked.scatter.v4i32.v4p0i32(<4 x i32> [[VAL]], <4 x i32*> [[PTRS]], i32 noundef 4, <4 x i1> noundef <i1 true, i1 false, i1 true, i1 false>) #[[ATTR10:[0-9]+]]
172 ; IS__TUNIT____-NEXT: ret void
174 ; IS__CGSCC____: Function Attrs: nofree nosync nounwind willreturn writeonly
175 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test9
176 ; IS__CGSCC____-SAME: (<4 x i32*> [[PTRS:%.*]], <4 x i32> [[VAL:%.*]]) #[[ATTR4:[0-9]+]] {
177 ; IS__CGSCC____-NEXT: call void @llvm.masked.scatter.v4i32.v4p0i32(<4 x i32> [[VAL]], <4 x i32*> [[PTRS]], i32 noundef 4, <4 x i1> noundef <i1 true, i1 false, i1 true, i1 false>) #[[ATTR11:[0-9]+]]
178 ; IS__CGSCC____-NEXT: ret void
180 call void @llvm.masked.scatter.v4i32.v4p0i32(<4 x i32>%val, <4 x i32*> %ptrs, i32 4, <4 x i1><i1 true, i1 false, i1 true, i1 false>)
184 ; CHECK: declare <4 x i32> @llvm.masked.gather
185 declare <4 x i32> @llvm.masked.gather.v4i32.v4p0i32(<4 x i32*>, i32, <4 x i1>, <4 x i32>)
186 define <4 x i32> @test10(<4 x i32*> %ptrs) {
187 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readonly willreturn
188 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test10
189 ; IS__TUNIT____-SAME: (<4 x i32*> [[PTRS:%.*]]) #[[ATTR4:[0-9]+]] {
190 ; IS__TUNIT____-NEXT: [[RES:%.*]] = call <4 x i32> @llvm.masked.gather.v4i32.v4p0i32(<4 x i32*> [[PTRS]], i32 noundef 4, <4 x i1> noundef <i1 true, i1 false, i1 true, i1 false>, <4 x i32> undef) #[[ATTR11:[0-9]+]]
191 ; IS__TUNIT____-NEXT: ret <4 x i32> [[RES]]
193 ; IS__CGSCC____: Function Attrs: nofree nosync nounwind readonly willreturn
194 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test10
195 ; IS__CGSCC____-SAME: (<4 x i32*> [[PTRS:%.*]]) #[[ATTR5:[0-9]+]] {
196 ; IS__CGSCC____-NEXT: [[RES:%.*]] = call <4 x i32> @llvm.masked.gather.v4i32.v4p0i32(<4 x i32*> [[PTRS]], i32 noundef 4, <4 x i1> noundef <i1 true, i1 false, i1 true, i1 false>, <4 x i32> undef) #[[ATTR12:[0-9]+]]
197 ; IS__CGSCC____-NEXT: ret <4 x i32> [[RES]]
199 %res = call <4 x i32> @llvm.masked.gather.v4i32.v4p0i32(<4 x i32*> %ptrs, i32 4, <4 x i1><i1 true, i1 false, i1 true, i1 false>, <4 x i32>undef)
203 ; CHECK: declare <4 x i32> @test11_1
204 declare <4 x i32> @test11_1(<4 x i32*>) argmemonly nounwind readonly
205 define <4 x i32> @test11_2(<4 x i32*> %ptrs) {
206 ; IS__TUNIT____: Function Attrs: argmemonly nounwind readonly
207 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test11_2
208 ; IS__TUNIT____-SAME: (<4 x i32*> [[PTRS:%.*]]) #[[ATTR5:[0-9]+]] {
209 ; IS__TUNIT____-NEXT: [[RES:%.*]] = call <4 x i32> @test11_1(<4 x i32*> [[PTRS]]) #[[ATTR9:[0-9]+]]
210 ; IS__TUNIT____-NEXT: ret <4 x i32> [[RES]]
212 ; IS__CGSCC____: Function Attrs: argmemonly nounwind readonly
213 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test11_2
214 ; IS__CGSCC____-SAME: (<4 x i32*> [[PTRS:%.*]]) #[[ATTR6:[0-9]+]] {
215 ; IS__CGSCC____-NEXT: [[RES:%.*]] = call <4 x i32> @test11_1(<4 x i32*> [[PTRS]]) #[[ATTR10:[0-9]+]]
216 ; IS__CGSCC____-NEXT: ret <4 x i32> [[RES]]
218 %res = call <4 x i32> @test11_1(<4 x i32*> %ptrs)
222 declare <4 x i32> @test12_1(<4 x i32*>) argmemonly nounwind
223 ; CHECK-NOT: readnone
224 define <4 x i32> @test12_2(<4 x i32*> %ptrs) {
225 ; IS__TUNIT____: Function Attrs: argmemonly nounwind
226 ; IS__TUNIT____-LABEL: define {{[^@]+}}@test12_2
227 ; IS__TUNIT____-SAME: (<4 x i32*> [[PTRS:%.*]]) #[[ATTR6:[0-9]+]] {
228 ; IS__TUNIT____-NEXT: [[RES:%.*]] = call <4 x i32> @test12_1(<4 x i32*> [[PTRS]]) #[[ATTR12:[0-9]+]]
229 ; IS__TUNIT____-NEXT: ret <4 x i32> [[RES]]
231 ; IS__CGSCC____: Function Attrs: argmemonly nounwind
232 ; IS__CGSCC____-LABEL: define {{[^@]+}}@test12_2
233 ; IS__CGSCC____-SAME: (<4 x i32*> [[PTRS:%.*]]) #[[ATTR7:[0-9]+]] {
234 ; IS__CGSCC____-NEXT: [[RES:%.*]] = call <4 x i32> @test12_1(<4 x i32*> [[PTRS]]) #[[ATTR13:[0-9]+]]
235 ; IS__CGSCC____-NEXT: ret <4 x i32> [[RES]]
237 %res = call <4 x i32> @test12_1(<4 x i32*> %ptrs)
241 define i32 @volatile_load(i32* %p) {
242 ; IS__TUNIT____: Function Attrs: argmemonly nofree nounwind willreturn
243 ; IS__TUNIT____-LABEL: define {{[^@]+}}@volatile_load
244 ; IS__TUNIT____-SAME: (i32* nofree noundef align 4 [[P:%.*]]) #[[ATTR7:[0-9]+]] {
245 ; IS__TUNIT____-NEXT: [[LOAD:%.*]] = load volatile i32, i32* [[P]], align 4
246 ; IS__TUNIT____-NEXT: ret i32 [[LOAD]]
248 ; IS__CGSCC____: Function Attrs: argmemonly nofree norecurse nounwind willreturn
249 ; IS__CGSCC____-LABEL: define {{[^@]+}}@volatile_load
250 ; IS__CGSCC____-SAME: (i32* nofree noundef align 4 [[P:%.*]]) #[[ATTR8:[0-9]+]] {
251 ; IS__CGSCC____-NEXT: [[LOAD:%.*]] = load volatile i32, i32* [[P]], align 4
252 ; IS__CGSCC____-NEXT: ret i32 [[LOAD]]
254 %load = load volatile i32, i32* %p
258 declare void @escape_readnone_ptr(i8** %addr, i8* readnone %ptr)
259 declare void @escape_readonly_ptr(i8** %addr, i8* readonly %ptr)
261 ; The argument pointer %escaped_then_written cannot be marked readnone/only even
262 ; though the only direct use, in @escape_readnone_ptr/@escape_readonly_ptr,
263 ; is marked as readnone/only. However, the functions can write the pointer into
264 ; %addr, causing the store to write to %escaped_then_written.
266 define void @unsound_readnone(i8* %ignored, i8* %escaped_then_written) {
267 ; CHECK-LABEL: define {{[^@]+}}@unsound_readnone
268 ; CHECK-SAME: (i8* nocapture nofree readnone [[IGNORED:%.*]], i8* [[ESCAPED_THEN_WRITTEN:%.*]]) {
269 ; CHECK-NEXT: [[ADDR:%.*]] = alloca i8*, align 8
270 ; CHECK-NEXT: call void @escape_readnone_ptr(i8** noundef nonnull align 8 dereferenceable(8) [[ADDR]], i8* noalias readnone [[ESCAPED_THEN_WRITTEN]])
271 ; CHECK-NEXT: [[ADDR_LD:%.*]] = load i8*, i8** [[ADDR]], align 8
272 ; CHECK-NEXT: store i8 0, i8* [[ADDR_LD]], align 1
273 ; CHECK-NEXT: ret void
276 call void @escape_readnone_ptr(i8** %addr, i8* %escaped_then_written)
277 %addr.ld = load i8*, i8** %addr
278 store i8 0, i8* %addr.ld
282 define void @unsound_readonly(i8* %ignored, i8* %escaped_then_written) {
283 ; CHECK-LABEL: define {{[^@]+}}@unsound_readonly
284 ; CHECK-SAME: (i8* nocapture nofree readnone [[IGNORED:%.*]], i8* [[ESCAPED_THEN_WRITTEN:%.*]]) {
285 ; CHECK-NEXT: [[ADDR:%.*]] = alloca i8*, align 8
286 ; CHECK-NEXT: call void @escape_readonly_ptr(i8** noundef nonnull align 8 dereferenceable(8) [[ADDR]], i8* readonly [[ESCAPED_THEN_WRITTEN]])
287 ; CHECK-NEXT: [[ADDR_LD:%.*]] = load i8*, i8** [[ADDR]], align 8
288 ; CHECK-NEXT: store i8 0, i8* [[ADDR_LD]], align 1
289 ; CHECK-NEXT: ret void
292 call void @escape_readonly_ptr(i8** %addr, i8* %escaped_then_written)
293 %addr.ld = load i8*, i8** %addr
294 store i8 0, i8* %addr.ld
298 ; Byval but not readonly/none tests
301 declare void @escape_i8(i8* %ptr)
303 define void @byval_not_readonly_1(i8* byval(i8) %written) readonly {
304 ; CHECK: Function Attrs: readonly
305 ; CHECK-LABEL: define {{[^@]+}}@byval_not_readonly_1
306 ; CHECK-SAME: (i8* noalias nonnull byval(i8) dereferenceable(1) [[WRITTEN:%.*]]) #[[ATTR2]] {
307 ; CHECK-NEXT: call void @escape_i8(i8* nonnull dereferenceable(1) [[WRITTEN]])
308 ; CHECK-NEXT: ret void
310 call void @escape_i8(i8* %written)
314 define void @byval_not_readonly_2(i8* byval(i8) %written) readonly {
315 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
316 ; IS__TUNIT____-LABEL: define {{[^@]+}}@byval_not_readonly_2
317 ; IS__TUNIT____-SAME: (i8* noalias nocapture nofree noundef nonnull writeonly byval(i8) dereferenceable(1) [[WRITTEN:%.*]]) #[[ATTR1]] {
318 ; IS__TUNIT____-NEXT: store i8 0, i8* [[WRITTEN]], align 1
319 ; IS__TUNIT____-NEXT: ret void
321 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
322 ; IS__CGSCC____-LABEL: define {{[^@]+}}@byval_not_readonly_2
323 ; IS__CGSCC____-SAME: (i8* noalias nocapture nofree noundef nonnull writeonly byval(i8) dereferenceable(1) [[WRITTEN:%.*]]) #[[ATTR1]] {
324 ; IS__CGSCC____-NEXT: store i8 0, i8* [[WRITTEN]], align 1
325 ; IS__CGSCC____-NEXT: ret void
327 store i8 0, i8* %written
331 define void @byval_not_readnone_1(i8* byval(i8) %written) readnone {
332 ; IS__TUNIT____: Function Attrs: readnone
333 ; IS__TUNIT____-LABEL: define {{[^@]+}}@byval_not_readnone_1
334 ; IS__TUNIT____-SAME: (i8* noalias nonnull byval(i8) dereferenceable(1) [[WRITTEN:%.*]]) #[[ATTR8:[0-9]+]] {
335 ; IS__TUNIT____-NEXT: call void @escape_i8(i8* nonnull dereferenceable(1) [[WRITTEN]])
336 ; IS__TUNIT____-NEXT: ret void
338 ; IS__CGSCC____: Function Attrs: readnone
339 ; IS__CGSCC____-LABEL: define {{[^@]+}}@byval_not_readnone_1
340 ; IS__CGSCC____-SAME: (i8* noalias nonnull byval(i8) dereferenceable(1) [[WRITTEN:%.*]]) #[[ATTR9:[0-9]+]] {
341 ; IS__CGSCC____-NEXT: call void @escape_i8(i8* nonnull dereferenceable(1) [[WRITTEN]])
342 ; IS__CGSCC____-NEXT: ret void
344 call void @escape_i8(i8* %written)
348 define void @byval_not_readnone_2(i8* byval(i8) %written) readnone {
349 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
350 ; IS__TUNIT____-LABEL: define {{[^@]+}}@byval_not_readnone_2
351 ; IS__TUNIT____-SAME: (i8* noalias nocapture nofree noundef nonnull writeonly byval(i8) dereferenceable(1) [[WRITTEN:%.*]]) #[[ATTR1]] {
352 ; IS__TUNIT____-NEXT: store i8 0, i8* [[WRITTEN]], align 1
353 ; IS__TUNIT____-NEXT: ret void
355 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
356 ; IS__CGSCC____-LABEL: define {{[^@]+}}@byval_not_readnone_2
357 ; IS__CGSCC____-SAME: (i8* noalias nocapture nofree noundef nonnull writeonly byval(i8) dereferenceable(1) [[WRITTEN:%.*]]) #[[ATTR1]] {
358 ; IS__CGSCC____-NEXT: store i8 0, i8* [[WRITTEN]], align 1
359 ; IS__CGSCC____-NEXT: ret void
361 store i8 0, i8* %written
365 define void @byval_no_fnarg(i8* byval(i8) %written) {
366 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
367 ; IS__TUNIT____-LABEL: define {{[^@]+}}@byval_no_fnarg
368 ; IS__TUNIT____-SAME: (i8* noalias nocapture nofree noundef nonnull writeonly byval(i8) dereferenceable(1) [[WRITTEN:%.*]]) #[[ATTR1]] {
369 ; IS__TUNIT____-NEXT: store i8 0, i8* [[WRITTEN]], align 1
370 ; IS__TUNIT____-NEXT: ret void
372 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
373 ; IS__CGSCC____-LABEL: define {{[^@]+}}@byval_no_fnarg
374 ; IS__CGSCC____-SAME: (i8* noalias nocapture nofree noundef nonnull writeonly byval(i8) dereferenceable(1) [[WRITTEN:%.*]]) #[[ATTR1]] {
375 ; IS__CGSCC____-NEXT: store i8 0, i8* [[WRITTEN]], align 1
376 ; IS__CGSCC____-NEXT: ret void
378 store i8 0, i8* %written
382 define void @testbyval(i8* %read_only) {
383 ; IS__TUNIT____-LABEL: define {{[^@]+}}@testbyval
384 ; IS__TUNIT____-SAME: (i8* nocapture readonly [[READ_ONLY:%.*]]) {
385 ; IS__TUNIT____-NEXT: call void @byval_not_readonly_1(i8* nocapture readonly byval(i8) [[READ_ONLY]]) #[[ATTR2]]
386 ; IS__TUNIT____-NEXT: call void @byval_not_readnone_1(i8* noalias nocapture readnone byval(i8) [[READ_ONLY]])
387 ; IS__TUNIT____-NEXT: ret void
389 ; IS__CGSCC____: Function Attrs: readonly
390 ; IS__CGSCC____-LABEL: define {{[^@]+}}@testbyval
391 ; IS__CGSCC____-SAME: (i8* nocapture noundef nonnull readonly dereferenceable(1) [[READ_ONLY:%.*]]) #[[ATTR2]] {
392 ; IS__CGSCC____-NEXT: call void @byval_not_readonly_1(i8* noalias nocapture noundef nonnull readonly byval(i8) dereferenceable(1) [[READ_ONLY]]) #[[ATTR2]]
393 ; IS__CGSCC____-NEXT: call void @byval_not_readnone_1(i8* noalias nocapture noundef nonnull readnone byval(i8) dereferenceable(1) [[READ_ONLY]])
394 ; IS__CGSCC____-NEXT: ret void
396 call void @byval_not_readonly_1(i8* byval(i8) %read_only)
397 call void @byval_not_readonly_2(i8* byval(i8) %read_only)
398 call void @byval_not_readnone_1(i8* byval(i8) %read_only)
399 call void @byval_not_readnone_2(i8* byval(i8) %read_only)
400 call void @byval_no_fnarg(i8* byval(i8) %read_only)
405 declare i8* @maybe_returned_ptr(i8* readonly %ptr) readonly nounwind
406 declare i8 @maybe_returned_val(i8* %ptr) readonly nounwind
407 declare void @val_use(i8 %ptr) readonly nounwind
409 define void @ptr_uses(i8* %ptr) {
410 ; IS__TUNIT____: Function Attrs: nounwind readonly
411 ; IS__TUNIT____-LABEL: define {{[^@]+}}@ptr_uses
412 ; IS__TUNIT____-SAME: (i8* nocapture readonly [[PTR:%.*]]) #[[ATTR9]] {
413 ; IS__TUNIT____-NEXT: [[CALL_PTR:%.*]] = call i8* @maybe_returned_ptr(i8* readonly [[PTR]]) #[[ATTR9]]
414 ; IS__TUNIT____-NEXT: [[CALL_VAL:%.*]] = call i8 @maybe_returned_val(i8* readonly [[CALL_PTR]]) #[[ATTR9]]
415 ; IS__TUNIT____-NEXT: ret void
417 ; IS__CGSCC____: Function Attrs: nounwind readonly
418 ; IS__CGSCC____-LABEL: define {{[^@]+}}@ptr_uses
419 ; IS__CGSCC____-SAME: (i8* nocapture readonly [[PTR:%.*]]) #[[ATTR10]] {
420 ; IS__CGSCC____-NEXT: [[CALL_PTR:%.*]] = call i8* @maybe_returned_ptr(i8* readonly [[PTR]]) #[[ATTR10]]
421 ; IS__CGSCC____-NEXT: [[CALL_VAL:%.*]] = call i8 @maybe_returned_val(i8* readonly [[CALL_PTR]]) #[[ATTR10]]
422 ; IS__CGSCC____-NEXT: ret void
424 %call_ptr = call i8* @maybe_returned_ptr(i8* %ptr)
425 %call_val = call i8 @maybe_returned_val(i8* %call_ptr)
426 call void @val_use(i8 %call_val)
430 define void @ptr_use_chain(i8* %ptr) {
431 ; CHECK-LABEL: define {{[^@]+}}@ptr_use_chain
432 ; CHECK-SAME: (i8* [[PTR:%.*]]) {
433 ; CHECK-NEXT: call void @escape_i8(i8* [[PTR]])
434 ; CHECK-NEXT: ret void
436 %bc0 = bitcast i8* %ptr to i32*
437 %bc1 = bitcast i32* %bc0 to i8*
438 %bc2 = bitcast i8* %bc1 to i32*
439 %bc3 = bitcast i32* %bc2 to i8*
440 %bc4 = bitcast i8* %bc3 to i32*
441 %bc5 = bitcast i32* %bc4 to i8*
442 %bc6 = bitcast i8* %bc5 to i32*
443 %bc7 = bitcast i32* %bc6 to i8*
444 %bc8 = bitcast i8* %bc7 to i32*
445 %bc9 = bitcast i32* %bc8 to i8*
446 %abc2 = bitcast i8* %bc9 to i32*
447 %abc3 = bitcast i32* %abc2 to i8*
448 %abc4 = bitcast i8* %abc3 to i32*
449 %abc5 = bitcast i32* %abc4 to i8*
450 %abc6 = bitcast i8* %abc5 to i32*
451 %abc7 = bitcast i32* %abc6 to i8*
452 %abc8 = bitcast i8* %abc7 to i32*
453 %abc9 = bitcast i32* %abc8 to i8*
454 call void @escape_i8(i8* %abc9)
458 @constant_mem = external dso_local constant i32, align 4
459 define i32 @read_only_constant_mem() {
460 ; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
461 ; IS__TUNIT____-LABEL: define {{[^@]+}}@read_only_constant_mem
462 ; IS__TUNIT____-SAME: () #[[ATTR1]] {
463 ; IS__TUNIT____-NEXT: [[L:%.*]] = load i32, i32* @constant_mem, align 4
464 ; IS__TUNIT____-NEXT: ret i32 [[L]]
466 ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
467 ; IS__CGSCC____-LABEL: define {{[^@]+}}@read_only_constant_mem
468 ; IS__CGSCC____-SAME: () #[[ATTR1]] {
469 ; IS__CGSCC____-NEXT: [[L:%.*]] = load i32, i32* @constant_mem, align 4
470 ; IS__CGSCC____-NEXT: ret i32 [[L]]
472 %l = load i32, i32* @constant_mem
476 ; IS__TUNIT____: attributes #[[ATTR0]] = { nofree nosync nounwind willreturn writeonly }
477 ; IS__TUNIT____: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn }
478 ; IS__TUNIT____: attributes #[[ATTR2]] = { readonly }
479 ; IS__TUNIT____: attributes #[[ATTR3]] = { argmemonly nofree nosync nounwind willreturn writeonly }
480 ; IS__TUNIT____: attributes #[[ATTR4]] = { nofree nosync nounwind readonly willreturn }
481 ; IS__TUNIT____: attributes #[[ATTR5]] = { argmemonly nounwind readonly }
482 ; IS__TUNIT____: attributes #[[ATTR6]] = { argmemonly nounwind }
483 ; IS__TUNIT____: attributes #[[ATTR7]] = { argmemonly nofree nounwind willreturn }
484 ; IS__TUNIT____: attributes #[[ATTR8]] = { readnone }
485 ; IS__TUNIT____: attributes #[[ATTR9]] = { nounwind readonly }
486 ; IS__TUNIT____: attributes #[[ATTR10]] = { willreturn writeonly }
487 ; IS__TUNIT____: attributes #[[ATTR11]] = { readonly willreturn }
488 ; IS__TUNIT____: attributes #[[ATTR12]] = { nounwind }
490 ; IS__CGSCC____: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind willreturn writeonly }
491 ; IS__CGSCC____: attributes #[[ATTR1]] = { nofree norecurse nosync nounwind readnone willreturn }
492 ; IS__CGSCC____: attributes #[[ATTR2]] = { readonly }
493 ; IS__CGSCC____: attributes #[[ATTR3]] = { argmemonly nofree norecurse nosync nounwind willreturn writeonly }
494 ; IS__CGSCC____: attributes #[[ATTR4]] = { nofree nosync nounwind willreturn writeonly }
495 ; IS__CGSCC____: attributes #[[ATTR5]] = { nofree nosync nounwind readonly willreturn }
496 ; IS__CGSCC____: attributes #[[ATTR6]] = { argmemonly nounwind readonly }
497 ; IS__CGSCC____: attributes #[[ATTR7]] = { argmemonly nounwind }
498 ; IS__CGSCC____: attributes #[[ATTR8]] = { argmemonly nofree norecurse nounwind willreturn }
499 ; IS__CGSCC____: attributes #[[ATTR9]] = { readnone }
500 ; IS__CGSCC____: attributes #[[ATTR10]] = { nounwind readonly }
501 ; IS__CGSCC____: attributes #[[ATTR11]] = { willreturn writeonly }
502 ; IS__CGSCC____: attributes #[[ATTR12]] = { readonly willreturn }
503 ; IS__CGSCC____: attributes #[[ATTR13]] = { nounwind }