[llvm] [MachineLICM] Improve register pressure estimation. (PR #118615)

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 08:21:45 PST 2024


mgudim wrote:

> 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;
> ...
> }
> ```

That's a good idea! I haven't considered the case when MI can define more than one register. I'll update the MR, thanks!

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


More information about the llvm-commits mailing list