1 ; RUN: opt < %s -function-attrs -S | FileCheck %s
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes='cgscc(function-attrs)' -S | FileCheck %s
6 declare void @test1_1(i8* %x1_1, i8* readonly %y1_1, ...)
8 ; NOTE: readonly for %y1_2 would be OK here but not for the similar situation in test13.
10 ; CHECK: define void @test1_2(i8* %x1_2, i8* readonly %y1_2, i8* %z1_2)
11 define void @test1_2(i8* %x1_2, i8* %y1_2, i8* %z1_2) {
12 call void (i8*, i8*, ...) @test1_1(i8* %x1_2, i8* %y1_2, i8* %z1_2)
17 ; CHECK: define i8* @test2(i8* readnone returned %p)
18 define i8* @test2(i8* %p) {
23 ; CHECK: define i1 @test3(i8* readnone %p, i8* readnone %q)
24 define i1 @test3(i8* %p, i8* %q) {
25 %A = icmp ult i8* %p, %q
29 declare void @test4_1(i8* nocapture) readonly
31 ; CHECK: define void @test4_2(i8* nocapture readonly %p)
32 define void @test4_2(i8* %p) {
33 call void @test4_1(i8* %p)
37 ; CHECK: define void @test5(i8** nocapture %p, i8* %q)
38 ; Missed optz'n: we could make %q readnone, but don't break test6!
39 define void @test5(i8** %p, i8* %q) {
44 declare void @test6_1()
45 ; CHECK: define void @test6_2(i8** nocapture %p, i8* %q)
46 ; This is not a missed optz'n.
47 define void @test6_2(i8** %p, i8* %q) {
53 ; CHECK: define void @test7_1(i32* nocapture inalloca(i32) %a)
54 ; inalloca parameters are always considered written
55 define void @test7_1(i32* inalloca(i32) %a) {
59 ; CHECK: define void @test7_2(i32* nocapture preallocated(i32) %a)
60 ; preallocated parameters are always considered written
61 define void @test7_2(i32* preallocated(i32) %a) {
65 ; CHECK: define i32* @test8_1(i32* readnone returned %p)
66 define i32* @test8_1(i32* %p) {
71 ; CHECK: define void @test8_2(i32* %p)
72 define void @test8_2(i32* %p) {
74 %call = call i32* @test8_1(i32* %p)
75 store i32 10, i32* %call, align 4
79 ; CHECK: declare void @llvm.masked.scatter
80 declare void @llvm.masked.scatter.v4i32.v4p0i32(<4 x i32>%val, <4 x i32*>, i32, <4 x i1>)
84 ; CHECK: define void @test9
85 define void @test9(<4 x i32*> %ptrs, <4 x i32>%val) {
86 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>)
90 ; CHECK: declare <4 x i32> @llvm.masked.gather
91 declare <4 x i32> @llvm.masked.gather.v4i32.v4p0i32(<4 x i32*>, i32, <4 x i1>, <4 x i32>)
93 ; CHECK: define <4 x i32> @test10
94 define <4 x i32> @test10(<4 x i32*> %ptrs) {
95 %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)
99 ; CHECK: declare <4 x i32> @test11_1
100 declare <4 x i32> @test11_1(<4 x i32*>) argmemonly nounwind readonly
102 ; CHECK-NOT: readnone
103 ; CHECK: define <4 x i32> @test11_2
104 define <4 x i32> @test11_2(<4 x i32*> %ptrs) {
105 %res = call <4 x i32> @test11_1(<4 x i32*> %ptrs)
109 declare <4 x i32> @test12_1(<4 x i32*>) argmemonly nounwind
110 ; CHECK-NOT: readnone
111 ; CHECK: define <4 x i32> @test12_2
112 define <4 x i32> @test12_2(<4 x i32*> %ptrs) {
113 %res = call <4 x i32> @test12_1(<4 x i32*> %ptrs)
117 ; CHECK: define i32 @volatile_load(
118 ; CHECK-NOT: readonly
120 define i32 @volatile_load(i32* %p) {
121 %load = load volatile i32, i32* %p
125 declare void @escape_readnone_ptr(i8** %addr, i8* readnone %ptr)
126 declare void @escape_readonly_ptr(i8** %addr, i8* readonly %ptr)
128 ; The argument pointer %escaped_then_written cannot be marked readnone/only even
129 ; though the only direct use, in @escape_readnone_ptr/@escape_readonly_ptr,
130 ; is marked as readnone/only. However, the functions can write the pointer into
131 ; %addr, causing the store to write to %escaped_then_written.
133 ; FIXME: This test currently exposes a bug in function-attrs!
135 ; CHECK: define void @unsound_readnone(i8* nocapture readnone %ignored, i8* readnone %escaped_then_written)
136 ; CHECK: define void @unsound_readonly(i8* nocapture readnone %ignored, i8* readonly %escaped_then_written)
138 define void @unsound_readnone(i8* %ignored, i8* %escaped_then_written) {
140 call void @escape_readnone_ptr(i8** %addr, i8* %escaped_then_written)
141 %addr.ld = load i8*, i8** %addr
142 store i8 0, i8* %addr.ld
146 define void @unsound_readonly(i8* %ignored, i8* %escaped_then_written) {
148 call void @escape_readonly_ptr(i8** %addr, i8* %escaped_then_written)
149 %addr.ld = load i8*, i8** %addr
150 store i8 0, i8* %addr.ld