[llvm] [MCP] Early exit if no copies (NFC) (PR #201602)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 08:14:04 PDT 2026


https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/201602

>From 156a0df89bcdd0cafbdb264d429c7ca38965906e Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 4 Jun 2026 16:13:04 +0200
Subject: [PATCH 1/2] [MCP] Early exit if no copies (NFC)

These two functions do expensive per-regunit work, but are no-ops
if there are no Copies, so short-circuit this case.
---
 llvm/lib/CodeGen/MachineCopyPropagation.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 6bfd21b215706..8e161b9b0739a 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -175,6 +175,9 @@ class CopyTracker {
   /// Remove register from copy maps.
   void invalidateRegister(MCRegister Reg, const TargetRegisterInfo &TRI,
                           const TargetInstrInfo &TII, bool UseCopyInstr) {
+    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 +265,9 @@ 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) {
+    if (Copies.empty())
+      return;
+
     for (MCRegUnit Unit : TRI.regunits(Reg)) {
       clobberRegUnit(Unit, TRI, TII, UseCopyInstr);
     }

>From bae405e49b00590dd001d05fb96f2fad49caae49 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 4 Jun 2026 17:13:47 +0200
Subject: [PATCH 2/2] Add comments

---
 llvm/lib/CodeGen/MachineCopyPropagation.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 8e161b9b0739a..54b2b2a0f4435 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -175,6 +175,8 @@ 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;
 
@@ -265,6 +267,8 @@ 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;
 



More information about the llvm-commits mailing list