lifetime.ll 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ; RUN: opt -inline -S < %s | FileCheck %s
  2. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
  3. declare void @llvm.lifetime.start(i64, i8*)
  4. declare void @llvm.lifetime.end(i64, i8*)
  5. define void @helper_both_markers() {
  6. %a = alloca i8
  7. ; Size in llvm.lifetime.start / llvm.lifetime.end differs from
  8. ; allocation size. We should use the former.
  9. call void @llvm.lifetime.start(i64 2, i8* %a)
  10. call void @llvm.lifetime.end(i64 2, i8* %a)
  11. ret void
  12. }
  13. define void @test_both_markers() {
  14. ; CHECK-LABEL: @test_both_markers(
  15. ; CHECK: llvm.lifetime.start(i64 2
  16. ; CHECK-NEXT: llvm.lifetime.end(i64 2
  17. call void @helper_both_markers()
  18. ; CHECK-NEXT: llvm.lifetime.start(i64 2
  19. ; CHECK-NEXT: llvm.lifetime.end(i64 2
  20. call void @helper_both_markers()
  21. ; CHECK-NEXT: ret void
  22. ret void
  23. }
  24. ;; Without this, the inliner will simplify out @test_no_marker before adding
  25. ;; any lifetime markers.
  26. declare void @use(i8* %a)
  27. define void @helper_no_markers() {
  28. %a = alloca i8 ; Allocation size is 1 byte.
  29. call void @use(i8* %a)
  30. ret void
  31. }
  32. ;; We can't use CHECK-NEXT because there's an extra call void @use in between.
  33. ;; Instead, we use CHECK-NOT to verify that there are no other lifetime calls.
  34. define void @test_no_marker() {
  35. ; CHECK-LABEL: @test_no_marker(
  36. ; CHECK-NOT: lifetime
  37. ; CHECK: llvm.lifetime.start(i64 1
  38. ; CHECK-NOT: lifetime
  39. ; CHECK: llvm.lifetime.end(i64 1
  40. call void @helper_no_markers()
  41. ; CHECK-NOT: lifetime
  42. ; CHECK: llvm.lifetime.start(i64 1
  43. ; CHECK-NOT: lifetime
  44. ; CHECK: llvm.lifetime.end(i64 1
  45. call void @helper_no_markers()
  46. ; CHECK-NOT: lifetime
  47. ; CHECK: ret void
  48. ret void
  49. }
  50. define void @helper_two_casts() {
  51. %a = alloca i32
  52. %b = bitcast i32* %a to i8*
  53. call void @llvm.lifetime.start(i64 4, i8* %b)
  54. %c = bitcast i32* %a to i8*
  55. call void @llvm.lifetime.end(i64 4, i8* %c)
  56. ret void
  57. }
  58. define void @test_two_casts() {
  59. ; CHECK-LABEL: @test_two_casts(
  60. ; CHECK-NOT: lifetime
  61. ; CHECK: llvm.lifetime.start(i64 4
  62. ; CHECK-NOT: lifetime
  63. ; CHECK: llvm.lifetime.end(i64 4
  64. call void @helper_two_casts()
  65. ; CHECK-NOT: lifetime
  66. ; CHECK: llvm.lifetime.start(i64 4
  67. ; CHECK-NOT: lifetime
  68. ; CHECK: llvm.lifetime.end(i64 4
  69. call void @helper_two_casts()
  70. ; CHECK-NOT: lifetime
  71. ; CHECK: ret void
  72. ret void
  73. }
  74. define void @helper_arrays_alloca() {
  75. %a = alloca [10 x i32], align 16
  76. %1 = bitcast [10 x i32]* %a to i8*
  77. call void @use(i8* %1)
  78. ret void
  79. }
  80. define void @test_arrays_alloca() {
  81. ; CHECK-LABEL: @test_arrays_alloca(
  82. ; CHECK-NOT: lifetime
  83. ; CHECK: llvm.lifetime.start(i64 40,
  84. ; CHECK-NOT: lifetime
  85. ; CHECK: llvm.lifetime.end(i64 40,
  86. call void @helper_arrays_alloca()
  87. ; CHECK-NOT: lifetime
  88. ; CHECK: ret void
  89. ret void
  90. }