[llvm-branch-commits] [llvm] LiveVariables: Remove dead live-in handling and Defs plumbing (PR #230150)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Oct 8 12:57:34 PDT 2026
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/230150
>From d1a22d9bb5e00f33d974b2642a04ba864ac05a8d Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 8 Oct 2026 16:17:00 +0200
Subject: [PATCH] LiveVariables: Remove dead live-in handling and Defs plumbing
No physical register is tracked at the start of a block, so handling
the block live-ins was a no-op. The Defs list was only appended for
instruction defs, which runOnInstr already collects.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
---
llvm/include/llvm/CodeGen/LiveVariables.h | 8 +++---
llvm/lib/CodeGen/LiveVariables.cpp | 33 +++++++----------------
2 files changed, 12 insertions(+), 29 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/LiveVariables.h b/llvm/include/llvm/CodeGen/LiveVariables.h
index 99fc2eadc1d22..94a85e1c87bfd 100644
--- a/llvm/include/llvm/CodeGen/LiveVariables.h
+++ b/llvm/include/llvm/CodeGen/LiveVariables.h
@@ -64,9 +64,8 @@ class LiveVariables {
void HandleRegMask(const MachineOperand &, unsigned);
void HandlePhysRegUse(Register Reg, MachineInstr &MI);
- void HandlePhysRegDef(Register Reg, MachineInstr *MI,
- SmallVectorImpl<Register> &Defs);
- void UpdatePhysRegDefs(MachineInstr &MI, SmallVectorImpl<Register> &Defs);
+ void HandlePhysRegDef(Register Reg, MachineInstr *MI);
+ void UpdatePhysRegDefs(MachineInstr &MI, ArrayRef<Register> Defs);
/// FindLastRefOrPartRef - Return the last reference or partial reference of
/// the specified register.
@@ -76,8 +75,7 @@ class LiveVariables {
/// register.
MachineInstr *FindLastPartialDef(Register Reg);
- void runOnInstr(MachineInstr &MI, SmallVectorImpl<Register> &Defs,
- unsigned NumRegs);
+ void runOnInstr(MachineInstr &MI, unsigned NumRegs);
void runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs);
diff --git a/llvm/lib/CodeGen/LiveVariables.cpp b/llvm/lib/CodeGen/LiveVariables.cpp
index af2ea6f9b8245..8546ccad1dcb1 100644
--- a/llvm/lib/CodeGen/LiveVariables.cpp
+++ b/llvm/lib/CodeGen/LiveVariables.cpp
@@ -247,8 +247,7 @@ void LiveVariables::HandleRegMask(const MachineOperand &MO, unsigned NumRegs) {
}
}
-void LiveVariables::HandlePhysRegDef(Register Reg, MachineInstr *MI,
- SmallVectorImpl<Register> &Defs) {
+void LiveVariables::HandlePhysRegDef(Register Reg, MachineInstr *MI) {
// What parts of the register are previously defined?
SmallSet<unsigned, 32> Live;
if (PhysRegDef[Reg.id()] || PhysRegUse[Reg.id()]) {
@@ -278,25 +277,19 @@ void LiveVariables::HandlePhysRegDef(Register Reg, MachineInstr *MI,
continue;
HandlePhysRegKill(SubReg, MI);
}
-
- if (MI)
- Defs.push_back(Reg); // Remember this def.
}
void LiveVariables::UpdatePhysRegDefs(MachineInstr &MI,
- SmallVectorImpl<Register> &Defs) {
- while (!Defs.empty()) {
- Register Reg = Defs.pop_back_val();
+ ArrayRef<Register> Defs) {
+ for (Register Reg : Defs) {
for (MCPhysReg SubReg : TRI->subregs_inclusive(Reg)) {
PhysRegDef[SubReg] = &MI;
- PhysRegUse[SubReg] = nullptr;
+ PhysRegUse[SubReg] = nullptr;
}
}
}
-void LiveVariables::runOnInstr(MachineInstr &MI,
- SmallVectorImpl<Register> &Defs,
- unsigned NumRegs) {
+void LiveVariables::runOnInstr(MachineInstr &MI, unsigned NumRegs) {
assert(!MI.isDebugOrPseudoInstr());
// Clear dead markers. LV will recompute them.
@@ -334,19 +327,11 @@ void LiveVariables::runOnInstr(MachineInstr &MI,
// Process all defs.
for (Register MOReg : DefRegs)
- HandlePhysRegDef(MOReg, &MI, Defs);
- UpdatePhysRegDefs(MI, Defs);
+ HandlePhysRegDef(MOReg, &MI);
+ UpdatePhysRegDefs(MI, DefRegs);
}
void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) {
- // Mark live-in registers as live-in.
- SmallVector<Register, 4> Defs;
- for (const auto &LI : MBB->liveins()) {
- assert(LI.PhysReg.isPhysical() &&
- "Cannot have a live-in virtual register!");
- HandlePhysRegDef(LI.PhysReg, nullptr, Defs);
- }
-
// Loop over all of the instructions, processing them.
DistanceMap.clear();
unsigned Dist = 0;
@@ -355,7 +340,7 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) {
continue;
DistanceMap.insert(std::make_pair(&MI, Dist++));
- runOnInstr(MI, Defs, NumRegs);
+ runOnInstr(MI, NumRegs);
}
// MachineCSE may CSE instructions which write to non-allocatable physical
@@ -375,7 +360,7 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) {
// available at the end of the basic block.
for (unsigned i = 0; i != NumRegs; ++i)
if ((PhysRegDef[i] || PhysRegUse[i]) && !LiveOuts.count(i))
- HandlePhysRegDef(i, nullptr, Defs);
+ HandlePhysRegDef(i, nullptr);
}
void LiveVariables::analyze(MachineFunction &mf) {
More information about the llvm-branch-commits
mailing list