[llvm] [VPlan] Add the cost of spills when considering register pressure (PR #179646)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 12 08:21:10 PDT 2026
================
@@ -389,13 +389,25 @@ bool VPDominatorTree::properlyDominates(const VPRecipeBase *A,
return Base::properlyDominates(ParentA, ParentB);
}
-bool VPRegisterUsage::exceedsMaxNumRegs(const TargetTransformInfo &TTI,
- unsigned OverrideMaxNumRegs) const {
- return any_of(MaxLocalUsers, [&TTI, &OverrideMaxNumRegs](auto &LU) {
- return LU.second > (OverrideMaxNumRegs > 0
- ? OverrideMaxNumRegs
- : TTI.getNumberOfRegisters(LU.first));
- });
+InstructionCost VPRegisterUsage::spillCost(VPCostContext &Ctx,
+ unsigned OverrideMaxNumRegs) const {
+ InstructionCost Cost;
+ for (const auto &[RegClass, MaxUsers] : MaxLocalUsers) {
+ unsigned AvailableRegs = OverrideMaxNumRegs > 0
+ ? OverrideMaxNumRegs
+ : Ctx.TTI.getNumberOfRegisters(RegClass);
+ if (MaxUsers > AvailableRegs) {
+ unsigned Spills = MaxUsers - AvailableRegs;
+ InstructionCost SpillCost =
+ Ctx.TTI.getRegisterClassSpillCost(RegClass, Ctx.CostKind);
----------------
lukel97 wrote:
Ah right, and I also don't see anything already in TTI that can get us from a register class to type. Not sure if that's something we necessarily even want to do though.
Can we change the hook to be the cost of either a single spill or reload though? Something like `getSpillCost(ClassID, CostKind)`/`getReloadCost(ClassID, CostKind)`. Since a single spill might have multiple reloads depending on the number of users etc, and maybe RegAlloc or MachineScheduler might want to use the hook to do more accurate costing.
But for the LV we can just do a single spill + reload like you've done in TTIImpl.
https://github.com/llvm/llvm-project/pull/179646
More information about the llvm-commits
mailing list