[llvm] 48f50e8 - [MCP] Early exit if no copies (NFC) (#201602)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 08:46:23 PDT 2026


Author: Nikita Popov
Date: 2026-06-04T15:46:18Z
New Revision: 48f50e89b726578ee87cd1305330fa32932bb685

URL: https://github.com/llvm/llvm-project/commit/48f50e89b726578ee87cd1305330fa32932bb685
DIFF: https://github.com/llvm/llvm-project/commit/48f50e89b726578ee87cd1305330fa32932bb685.diff

LOG: [MCP] Early exit if no copies (NFC) (#201602)

These two functions do expensive per-regunit work, but are no-ops if
there are no Copies, so short-circuit this case.

Added: 
    

Modified: 
    llvm/lib/CodeGen/MachineCopyPropagation.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 6bfd21b215706..54b2b2a0f4435 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -175,6 +175,11 @@ class CopyTracker {
   /// Remove register from copy maps.
   void invalidateRegister(MCRegister Reg, const TargetRegisterInfo &TRI,
                           const TargetInstrInfo &TII, bool UseCopyInstr) {
+    // Early exit if there are no copies, as the function wouldn't do anything
+    // in that case.
+    if (Copies.empty())
+      return;
+
     // Since Reg might be a subreg of some registers, only invalidate Reg is not
     // enough. We have to find the COPY defines Reg or registers defined by Reg
     // and invalidate all of them. Similarly, we must invalidate all of the
@@ -262,6 +267,11 @@ class CopyTracker {
   /// Clobber a single register, removing it from the tracker's copy maps.
   void clobberRegister(MCRegister Reg, const TargetRegisterInfo &TRI,
                        const TargetInstrInfo &TII, bool UseCopyInstr) {
+    // Early exit if there are no copies, as the function wouldn't do anything
+    // in that case.
+    if (Copies.empty())
+      return;
+
     for (MCRegUnit Unit : TRI.regunits(Reg)) {
       clobberRegUnit(Unit, TRI, TII, UseCopyInstr);
     }


        


More information about the llvm-commits mailing list