[llvm] [RegAlloc] Scale the spill weight by the weight of register class (PR #113675)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 23:30:58 PST 2024


wangpc-pp wrote:

> > > E.g. there is the possibility that spilling one M8 register allows 8 M1 registers to avoid spills.
> > 
> > 
> > I don't think this is possible in current greedy RA (please correct me if my understanding is wrong). When spilling, we compare the weights of candidates one by one, because we can easily compare the live intervals of two registers. But when it comes to 8 registers, there are some problems: how can we compare the live intervals? how can compare the weight of one register with the weight of 8 registers (that means, how can we calculate one weight from 8 weights?), etc.
> 
> I agree that the eviction advisor isn't currently taking regunits/register size into account, but I don't see how that wouldn't make it possible for an LMUL 8 spill to avoid 8 M1 spills.
> 
> From my understanding of `DefaultEvictionAdvisor::canEvictInterferenceBasedOnCost`, when choosing a register to evict it just goes through the registers in the allocation order and picks the one with the smallest spill weight in its interferences.
> 
> So if an interfering LMUL 8 LiveInterval has a smaller spill weight, e.g. is only used once, it may get evicted instead of an LMUL 1 LiveInterval with say two uses (higher spill weight).
> 
> If the LMUL 8 LiveInterval is evicted and subsequently spilled, then 8 more regunits become free which can prevent further spilling.
> 
> So the eviction advisor doesn't take into account the number of regunits (size of the registers), only the spill weights (the frequency with which they're used).
> 
> I think the bit I would like to get clarity on is, are we conflating two separate metrics here, the frequency with which a LiveInterval would need to be spilled and reloaded, vs the size of the spills? Because currently spill weights are based on the former, and this PR is now adding the latter

Oh I know your point here! Here is my thinking: I think the `frequency` and the `size` here are the same thing as long as we are using reg units to scale the weight. For example, for a LMUL 8 register, we can consider it as that all its 8 registers have one use, `frequency+=8` and also `size+=8`. Maybe thinking in this way will make this patch more straightforward?

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


More information about the llvm-commits mailing list