2
0

placement-tbaa.ll 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ; RUN: opt < %s -tbaa -basicaa -aa-eval -evaluate-aa-metadata -print-no-aliases -print-may-aliases -disable-output 2>&1 | FileCheck %s
  2. ; Generated with "clang -cc1 -disable-llvm-optzns -O1 -emit-llvm"
  3. ; #include <new>
  4. ; struct Foo { long i; };
  5. ; struct Bar { void *p; };
  6. ; long foo(int n) {
  7. ; Foo *f = new Foo;
  8. ; f->i = 1;
  9. ; for (int i=0; i<n; ++i) {
  10. ; Bar *b = new (f) Bar;
  11. ; b->p = 0;
  12. ; f = new (f) Foo;
  13. ; f->i = i;
  14. ; }
  15. ; return f->i;
  16. ; }
  17. ; Basic AA says MayAlias, TBAA says NoAlias
  18. ; CHECK: MayAlias: i64* %i5, i8** %p
  19. ; CHECK: NoAlias: store i64 %conv, i64* %i5, align 8, !tbaa !6 <-> store i8* null, i8** %p, align 8, !tbaa !9
  20. %struct.Foo = type { i64 }
  21. %struct.Bar = type { i8* }
  22. define i64 @_Z3fooi(i32 %n) #0 {
  23. entry:
  24. %n.addr = alloca i32, align 4
  25. %f = alloca %struct.Foo*, align 8
  26. %i1 = alloca i32, align 4
  27. %b = alloca %struct.Bar*, align 8
  28. store i32 %n, i32* %n.addr, align 4, !tbaa !0
  29. %call = call noalias i8* @_Znwm(i64 8)
  30. %0 = bitcast i8* %call to %struct.Foo*
  31. store %struct.Foo* %0, %struct.Foo** %f, align 8, !tbaa !4
  32. %1 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4
  33. %i = getelementptr inbounds %struct.Foo, %struct.Foo* %1, i32 0, i32 0
  34. store i64 1, i64* %i, align 8, !tbaa !6
  35. store i32 0, i32* %i1, align 4, !tbaa !0
  36. br label %for.cond
  37. for.cond:
  38. %2 = load i32, i32* %i1, align 4, !tbaa !0
  39. %3 = load i32, i32* %n.addr, align 4, !tbaa !0
  40. %cmp = icmp slt i32 %2, %3
  41. br i1 %cmp, label %for.body, label %for.end
  42. for.body:
  43. %4 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4
  44. %5 = bitcast %struct.Foo* %4 to i8*
  45. %new.isnull = icmp eq i8* %5, null
  46. br i1 %new.isnull, label %new.cont, label %new.notnull
  47. new.notnull:
  48. %6 = bitcast i8* %5 to %struct.Bar*
  49. br label %new.cont
  50. new.cont:
  51. %7 = phi %struct.Bar* [ %6, %new.notnull ], [ null, %for.body ]
  52. store %struct.Bar* %7, %struct.Bar** %b, align 8, !tbaa !4
  53. %8 = load %struct.Bar*, %struct.Bar** %b, align 8, !tbaa !4
  54. %p = getelementptr inbounds %struct.Bar, %struct.Bar* %8, i32 0, i32 0
  55. store i8* null, i8** %p, align 8, !tbaa !9
  56. %9 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4
  57. %10 = bitcast %struct.Foo* %9 to i8*
  58. %new.isnull2 = icmp eq i8* %10, null
  59. br i1 %new.isnull2, label %new.cont4, label %new.notnull3
  60. new.notnull3:
  61. %11 = bitcast i8* %10 to %struct.Foo*
  62. br label %new.cont4
  63. new.cont4:
  64. %12 = phi %struct.Foo* [ %11, %new.notnull3 ], [ null, %new.cont ]
  65. store %struct.Foo* %12, %struct.Foo** %f, align 8, !tbaa !4
  66. %13 = load i32, i32* %i1, align 4, !tbaa !0
  67. %conv = sext i32 %13 to i64
  68. %14 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4
  69. %i5 = getelementptr inbounds %struct.Foo, %struct.Foo* %14, i32 0, i32 0
  70. store i64 %conv, i64* %i5, align 8, !tbaa !6
  71. br label %for.inc
  72. for.inc:
  73. %15 = load i32, i32* %i1, align 4, !tbaa !0
  74. %inc = add nsw i32 %15, 1
  75. store i32 %inc, i32* %i1, align 4, !tbaa !0
  76. br label %for.cond
  77. for.end:
  78. %16 = load %struct.Foo*, %struct.Foo** %f, align 8, !tbaa !4
  79. %i6 = getelementptr inbounds %struct.Foo, %struct.Foo* %16, i32 0, i32 0
  80. %17 = load i64, i64* %i6, align 8, !tbaa !6
  81. ret i64 %17
  82. }
  83. declare noalias i8* @_Znwm(i64)
  84. attributes #0 = { nounwind }
  85. !0 = !{!1, !1, i64 0}
  86. !1 = !{!"int", !2, i64 0}
  87. !2 = !{!"omnipotent char", !3, i64 0}
  88. !3 = !{!"Simple C/C++ TBAA"}
  89. !4 = !{!5, !5, i64 0}
  90. !5 = !{!"any pointer", !2, i64 0}
  91. !6 = !{!7, !8, i64 0}
  92. !7 = !{!"_ZTS3Foo", !8, i64 0}
  93. !8 = !{!"long", !2, i64 0}
  94. !9 = !{!10, !5, i64 0}
  95. !10 = !{!"_ZTS3Bar", !5, i64 0}