[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:28:59 PDT 2026
================
@@ -4687,22 +4684,23 @@ LoopVectorizationPlanner::selectInterleaveCount(VPlan &Plan, ElementCount VF,
if (hasFindLastReductionPhi(Plan))
return 1;
+ VPRegisterUsage R =
+ calculateRegisterUsageForPlan(Plan, {VF}, TTI, CM.ValuesToIgnore)[0];
+
// If we did not calculate the cost for VF (because the user selected the VF)
// then we calculate the cost of VF here.
if (LoopCost == 0) {
if (VF.isScalar())
LoopCost = CM.expectedCost(VF);
else
- LoopCost = cost(Plan, VF);
+ LoopCost = cost(Plan, VF, &R);
----------------
john-brawn-arm wrote:
Looking at the debug output for test/Transforms/LoopVectorize/ARM/mve-reg-pressure-spills.ll with this PR as it currently is, it has
```
Cost of 1 for VF 2: induction instruction %inc = add nuw i32 %i, 1
Cost of 0 for VF 2: induction instruction %i = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
... lots of instructions skipped ...
Cost of 0 for VF 2: IR %acc6.next.lcssa = phi float [ %acc6.next, %for.body ] (extra operand: vp<%29> from middle.block)
Cost of 0 for VF 2: IR %acc7.next.lcssa = phi float [ %acc7.next, %for.body ] (extra operand: vp<%28> from middle.block)
LV(REG): Cost of 50 from 25 spills of Generic::VectorRC
Cost for VF 2: 444 (Estimated cost per lane: 222.0)
Cost of 1 for VF 4: induction instruction %inc = add nuw i32 %i, 1
Cost of 0 for VF 4: induction instruction %i = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
... lots of instructions skipped ...
Cost of 0 for VF 4: IR %acc6.next.lcssa = phi float [ %acc6.next, %for.body ] (extra operand: vp<%29> from middle.block)
Cost of 0 for VF 4: IR %acc7.next.lcssa = phi float [ %acc7.next, %for.body ] (extra operand: vp<%28> from middle.block)
LV(REG): Cost of 50 from 25 spills of Generic::VectorRC
Cost for VF 4: 388 (Estimated cost per lane: 97.0)
LV: Found an estimated cost of 0 for VF 1 For instruction: %i = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
LV: Found an estimated cost of 0 for VF 1 For instruction: %x4 = phi float [ %x4.next, %for.body ], [ 0.000000e+00, %for.body.preheader ]
... etc
```
It consists of, for each VF:
* a line for each instruction in the VPlan with how much it costs for that VF
* a line for each register class with spills saying how much it cost
* the total cost for that VF, which is all of the previous numbers added together
The total cost is printed in LoopVectorizationPlanner::cost. Adding and printing the cost after the call to cost would mean the "Cost for VF" line would be wrong, as it wouldn't contain the cost of the spills. We could possibly print the total cost of spills in addition to the cost of spills for each register class, but then we lose the property that the "Cost for VF" value is the sum of all the previous values, and it doesn't seem that useful.
https://github.com/llvm/llvm-project/pull/179646
More information about the llvm-commits
mailing list