[llvm] [MachineSink] Reduce the number of unnecessary invalidations of StoreInstrCache (NFC) (PR #68676)

Momchil Velikov via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 02:05:11 PDT 2023


https://github.com/momchil-velikov created https://github.com/llvm/llvm-project/pull/68676

Don't invalidate the cache when erasing instructions which cannot ever appear be in the cache.

>From 838820b542fef13cf8d4d0c9b4e5b285b2b42e1b Mon Sep 17 00:00:00 2001
From: Momchil Velikov <momchil.velikov at arm.com>
Date: Mon, 9 Oct 2023 16:47:57 +0100
Subject: [PATCH] [MachineSink] Invalidate StoreInstrCache only if we are about
 to erase a store (NFC)

---
 llvm/lib/CodeGen/MachineSink.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index 40f33d664414dbb..7d329bfde89bc16 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -539,9 +539,10 @@ bool MachineSinking::PerformSinkAndFold(MachineInstr &MI,
       New = TII->emitLdStWithAddr(*SinkDst, MaybeAM);
     }
     LLVM_DEBUG(dbgs() << "yielding"; New->dump());
+    // Clear the StoreInstrCache, since we may invalidate it by erasing.
+    if (SinkDst->mayStore() && !SinkDst->hasOrderedMemoryRef())
+      StoreInstrCache.clear();
     SinkDst->eraseFromParent();
-    // Clear the StoreInstrCache, since we may have invalidated it by erasing.
-    StoreInstrCache.clear();
   }
 
   // Collect operands that need to be cleaned up because the registers no longer



More information about the llvm-commits mailing list