1; RUN: opt < %s -aa-pipeline=tbaa,basic-aa -passes=function-attrs -S | FileCheck %s 2 3; FunctionAttrs should make use of TBAA. 4 5; Add the readnone attribute, since the only access is a store which TBAA 6; says is to constant memory. 7; 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. 11 12; CHECK: define void @test0_yes(i32* nocapture %p) #0 { 13define void @test0_yes(i32* %p) nounwind { 14 store i32 0, i32* %p, !tbaa !1 15 ret void 16} 17 18; CHECK: define void @test0_no(i32* nocapture writeonly %p) #1 { 19define void @test0_no(i32* %p) nounwind { 20 store i32 0, i32* %p, !tbaa !2 21 ret void 22} 23 24; Add the readonly attribute, since there's just a call to a function which 25; TBAA says doesn't modify any memory. 26 27; CHECK: define void @test1_yes(i32* nocapture %p) #2 { 28define void @test1_yes(i32* %p) nounwind { 29 call void @callee(i32* %p), !tbaa !1 30 ret void 31} 32 33; CHECK: define void @test1_no(i32* %p) #3 { 34define void @test1_no(i32* %p) nounwind { 35 call void @callee(i32* %p), !tbaa !2 36 ret void 37} 38 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. 42; 43; This is unusual, since the function is memcpy, but as above, this 44; isn't necessarily invalid. 45 46; CHECK: define void @test2_yes(i8* nocapture %p, i8* nocapture %q, i64 %n) #4 { 47define void @test2_yes(i8* %p, i8* %q, i64 %n) nounwind { 48 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %p, i8* %q, i64 %n, i1 false), !tbaa !1 49 ret void 50} 51 52; CHECK: define void @test2_no(i8* nocapture writeonly %p, i8* nocapture readonly %q, i64 %n) #5 { 53define void @test2_no(i8* %p, i8* %q, i64 %n) nounwind { 54 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %p, i8* %q, i64 %n, i1 false), !tbaa !2 55 ret void 56} 57 58; Similar to the others, va_arg only accesses memory through its operand. 59 60; CHECK: define i32 @test3_yes(i8* nocapture %p) #0 { 61define i32 @test3_yes(i8* %p) nounwind { 62 %t = va_arg i8* %p, i32, !tbaa !1 63 ret i32 %t 64} 65 66; CHECK: define i32 @test3_no(i8* nocapture %p) #6 { 67define i32 @test3_no(i8* %p) nounwind { 68 %t = va_arg i8* %p, i32, !tbaa !2 69 ret i32 %t 70} 71 72declare void @callee(i32* %p) nounwind 73declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i1) nounwind 74 75; CHECK: attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone willreturn } 76; CHECK: attributes #1 = { argmemonly mustprogress nofree norecurse nosync nounwind willreturn writeonly } 77; CHECK: attributes #2 = { nofree nounwind readonly } 78; CHECK: attributes #3 = { nounwind } 79; CHECK: attributes #4 = { mustprogress nofree nosync nounwind readnone willreturn } 80; CHECK: attributes #5 = { argmemonly mustprogress nofree nosync nounwind willreturn } 81; CHECK: attributes #6 = { argmemonly mustprogress nofree norecurse nosync nounwind willreturn } 82; CHECK: attributes #7 = { argmemonly nocallback nofree nounwind willreturn } 83 84; Root note. 85!0 = !{ } 86 87; Invariant memory. 88!1 = !{!3, !3, i64 0, i1 1 } 89; Not invariant memory. 90!2 = !{!3, !3, i64 0, i1 0 } 91!3 = !{ !"foo", !0 } 92