[PATCH] D121366: Allow ImproveChain to get past relaxed atomics

Yoni Lavi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 10 02:51:49 PST 2022


yoni-lavi created this revision.
Herald added subscribers: ecnelises, hiraditya.
Herald added a project: All.
yoni-lavi requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

As titled; Relaxed AKA Monotonic atomics don't impose any synchronization semantics between threads. Any other non-aliasing mem operation can treat them the same as an ordinary load (or load/modify/store) so it should not preclude chain improvement.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121366

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp


Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -24039,6 +24039,16 @@
               Optional<int64_t>(Size),
               LSN->getMemOperand()};
     }
+    if (const auto *AN = dyn_cast<AtomicSDNode>(N)) {
+      // PRE_INC / PRE_DEC allegedly not a relevant issue, can set this to zero
+      int64_t Offset = 0;
+      uint64_t Size =
+          MemoryLocation::getSizeOrUnknown(AN->getMemoryVT().getStoreSize());
+      return {AN->isVolatile(), AN->isAtomic(), AN->getBasePtr(),
+              Offset,
+              Optional<int64_t>(Size),
+              AN->getMemOperand()};
+    }
     if (const auto *LN = cast<LifetimeSDNode>(N))
       return {false /*isVolatile*/, /*isAtomic*/ false, LN->getOperand(1),
               (LN->hasOffset()) ? LN->getOffset() : 0,
@@ -24198,6 +24208,20 @@
       return false;
     }
     default:
+      if (auto *AC = dyn_cast<AtomicSDNode>(C.getNode())) {
+        if (AC->getOrdering() == AtomicOrdering::Monotonic) {
+          bool IsOpLoad = AC->getOpcode() == ISD::ATOMIC_LOAD;
+          if ((IsLoad && IsOpLoad) || !mayAlias(N, AC)) {
+            LLVM_DEBUG(
+              dbgs() << "ImproveChain of node went past a monotonic Atomic operation.\n  Node: ";
+              N->dump();
+              dbgs() << "  Atomic: ";
+              AC->dump());
+            C = C.getOperand(0);
+            return true;
+          }
+        }
+      }
       return false;
     }
   };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121366.414322.patch
Type: text/x-patch
Size: 1611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220310/53cb24bb/attachment.bin>


More information about the llvm-commits mailing list