atomic.ll 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ; RUN: opt -basicaa -gvn -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. @x = common global i32 0, align 4
  5. @y = common global i32 0, align 4
  6. ; GVN across unordered store (allowed)
  7. define i32 @test1() nounwind uwtable ssp {
  8. ; CHECK-LABEL: test1
  9. ; CHECK: add i32 %x, %x
  10. entry:
  11. %x = load i32, i32* @y
  12. store atomic i32 %x, i32* @x unordered, align 4
  13. %y = load i32, i32* @y
  14. %z = add i32 %x, %y
  15. ret i32 %z
  16. }
  17. ; GVN across unordered load (allowed)
  18. define i32 @test3() nounwind uwtable ssp {
  19. ; CHECK-LABEL: test3
  20. ; CHECK: add i32 %x, %x
  21. entry:
  22. %x = load i32, i32* @y
  23. %y = load atomic i32, i32* @x unordered, align 4
  24. %z = load i32, i32* @y
  25. %a = add i32 %x, %z
  26. %b = add i32 %y, %a
  27. ret i32 %b
  28. }
  29. ; GVN load to unordered load (allowed)
  30. define i32 @test5() nounwind uwtable ssp {
  31. ; CHECK-LABEL: test5
  32. ; CHECK: add i32 %x, %x
  33. entry:
  34. %x = load atomic i32, i32* @x unordered, align 4
  35. %y = load i32, i32* @x
  36. %z = add i32 %x, %y
  37. ret i32 %z
  38. }
  39. ; GVN unordered load to load (unordered load must not be removed)
  40. define i32 @test6() nounwind uwtable ssp {
  41. ; CHECK-LABEL: test6
  42. ; CHECK: load atomic i32, i32* @x unordered
  43. entry:
  44. %x = load i32, i32* @x
  45. %x2 = load atomic i32, i32* @x unordered, align 4
  46. %x3 = add i32 %x, %x2
  47. ret i32 %x3
  48. }
  49. ; GVN across release-acquire pair (forbidden)
  50. define i32 @test7() nounwind uwtable ssp {
  51. ; CHECK-LABEL: test7
  52. ; CHECK: add i32 %x, %y
  53. entry:
  54. %x = load i32, i32* @y
  55. store atomic i32 %x, i32* @x release, align 4
  56. %w = load atomic i32, i32* @x acquire, align 4
  57. %y = load i32, i32* @y
  58. %z = add i32 %x, %y
  59. ret i32 %z
  60. }
  61. ; GVN across monotonic store (allowed)
  62. define i32 @test9() nounwind uwtable ssp {
  63. ; CHECK-LABEL: test9
  64. ; CHECK: add i32 %x, %x
  65. entry:
  66. %x = load i32, i32* @y
  67. store atomic i32 %x, i32* @x monotonic, align 4
  68. %y = load i32, i32* @y
  69. %z = add i32 %x, %y
  70. ret i32 %z
  71. }
  72. ; GVN of an unordered across monotonic load (not allowed)
  73. define i32 @test10() nounwind uwtable ssp {
  74. ; CHECK-LABEL: test10
  75. ; CHECK: add i32 %x, %y
  76. entry:
  77. %x = load atomic i32, i32* @y unordered, align 4
  78. %clobber = load atomic i32, i32* @x monotonic, align 4
  79. %y = load atomic i32, i32* @y monotonic, align 4
  80. %z = add i32 %x, %y
  81. ret i32 %z
  82. }
  83. define i32 @PR22708(i1 %flag) {
  84. ; CHECK-LABEL: PR22708
  85. entry:
  86. br i1 %flag, label %if.then, label %if.end
  87. if.then:
  88. store i32 43, i32* @y, align 4
  89. ; CHECK: store i32 43, i32* @y, align 4
  90. br label %if.end
  91. if.end:
  92. load atomic i32, i32* @x acquire, align 4
  93. %load = load i32, i32* @y, align 4
  94. ; CHECK: load atomic i32, i32* @x acquire, align 4
  95. ; CHECK: load i32, i32* @y, align 4
  96. ret i32 %load
  97. }