[llvm] [VPlan] Add the cost of spills when considering register pressure (PR #179646)

John Brawn via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 12 07:41:18 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);
----------------
john-brawn-arm wrote:

As I mentioned in https://github.com/llvm/llvm-project/pull/179646#discussion_r2848028620 doing things in terms of types doesn't work, because it's ultimately registers that get spilled (and we already use getRegUsageForType so get the number of registers used for each type). So I we need _something_ in TTI, that gets us from registers spilled to a cost, though there may be a better way to do this than a getRegisterClassSpillCost function. Possibly we could add a function to get a representative type for a register class which we could then pass to getMemoryOpCost, but it's not clear to me how we could implement a generic versoin of this in TargetTransformInfoImpl.

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


More information about the llvm-commits mailing list