[llvm] 9969c31 - [DSE,MemorySSA] Handle atomic stores explicitly in isReadClobber.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 15:02:13 PDT 2020


Author: Florian Hahn
Date: 2020-09-09T23:01:58+01:00
New Revision: 9969c317ff0877ed6155043422c70e1d4c028a35

URL: https://github.com/llvm/llvm-project/commit/9969c317ff0877ed6155043422c70e1d4c028a35
DIFF: https://github.com/llvm/llvm-project/commit/9969c317ff0877ed6155043422c70e1d4c028a35.diff

LOG: [DSE,MemorySSA] Handle atomic stores explicitly in isReadClobber.

Atomic stores are modeled as MemoryDef to model the fact that they may
not be reordered, depending on the ordering constraints.

Atomic stores that are monotonic or weaker do not limit re-ordering, so
we do not have to treat them as potential read clobbers.

Note that llvm/test/Transforms/DeadStoreElimination/MSSA/atomic.ll
already contains a set of negative test cases.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D87386

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
    llvm/test/Transforms/DeadStoreElimination/MSSA/atomic-todo.ll
    llvm/test/Transforms/DeadStoreElimination/MSSA/atomic.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 1427bd4ad4df..12514be0e631 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1824,6 +1824,11 @@ struct DSEState {
 
   // Returns true if \p Use may read from \p DefLoc.
   bool isReadClobber(MemoryLocation DefLoc, Instruction *UseInst) {
+    // Monotonic or weaker atomic stores can be re-ordered and do not need to be
+    // treated as read clobber.
+    if (auto SI = dyn_cast<StoreInst>(UseInst))
+      return isStrongerThan(SI->getOrdering(), AtomicOrdering::Monotonic);
+
     if (!UseInst->mayReadFromMemory())
       return false;
 

diff  --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/atomic-todo.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/atomic-todo.ll
index 04361e63e6d0..8dfb85719c30 100644
--- a/llvm/test/Transforms/DeadStoreElimination/MSSA/atomic-todo.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/atomic-todo.ll
@@ -21,14 +21,3 @@ define i32 @test9() {
   store i32 1, i32* @x
   ret i32 %x
 }
-
-; DSE across monotonic store (allowed as long as the eliminated store isUnordered)
-define void @test10() {
-; CHECK-LABEL: test10
-; CHECK-NOT: store i32 0
-; CHECK: store i32 1
-  store i32 0, i32* @x
-  store atomic i32 42, i32* @y monotonic, align 4
-  store i32 1, i32* @x
-  ret void
-}

diff  --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/atomic.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/atomic.ll
index 5a3ea376415c..51129fe2bcad 100644
--- a/llvm/test/Transforms/DeadStoreElimination/MSSA/atomic.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/atomic.ll
@@ -88,6 +88,17 @@ define i32 @test8() {
   ret i32 %x
 }
 
+; DSE across monotonic store (allowed as long as the eliminated store isUnordered)
+define void @test10() {
+; CHECK-LABEL: test10
+; CHECK-NOT: store i32 0
+; CHECK: store i32 1
+  store i32 0, i32* @x
+  store atomic i32 42, i32* @y monotonic, align 4
+  store i32 1, i32* @x
+  ret void
+}
+
 ; DSE across monotonic load (forbidden since the eliminated store is atomic)
 define i32 @test11() {
 ; CHECK-LABEL: @test11(


        


More information about the llvm-commits mailing list