• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -functionattrs -S | FileCheck %s
2; RUN: opt < %s -aa-pipeline=basic-aa -passes='cgscc(function-attrs)' -S | FileCheck %s
3@x = global i32 0
4
5declare void @test1_1(i8* %x1_1, i8* readonly %y1_1, ...)
6
7; CHECK: define void @test1_2(i8* %x1_2, i8* readonly %y1_2, i8* %z1_2)
8define void @test1_2(i8* %x1_2, i8* %y1_2, i8* %z1_2) {
9  call void (i8*, i8*, ...) @test1_1(i8* %x1_2, i8* %y1_2, i8* %z1_2)
10  store i32 0, i32* @x
11  ret void
12}
13
14; CHECK: define i8* @test2(i8* readnone %p)
15define i8* @test2(i8* %p) {
16  store i32 0, i32* @x
17  ret i8* %p
18}
19
20; CHECK: define i1 @test3(i8* readnone %p, i8* readnone %q)
21define i1 @test3(i8* %p, i8* %q) {
22  %A = icmp ult i8* %p, %q
23  ret i1 %A
24}
25
26declare void @test4_1(i8* nocapture) readonly
27
28; CHECK: define void @test4_2(i8* nocapture readonly %p)
29define void @test4_2(i8* %p) {
30  call void @test4_1(i8* %p)
31  ret void
32}
33
34; CHECK: define void @test5(i8** nocapture %p, i8* %q)
35; Missed optz'n: we could make %q readnone, but don't break test6!
36define void @test5(i8** %p, i8* %q) {
37  store i8* %q, i8** %p
38  ret void
39}
40
41declare void @test6_1()
42; CHECK: define void @test6_2(i8** nocapture %p, i8* %q)
43; This is not a missed optz'n.
44define void @test6_2(i8** %p, i8* %q) {
45  store i8* %q, i8** %p
46  call void @test6_1()
47  ret void
48}
49
50; CHECK: define void @test7_1(i32* inalloca nocapture %a)
51; inalloca parameters are always considered written
52define void @test7_1(i32* inalloca %a) {
53  ret void
54}
55
56; CHECK: define i32* @test8_1(i32* readnone %p)
57define i32* @test8_1(i32* %p) {
58entry:
59  ret i32* %p
60}
61
62; CHECK: define void @test8_2(i32* %p)
63define void @test8_2(i32* %p) {
64entry:
65  %call = call i32* @test8_1(i32* %p)
66  store i32 10, i32* %call, align 4
67  ret void
68}
69
70; CHECK: declare void @llvm.masked.scatter
71declare void @llvm.masked.scatter.v4i32(<4 x i32>%val, <4 x i32*>, i32, <4 x i1>)
72
73; CHECK-NOT: readnone
74; CHECK-NOT: readonly
75; CHECK: define void @test9
76define void @test9(<4 x i32*> %ptrs, <4 x i32>%val) {
77  call void @llvm.masked.scatter.v4i32(<4 x i32>%val, <4 x i32*> %ptrs, i32 4, <4 x i1><i1 true, i1 false, i1 true, i1 false>)
78  ret void
79}
80
81; CHECK: declare <4 x i32> @llvm.masked.gather
82declare <4 x i32> @llvm.masked.gather.v4i32(<4 x i32*>, i32, <4 x i1>, <4 x i32>)
83; CHECK: readonly
84; CHECK: define <4 x i32> @test10
85define <4 x i32> @test10(<4 x i32*> %ptrs) {
86  %res = call <4 x i32> @llvm.masked.gather.v4i32(<4 x i32*> %ptrs, i32 4, <4 x i1><i1 true, i1 false, i1 true, i1 false>, <4 x i32>undef)
87  ret <4 x i32> %res
88}
89
90; CHECK: declare <4 x i32> @test11_1
91declare <4 x i32> @test11_1(<4 x i32*>) argmemonly nounwind readonly
92; CHECK: readonly
93; CHECK-NOT: readnone
94; CHECK: define <4 x i32> @test11_2
95define <4 x i32> @test11_2(<4 x i32*> %ptrs) {
96  %res = call <4 x i32> @test11_1(<4 x i32*> %ptrs)
97  ret <4 x i32> %res
98}
99
100declare <4 x i32> @test12_1(<4 x i32*>) argmemonly nounwind
101; CHECK-NOT: readnone
102; CHECK: define <4 x i32> @test12_2
103define <4 x i32> @test12_2(<4 x i32*> %ptrs) {
104  %res = call <4 x i32> @test12_1(<4 x i32*> %ptrs)
105  ret <4 x i32> %res
106}
107
108; CHECK: define i32 @volatile_load(
109; CHECK-NOT: readonly
110; CHECK: ret
111define i32 @volatile_load(i32* %p) {
112  %load = load volatile i32, i32* %p
113  ret i32 %load
114}
115