functionattrs.ll 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ; RUN: opt < %s -tbaa -basicaa -functionattrs -S | FileCheck %s
  2. ; FunctionAttrs should make use of TBAA.
  3. ; Add the readnone attribute, since the only access is a store which TBAA
  4. ; says is to constant memory.
  5. ;
  6. ; It's unusual to see a store to constant memory, but it isn't necessarily
  7. ; invalid, as it's possible that this only happens after optimization on a
  8. ; code path which isn't ever executed.
  9. ; CHECK: define void @test0_yes(i32* nocapture %p) #0 {
  10. define void @test0_yes(i32* %p) nounwind {
  11. store i32 0, i32* %p, !tbaa !1
  12. ret void
  13. }
  14. ; CHECK: define void @test0_no(i32* nocapture %p) #1 {
  15. define void @test0_no(i32* %p) nounwind {
  16. store i32 0, i32* %p, !tbaa !2
  17. ret void
  18. }
  19. ; Add the readonly attribute, since there's just a call to a function which
  20. ; TBAA says doesn't modify any memory.
  21. ; CHECK: define void @test1_yes(i32* nocapture %p) #2 {
  22. define void @test1_yes(i32* %p) nounwind {
  23. call void @callee(i32* %p), !tbaa !1
  24. ret void
  25. }
  26. ; CHECK: define void @test1_no(i32* %p) #1 {
  27. define void @test1_no(i32* %p) nounwind {
  28. call void @callee(i32* %p), !tbaa !2
  29. ret void
  30. }
  31. ; Add the readonly attribute, as above, but this time BasicAA will say
  32. ; that the function accesses memory through its arguments, which TBAA
  33. ; still says that the function doesn't write to memory.
  34. ;
  35. ; This is unusual, since the function is memcpy, but as above, this
  36. ; isn't necessarily invalid.
  37. ; CHECK: define void @test2_yes(i8* nocapture %p, i8* nocapture %q, i64 %n) #0 {
  38. define void @test2_yes(i8* %p, i8* %q, i64 %n) nounwind {
  39. call void @llvm.memcpy.p0i8.p0i8.i64(i8* %p, i8* %q, i64 %n, i32 1, i1 false), !tbaa !1
  40. ret void
  41. }
  42. ; CHECK: define void @test2_no(i8* nocapture %p, i8* nocapture readonly %q, i64 %n) #1 {
  43. define void @test2_no(i8* %p, i8* %q, i64 %n) nounwind {
  44. call void @llvm.memcpy.p0i8.p0i8.i64(i8* %p, i8* %q, i64 %n, i32 1, i1 false), !tbaa !2
  45. ret void
  46. }
  47. ; Similar to the others, va_arg only accesses memory through its operand.
  48. ; CHECK: define i32 @test3_yes(i8* nocapture %p) #0 {
  49. define i32 @test3_yes(i8* %p) nounwind {
  50. %t = va_arg i8* %p, i32, !tbaa !1
  51. ret i32 %t
  52. }
  53. ; CHECK: define i32 @test3_no(i8* nocapture %p) #1 {
  54. define i32 @test3_no(i8* %p) nounwind {
  55. %t = va_arg i8* %p, i32, !tbaa !2
  56. ret i32 %t
  57. }
  58. declare void @callee(i32* %p) nounwind
  59. declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i32, i1) nounwind
  60. ; CHECK: attributes #0 = { nounwind readnone }
  61. ; CHECK: attributes #1 = { nounwind }
  62. ; CHECK: attributes #2 = { nounwind readonly }
  63. ; Root note.
  64. !0 = !{ }
  65. ; Invariant memory.
  66. !1 = !{!3, !3, i64 0, i1 1 }
  67. ; Not invariant memory.
  68. !2 = !{!3, !3, i64 0, i1 0 }
  69. !3 = !{ !"foo", !0 }