atomic.ll 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ; RUN: opt -basicaa -dse -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"
  3. target triple = "x86_64-apple-macosx10.7.0"
  4. ; Sanity tests for atomic stores.
  5. ; Note that it turns out essentially every transformation DSE does is legal on
  6. ; atomic ops, just some transformations are not allowed across release-acquire pairs.
  7. @x = common global i32 0, align 4
  8. @y = common global i32 0, align 4
  9. declare void @randomop(i32*)
  10. ; DSE across unordered store (allowed)
  11. define void @test1() {
  12. ; CHECK-LABEL: test1
  13. ; CHECK-NOT: store i32 0
  14. ; CHECK: store i32 1
  15. store i32 0, i32* @x
  16. store atomic i32 0, i32* @y unordered, align 4
  17. store i32 1, i32* @x
  18. ret void
  19. }
  20. ; DSE remove unordered store (allowed)
  21. define void @test4() {
  22. ; CHECK-LABEL: test4
  23. ; CHECK-NOT: store atomic
  24. ; CHECK: store i32 1
  25. store atomic i32 0, i32* @x unordered, align 4
  26. store i32 1, i32* @x
  27. ret void
  28. }
  29. ; DSE unordered store overwriting non-atomic store (allowed)
  30. define void @test5() {
  31. ; CHECK-LABEL: test5
  32. ; CHECK: store atomic i32 1
  33. store i32 0, i32* @x
  34. store atomic i32 1, i32* @x unordered, align 4
  35. ret void
  36. }
  37. ; DSE no-op unordered atomic store (allowed)
  38. define void @test6() {
  39. ; CHECK-LABEL: test6
  40. ; CHECK-NOT: store
  41. ; CHECK: ret void
  42. %x = load atomic i32, i32* @x unordered, align 4
  43. store atomic i32 %x, i32* @x unordered, align 4
  44. ret void
  45. }
  46. ; DSE seq_cst store (be conservative; DSE doesn't have infrastructure
  47. ; to reason about atomic operations).
  48. define void @test7() {
  49. ; CHECK-LABEL: test7
  50. ; CHECK: store atomic
  51. %a = alloca i32
  52. store atomic i32 0, i32* %a seq_cst, align 4
  53. ret void
  54. }
  55. ; DSE and seq_cst load (be conservative; DSE doesn't have infrastructure
  56. ; to reason about atomic operations).
  57. define i32 @test8() {
  58. ; CHECK-LABEL: test8
  59. ; CHECK: store
  60. ; CHECK: load atomic
  61. %a = alloca i32
  62. call void @randomop(i32* %a)
  63. store i32 0, i32* %a, align 4
  64. %x = load atomic i32, i32* @x seq_cst, align 4
  65. ret i32 %x
  66. }
  67. ; DSE across monotonic load (allowed as long as the eliminated store isUnordered)
  68. define i32 @test9() {
  69. ; CHECK-LABEL: test9
  70. ; CHECK-NOT: store i32 0
  71. ; CHECK: store i32 1
  72. store i32 0, i32* @x
  73. %x = load atomic i32, i32* @y monotonic, align 4
  74. store i32 1, i32* @x
  75. ret i32 %x
  76. }
  77. ; DSE across monotonic store (allowed as long as the eliminated store isUnordered)
  78. define void @test10() {
  79. ; CHECK-LABEL: test10
  80. ; CHECK-NOT: store i32 0
  81. ; CHECK: store i32 1
  82. store i32 0, i32* @x
  83. store atomic i32 42, i32* @y monotonic, align 4
  84. store i32 1, i32* @x
  85. ret void
  86. }
  87. ; DSE across monotonic load (forbidden since the eliminated store is atomic)
  88. define i32 @test11() {
  89. ; CHECK-LABEL: test11
  90. ; CHECK: store atomic i32 0
  91. ; CHECK: store atomic i32 1
  92. store atomic i32 0, i32* @x monotonic, align 4
  93. %x = load atomic i32, i32* @y monotonic, align 4
  94. store atomic i32 1, i32* @x monotonic, align 4
  95. ret i32 %x
  96. }
  97. ; DSE across monotonic store (forbidden since the eliminated store is atomic)
  98. define void @test12() {
  99. ; CHECK-LABEL: test12
  100. ; CHECK: store atomic i32 0
  101. ; CHECK: store atomic i32 1
  102. store atomic i32 0, i32* @x monotonic, align 4
  103. store atomic i32 42, i32* @y monotonic, align 4
  104. store atomic i32 1, i32* @x monotonic, align 4
  105. ret void
  106. }
  107. ; But DSE is not allowed across a release-acquire pair.
  108. define i32 @test15() {
  109. ; CHECK-LABEL: test15
  110. ; CHECK: store i32 0
  111. ; CHECK: store i32 1
  112. store i32 0, i32* @x
  113. store atomic i32 0, i32* @y release, align 4
  114. %x = load atomic i32, i32* @y acquire, align 4
  115. store i32 1, i32* @x
  116. ret i32 %x
  117. }