[llvm] [LV] Use VPReductionRecipe for partial reductions (PR #144908)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 24 01:27:44 PDT 2025
================
@@ -8367,12 +8373,10 @@ VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction,
"Expected an ADD or SUB operation for predicated partial "
"reductions (because the neutral element in the mask is zero)!");
Cond = getBlockInMask(Builder.getInsertBlock());
- VPValue *Zero =
- Plan.getOrAddLiveIn(ConstantInt::get(Reduction->getType(), 0));
- BinOp = Builder.createSelect(Cond, BinOp, Zero, Reduction->getDebugLoc());
}
- return new VPPartialReductionRecipe(ReductionOpcode, Accumulator, BinOp, Cond,
- ScaleFactor, Reduction);
+
+ return new VPReductionRecipe(RecurKind::Add, FastMathFlags(), Reduction,
+ Accumulator, BinOp, Cond, false, ScaleFactor);
----------------
sdesmalen-arm wrote:
Just sharing an observation in case other reviewers notice changes in CodeGen in `partial-reduce-dot-product-neon.ll`.
Passing in the condition to the VPReductionRecipe rather than creating a select on the input and passing that into the VPReductionRecipe results in different, but better, code for `partial-reduce-dot-product-neon.ll`. The test loads from two pointers `a` and `b`. Before this change, it would load lane `a[i]` and `b[i]` under two separate predicated blocks, i.e. `if(cond[i]) { load(a[i]) } `, `if(cond[i]) { load(b[i]) }`, whereas by moving the condition to the VPReductionRecipe it now bundles together these two predicated loads in a single condition block `if(cond[i]) { load(a[i]), load(b[i]) }`.
https://github.com/llvm/llvm-project/pull/144908
More information about the llvm-commits
mailing list