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

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


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-regalloc

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/201602.diff


1 Files Affected:

- (modified) llvm/lib/CodeGen/MachineCopyPropagation.cpp (+6) 


``````````diff
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);
     }

``````````

</details>


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


More information about the llvm-commits mailing list