1 ; RUN: opt < %s -aa-pipeline=tbaa,basic-aa -passes=function-attrs -S | FileCheck %s
3 ; FunctionAttrs should make use of TBAA.
5 ; Add the readnone attribute, since the only access is a store which TBAA
6 ; says is to constant memory.
8 ; It's unusual to see a store to constant memory, but it isn't necessarily
9 ; invalid, as it's possible that this only happens after optimization on a
10 ; code path which isn't ever executed.
12 ; CHECK: define void @test0_yes(ptr nocapture %p) #0 {
13 define void @test0_yes(ptr %p) nounwind {
14 store i32 0, ptr %p, !tbaa !1
18 ; CHECK: define void @test0_no(ptr nocapture writeonly %p) #1 {
19 define void @test0_no(ptr %p) nounwind {
20 store i32 0, ptr %p, !tbaa !2
24 ; Add the readnone attribute, since there's just a call to a function which
25 ; TBAA says only accesses constant memory.
27 ; CHECK: define void @test1_yes(ptr nocapture %p) #2 {
28 define void @test1_yes(ptr %p) nounwind {
29 call void @callee(ptr %p), !tbaa !1
33 ; CHECK: define void @test1_no(ptr %p) #3 {
34 define void @test1_no(ptr %p) nounwind {
35 call void @callee(ptr %p), !tbaa !2
39 ; Add the readonly attribute, as above, but this time BasicAA will say
40 ; that the function accesses memory through its arguments, which TBAA
41 ; still says that the function doesn't write to memory.
43 ; This is unusual, since the function is memcpy, but as above, this
44 ; isn't necessarily invalid.
46 ; CHECK: define void @test2_yes(ptr nocapture %p, ptr nocapture %q, i64 %n) #0 {
47 define void @test2_yes(ptr %p, ptr %q, i64 %n) nounwind {
48 call void @llvm.memcpy.p0.p0.i64(ptr %p, ptr %q, i64 %n, i1 false), !tbaa !1
52 ; CHECK: define void @test2_no(ptr nocapture writeonly %p, ptr nocapture readonly %q, i64 %n) #4 {
53 define void @test2_no(ptr %p, ptr %q, i64 %n) nounwind {
54 call void @llvm.memcpy.p0.p0.i64(ptr %p, ptr %q, i64 %n, i1 false), !tbaa !2
58 ; Similar to the others, va_arg only accesses memory through its operand.
60 ; CHECK: define i32 @test3_yes(ptr nocapture %p) #0 {
61 define i32 @test3_yes(ptr %p) nounwind {
62 %t = va_arg ptr %p, i32, !tbaa !1
66 ; CHECK: define i32 @test3_no(ptr nocapture %p) #4 {
67 define i32 @test3_no(ptr %p) nounwind {
68 %t = va_arg ptr %p, i32, !tbaa !2
72 declare void @callee(ptr %p) nounwind
73 declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1) nounwind
75 ; CHECK: attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
76 ; CHECK: attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }
77 ; CHECK: attributes #2 = { nofree nosync nounwind memory(none) }
78 ; CHECK: attributes #3 = { nounwind }
79 ; CHECK: attributes #4 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) }
80 ; CHECK: attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
86 !1 = !{!3, !3, i64 0, i1 1 }
87 ; Not invariant memory.
88 !2 = !{!3, !3, i64 0, i1 0 }