[llvm] [Sink] Allow sinking of loads to distant blocks (PR #135986)

via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 26 05:51:27 PDT 2025


================
@@ -60,10 +63,62 @@ static bool isSafeToMove(Instruction *Inst, AliasAnalysis &AA,
   return true;
 }
 
+static cl::opt<unsigned> SinkLoadStoreLimit(
+    "sink-load-store-limit", cl::Hidden, cl::init(4),
+    cl::desc("Maximum number of stores in descendant blocks that will be "
+             "analyzed when attempting to sink a load."));
+
+using BlocksSet = SmallPtrSet<BasicBlock *, 8>;
+static bool hasStoreConflict(BasicBlock *LoadBB, BasicBlock *BB,
+                             BlocksSet &VisitedBlocksSet,
+                             MemorySSAUpdater &MSSAU, BatchAAResults &BAA,
+                             Instruction *ReadMemInst, unsigned &StoreCnt) {
+  if (BB == LoadBB || !VisitedBlocksSet.insert(BB).second)
+    return false;
+  if (auto *Accesses = MSSAU.getMemorySSA()->getBlockDefs(BB)) {
+    StoreCnt += Accesses->size();
+    if (StoreCnt > SinkLoadStoreLimit)
+      return true;
+    for (auto &MA : *Accesses)
----------------
LU-JOHN wrote:

Added.

https://github.com/llvm/llvm-project/pull/135986


More information about the llvm-commits mailing list