[llvm-branch-commits] [llvm] [LV] Reduce register usage for scaled reductions (PR #133090)
David Sherwood via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Apr 7 08:34:29 PDT 2025
================
@@ -5039,10 +5039,25 @@ calculateRegisterUsage(VPlan &Plan, ArrayRef<ElementCount> VFs,
// even in the scalar case.
RegUsage[ClassID] += 1;
} else {
+ // The output from scaled phis and scaled reductions actually have
+ // fewer lanes than the VF.
+ ElementCount VF = VFs[J];
+ if (auto *ReductionR = dyn_cast<VPReductionPHIRecipe>(R))
----------------
david-arm wrote:
I realise it may be less efficient, but perhaps it's better to commonise these into the same block? If for some reason we need to update this logic in future it's easier to fix it only once, i.e.
```
if (isa<VPReductionPHIRecipe, VPPartialReductionRecipe>(R)) {
auto *ReductionR = dyn_cast<VPReductionPHIRecipe>(R);
auto *PartialReductionR = dyn_cast<VPPartialReductionRecipe>(R);
unsigned ScaleFactor = ReductionR ? ReductionR->getVFScaleFactor() : PartialReductionR->getVFScaleFactor();
VF = VF.divideCoefficientBy(ScaleFactor);
}
```
If `getVFScaleFactor` becomes available to a common base class then it should simplify further. What do you think?
https://github.com/llvm/llvm-project/pull/133090
More information about the llvm-branch-commits
mailing list