[llvm] [CodeGen] Optimize/simplify finalizeBundle. NFC (PR #155448)
Björn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 26 10:12:49 PDT 2025
https://github.com/bjope created https://github.com/llvm/llvm-project/pull/155448
When tracking defs in finalizeBundle two sets are used. LocalDefs is used to track defined virtual and physical registers, while LocalDefsP is used to track defined register units for the physical registers.
This patch moves the updates of LocalDefsP to only iterate over regunits when a new physical register is added to LocalDefs. When the physical register already is present in LocalDefs, then the corresponding register units are present in LocalDefsP. So it was a waste of time to add them to the set again.
>From 62ff383ff2aa04291f57b37c92ee0ba8df1103f6 Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
Date: Tue, 26 Aug 2025 17:57:10 +0200
Subject: [PATCH] [CodeGen] Optimize/simplify finalizeBundle. NFC
When tracking defs in finalizeBundle two sets are used. LocalDefs
is used to track defined virtual and physical registers, while
LocalDefsP is used to track defined register units for the physical
registers.
This patch moves the updates of LocalDefsP to only iterate over
regunits when a new physical register is added to LocalDefs. When
the physical register already is present in LocalDefs, then the
corresponding register units are present in LocalDefsP. So it
was a waste of time to add them to the set again.
---
llvm/lib/CodeGen/MachineInstrBundle.cpp | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineInstrBundle.cpp b/llvm/lib/CodeGen/MachineInstrBundle.cpp
index d9e8484c08d76..5830ecfe4aa20 100644
--- a/llvm/lib/CodeGen/MachineInstrBundle.cpp
+++ b/llvm/lib/CodeGen/MachineInstrBundle.cpp
@@ -173,6 +173,9 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB,
if (LocalDefs.insert(Reg)) {
if (MO.isDead())
DeadDefSet.insert(Reg);
+ else if (Reg.isPhysical())
+ for (MCRegUnit Unit : TRI->regunits(Reg.asMCReg()))
+ LocalDefsP.set(Unit);
} else {
// Re-defined inside the bundle, it's no longer killed.
KilledDefSet.erase(Reg);
@@ -181,11 +184,6 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB,
DeadDefSet.erase(Reg);
}
}
-
- if (!MO.isDead() && Reg.isPhysical()) {
- for (MCRegUnit Unit : TRI->regunits(Reg.asMCReg()))
- LocalDefsP.set(Unit);
- }
}
// Set FrameSetup/FrameDestroy for the bundle. If any of the instructions
More information about the llvm-commits
mailing list