[llvm] 007418c - RegAllocGreedy: Avoid unused block frequency lookups in hint recoloring (#231027)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 11 13:26:44 PDT 2026
Author: Matt Arsenault
Date: 2026-10-11T22:26:39+02:00
New Revision: 007418c606a1cceb712d5873c36a2cf1c54f44db
URL: https://github.com/llvm/llvm-project/commit/007418c606a1cceb712d5873c36a2cf1c54f44db
DIFF: https://github.com/llvm/llvm-project/commit/007418c606a1cceb712d5873c36a2cf1c54f44db.diff
LOG: RegAllocGreedy: Avoid unused block frequency lookups in hint recoloring (#231027)
collectHintInfo looked up the block frequency of every copy, but the
frequencies are only used for the profitability check when the register
would be recolored. Most visited registers are already assigned the
target register, so record the block and look the frequency up only
when it is needed. Also use a SmallDenseSet for the visited set, which
otherwise falls back to a std::set on anything but tiny components.
On a stress test with 4000 critical edges into a block with 4 PHIs,
this roughly halves the time in Greedy.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Added:
Modified:
llvm/lib/CodeGen/RegAllocGreedy.cpp
llvm/lib/CodeGen/RegAllocGreedy.h
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/RegAllocGreedy.cpp b/llvm/lib/CodeGen/RegAllocGreedy.cpp
index 51faa9dd91039..bbe721587dc72 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ b/llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -2507,8 +2507,7 @@ void RAGreedy::collectHintInfo(Register Reg, HintsInfo &Out) {
// Push the collected information.
if (OtherPhysReg) {
- Out.push_back(HintInfo(MBFI->getBlockFreq(Instr.getParent()), OtherReg,
- OtherPhysReg));
+ Out.push_back(HintInfo(Instr.getParent(), OtherReg, OtherPhysReg));
}
}
}
@@ -2521,7 +2520,7 @@ BlockFrequency RAGreedy::getBrokenHintFreq(const HintsInfo &List,
BlockFrequency Cost = BlockFrequency(0);
for (const HintInfo &Info : List) {
if (Info.PhysReg != PhysReg)
- Cost += Info.Freq;
+ Cost += MBFI->getBlockFreq(Info.MBB);
}
return Cost;
}
@@ -2543,7 +2542,7 @@ void RAGreedy::tryHintRecoloring(const LiveInterval &VirtReg) {
MCRegister PhysReg = VRM->getPhys(Reg);
// Start the recoloring algorithm from the input live-interval, then
// it will propagate to the ones that are copy-related with it.
- SmallSet<Register, 4> Visited = {Reg};
+ SmallDenseSet<Register, 8> Visited = {Reg};
SmallVector<Register, 2> RecoloringCandidates = {Reg};
LLVM_DEBUG(dbgs() << "Trying to reconcile hints for: " << printReg(Reg, TRI)
diff --git a/llvm/lib/CodeGen/RegAllocGreedy.h b/llvm/lib/CodeGen/RegAllocGreedy.h
index 465be0d76809e..9da4544608dbb 100644
--- a/llvm/lib/CodeGen/RegAllocGreedy.h
+++ b/llvm/lib/CodeGen/RegAllocGreedy.h
@@ -381,16 +381,16 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public RegAllocBase,
/// Model the information carried by one end of a copy.
struct HintInfo {
- /// The frequency of the copy.
- BlockFrequency Freq;
+ /// The block containing the copy.
+ const MachineBasicBlock *MBB;
/// The virtual register or physical register.
Register Reg;
/// Its currently assigned register.
/// In case of a physical register Reg == PhysReg.
MCRegister PhysReg;
- HintInfo(BlockFrequency Freq, Register Reg, MCRegister PhysReg)
- : Freq(Freq), Reg(Reg), PhysReg(PhysReg) {}
+ HintInfo(const MachineBasicBlock *MBB, Register Reg, MCRegister PhysReg)
+ : MBB(MBB), Reg(Reg), PhysReg(PhysReg) {}
};
using HintsInfo = SmallVector<HintInfo, 4>;
More information about the llvm-commits
mailing list