1 ; RUN: opt < %s -functionattrs -S | FileCheck %s --check-prefixes=CHECK,FNATTR
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes='cgscc(function-attrs)' -S | FileCheck %s --check-prefixes=CHECK,FNATTR
3 ; RUN: opt < %s -attributor -attributor-disable=false -S | FileCheck %s --check-prefixes=CHECK,ATTRIBUTOR
4 ; RUN: opt < %s -aa-pipeline=basic-aa -passes='attributor' -attributor-disable=false -S | FileCheck %s --check-prefixes=CHECK,ATTRIBUTOR
8 declare void @test1_1(i8* %x1_1, i8* readonly %y1_1, ...)
10 ; NOTE: readonly for %y1_2 would be OK here but not for the similar situation in test13.
12 ; FNATTR: define void @test1_2(i8* %x1_2, i8* readonly %y1_2, i8* %z1_2)
13 ; ATTRIBUTOR: define void @test1_2(i8* %x1_2, i8* %y1_2, i8* %z1_2)
14 define void @test1_2(i8* %x1_2, i8* %y1_2, i8* %z1_2) {
15 call void (i8*, i8*, ...) @test1_1(i8* %x1_2, i8* %y1_2, i8* %z1_2)
20 ; FNATTR: define i8* @test2(i8* readnone returned %p)
21 ; ATTRIBUTOR: define i8* @test2(i8* readnone returned %p)
22 define i8* @test2(i8* %p) {
27 ; CHECK: define i1 @test3(i8* readnone %p, i8* readnone %q)
28 define i1 @test3(i8* %p, i8* %q) {
29 %A = icmp ult i8* %p, %q
33 declare void @test4_1(i8* nocapture) readonly
35 ; CHECK: define void @test4_2(i8* nocapture readonly %p)
36 define void @test4_2(i8* %p) {
37 call void @test4_1(i8* %p)
41 ; FNATTR: define void @test5(i8** nocapture %p, i8* %q)
42 ; ATTRIBUTOR: define void @test5(i8** nocapture nonnull writeonly dereferenceable(8) %p, i8* writeonly %q)
43 ; Missed optz'n: we could make %q readnone, but don't break test6!
44 define void @test5(i8** %p, i8* %q) {
49 declare void @test6_1()
50 ; FNATTR: define void @test6_2(i8** nocapture %p, i8* %q)
51 ; ATTRIBUTOR: define void @test6_2(i8** nocapture nonnull writeonly dereferenceable(8) %p, i8* %q)
52 ; This is not a missed optz'n.
53 define void @test6_2(i8** %p, i8* %q) {
59 ; FNATTR: define void @test7_1(i32* inalloca nocapture %a)
60 ; ATTRIBUTOR: define void @test7_1(i32* inalloca nocapture writeonly %a)
61 ; inalloca parameters are always considered written
62 define void @test7_1(i32* inalloca %a) {
66 ; FNATTR: define i32* @test8_1(i32* readnone returned %p)
67 ; ATTRIBUTOR: define i32* @test8_1(i32* readnone returned %p)
68 define i32* @test8_1(i32* %p) {
73 ; FNATTR: define void @test8_2(i32* %p)
74 ; ATTRIBUTOR: define void @test8_2(i32* nocapture writeonly %p)
75 define void @test8_2(i32* %p) {
77 %call = call i32* @test8_1(i32* %p)
78 store i32 10, i32* %call, align 4
82 ; CHECK: declare void @llvm.masked.scatter
83 declare void @llvm.masked.scatter.v4i32.v4p0i32(<4 x i32>%val, <4 x i32*>, i32, <4 x i1>)
87 ; CHECK: define void @test9
88 define void @test9(<4 x i32*> %ptrs, <4 x i32>%val) {
89 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>)
93 ; CHECK: declare <4 x i32> @llvm.masked.gather
94 declare <4 x i32> @llvm.masked.gather.v4i32.v4p0i32(<4 x i32*>, i32, <4 x i1>, <4 x i32>)
96 ; CHECK: define <4 x i32> @test10
97 define <4 x i32> @test10(<4 x i32*> %ptrs) {
98 %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)
102 ; CHECK: declare <4 x i32> @test11_1
103 declare <4 x i32> @test11_1(<4 x i32*>) argmemonly nounwind readonly
105 ; CHECK-NOT: readnone
106 ; CHECK: define <4 x i32> @test11_2
107 define <4 x i32> @test11_2(<4 x i32*> %ptrs) {
108 %res = call <4 x i32> @test11_1(<4 x i32*> %ptrs)
112 declare <4 x i32> @test12_1(<4 x i32*>) argmemonly nounwind
113 ; CHECK-NOT: readnone
114 ; CHECK: define <4 x i32> @test12_2
115 define <4 x i32> @test12_2(<4 x i32*> %ptrs) {
116 %res = call <4 x i32> @test12_1(<4 x i32*> %ptrs)
120 ; CHECK: define i32 @volatile_load(
121 ; CHECK-NOT: readonly
123 define i32 @volatile_load(i32* %p) {
124 %load = load volatile i32, i32* %p
128 declare void @escape_readnone_ptr(i8** %addr, i8* readnone %ptr)
129 declare void @escape_readonly_ptr(i8** %addr, i8* readonly %ptr)
131 ; The argument pointer %escaped_then_written cannot be marked readnone/only even
132 ; though the only direct use, in @escape_readnone_ptr/@escape_readonly_ptr,
133 ; is marked as readnone/only. However, the functions can write the pointer into
134 ; %addr, causing the store to write to %escaped_then_written.
136 ; FIXME: This test currently exposes a bug in functionattrs!
138 ; FNATTR: define void @unsound_readnone(i8* nocapture readnone %ignored, i8* readnone %escaped_then_written)
139 ; FNATTR: define void @unsound_readonly(i8* nocapture readnone %ignored, i8* readonly %escaped_then_written)
141 ; ATTRIBUTOR: define void @unsound_readnone(i8* nocapture readnone %ignored, i8* %escaped_then_written)
142 ; ATTRIBUTOR: define void @unsound_readonly(i8* nocapture readnone %ignored, i8* %escaped_then_written)
143 define void @unsound_readnone(i8* %ignored, i8* %escaped_then_written) {
145 call void @escape_readnone_ptr(i8** %addr, i8* %escaped_then_written)
146 %addr.ld = load i8*, i8** %addr
147 store i8 0, i8* %addr.ld
151 define void @unsound_readonly(i8* %ignored, i8* %escaped_then_written) {
153 call void @escape_readonly_ptr(i8** %addr, i8* %escaped_then_written)
154 %addr.ld = load i8*, i8** %addr
155 store i8 0, i8* %addr.ld