[llvm-branch-commits] [llvm] [LV] Choose best reduction for VPlan (PR #166138)
Sushant Gokhale via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 4 02:27:51 PST 2025
================
@@ -5679,6 +5679,18 @@ InstructionCost AArch64TTIImpl::getPartialReductionCost(
if (CostKind != TTI::TCK_RecipThroughput)
return Invalid;
+ unsigned Ratio =
+ AccumType->getScalarSizeInBits() / InputTypeA->getScalarSizeInBits();
+
+ // A ratio of 1 would mean it's similar to a regular add, e.g.
+ // v4i64 partial.reduce(v4i64 %acc, v4i64 %vec)
+ // <=> add v4i64 %acc, %vec
+ if (Ratio == 1) {
----------------
sushgokh wrote:
rather than checking for ratio=1, you should either replace
1. https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp#L323 with getArithmeticInstructionCost (I believe this line is simply checking for the simple add reduction)
OR
2. https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp#L3552 with getAirthmeticInstructionCost
https://github.com/llvm/llvm-project/pull/166138
More information about the llvm-branch-commits
mailing list