[llvm] [MachineLICM] Improve register pressure estimation. (PR #118615)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 4 08:11:47 PST 2024
https://github.com/michaelmaitland commented:
My understanding of the approach taken here is that if all defs in the preheader are only used outside the loop, then we can skip adding the defs in the preheader to the register pressure.
This approach is an all or nothing approach. Have you considered a more fine grained approach? Something like this:
```
/// Return the registers which are defined by MI that are not used in Loop.
SmallVector<Register> findDefsOnlyUsedOutsideOfTheLoop(MachineInstr &MI, MachineLoop *Loop) { ... }
void MachineLICMImpl::InitRegPressure(MachineBasicBlock *BB,
const MachineLoop *Loop) {
...
for (const MachineInstr &MI : *BB) {
SmallVector<Register> IgnoreDefs = findDefsOnlyUsedOutsideOfTheLoop(MI, Loop);
UpdateRegPressure(&MI, /*ConsiderUnseenAsDef=*/true, IgnoreDefs);
}
...
}
SmallDenseMap<unsigned, int>
MachineLICMImpl::calcRegisterCost(const MachineInstr *MI, bool ConsiderSeen,
bool ConsiderUnseenAsDef, SmallVector<Register> IgnoreDefs) {
...
if (MO.isDef() && !IgnoreDefs.contains(MO.getReg()))
RCCost = W.RegWeight;
...
}
```
https://github.com/llvm/llvm-project/pull/118615
More information about the llvm-commits
mailing list