[PATCH] D87386: [DSE,MemorySSA] Handle atomic stores expliclty in isReadClobber.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 08:22:59 PDT 2020


fhahn created this revision.
fhahn added reviewers: jfb, efriedma, asbirlea.
Herald added subscribers: dexonsmith, george.burgess.iv, hiraditya, Prazek.
Herald added a project: LLVM.
fhahn requested review of this revision.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87386

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


Index: llvm/test/Transforms/DeadStoreElimination/MSSA/atomic.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/MSSA/atomic.ll
+++ llvm/test/Transforms/DeadStoreElimination/MSSA/atomic.ll
@@ -88,6 +88,17 @@
   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(
Index: llvm/test/Transforms/DeadStoreElimination/MSSA/atomic-todo.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/MSSA/atomic-todo.ll
+++ llvm/test/Transforms/DeadStoreElimination/MSSA/atomic-todo.ll
@@ -21,14 +21,3 @@
   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
-}
Index: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1795,6 +1795,11 @@
 
   // 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;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87386.290746.patch
Type: text/x-patch
Size: 2032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200909/acbc94f9/attachment.bin>


More information about the llvm-commits mailing list