atomics.ll 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ; RUN: opt < %s -S -basicaa -licm | FileCheck %s
  2. ; Check that we can hoist unordered loads
  3. define i32 @test1(i32* nocapture %y) nounwind uwtable ssp {
  4. entry:
  5. br label %loop
  6. loop:
  7. %i = phi i32 [ %inc, %loop ], [ 0, %entry ]
  8. %val = load atomic i32, i32* %y unordered, align 4
  9. %inc = add nsw i32 %i, 1
  10. %exitcond = icmp eq i32 %inc, %val
  11. br i1 %exitcond, label %end, label %loop
  12. end:
  13. ret i32 %val
  14. ; CHECK-LABEL: define i32 @test1(
  15. ; CHECK: load atomic
  16. ; CHECK-NEXT: br label %loop
  17. }
  18. ; Check that we don't sink/hoist monotonic loads
  19. ; (Strictly speaking, it's not forbidden, but it's supposed to be possible to
  20. ; use monotonic for spinlock-like constructs.)
  21. define i32 @test2(i32* nocapture %y) nounwind uwtable ssp {
  22. entry:
  23. br label %loop
  24. loop:
  25. %val = load atomic i32, i32* %y monotonic, align 4
  26. %exitcond = icmp ne i32 %val, 0
  27. br i1 %exitcond, label %end, label %loop
  28. end:
  29. ret i32 %val
  30. ; CHECK-LABEL: define i32 @test2(
  31. ; CHECK: load atomic
  32. ; CHECK-NEXT: %exitcond = icmp ne
  33. ; CHECK-NEXT: br i1 %exitcond, label %end, label %loop
  34. }
  35. ; Check that we hoist unordered around monotonic.
  36. ; (The noalias shouldn't be necessary in theory, but LICM isn't quite that
  37. ; smart yet.)
  38. define i32 @test3(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
  39. entry:
  40. br label %loop
  41. loop:
  42. %vala = load atomic i32, i32* %y monotonic, align 4
  43. %valb = load atomic i32, i32* %x unordered, align 4
  44. %exitcond = icmp ne i32 %vala, %valb
  45. br i1 %exitcond, label %end, label %loop
  46. end:
  47. ret i32 %vala
  48. ; CHECK-LABEL: define i32 @test3(
  49. ; CHECK: load atomic i32, i32* %x unordered
  50. ; CHECK-NEXT: br label %loop
  51. }
  52. ; Don't try to "sink" unordered stores yet; it is legal, but the machinery
  53. ; isn't there.
  54. define i32 @test4(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
  55. entry:
  56. br label %loop
  57. loop:
  58. %vala = load atomic i32, i32* %y monotonic, align 4
  59. store atomic i32 %vala, i32* %x unordered, align 4
  60. %exitcond = icmp ne i32 %vala, 0
  61. br i1 %exitcond, label %end, label %loop
  62. end:
  63. ret i32 %vala
  64. ; CHECK-LABEL: define i32 @test4(
  65. ; CHECK: load atomic i32, i32* %y monotonic
  66. ; CHECK-NEXT: store atomic
  67. }