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

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


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

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

This is a small compile-time improvement: https://llvm-compile-time-tracker.com/compare.php?from=4d2a670ba868a75103424ff3203f443391d55b1b&to=156a0df89bcdd0cafbdb264d429c7ca38965906e&stat=instructions%3Au

>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] [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);
     }



More information about the llvm-commits mailing list