[llvm] [SLP] Support ordered fadd reduction via reduction intrinsics (PR #189451)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Sat May 9 14:20:39 PDT 2026
================
@@ -29046,6 +29138,239 @@ class HorizontalReduction {
return VectorizedTree;
}
+ /// Attempt to vectorize an ordered (linearized) reduction chain.
+ /// Reduced values from matchOrderedReduction() are in accumulation order.
+ /// Vectorized subsets are immediately reduced via ordered reduction
+ /// intrinsics; non-vectorized values are folded linearly.
+ Value *tryToReduceOrdered(BoUpSLP &V, const DataLayout &DL,
+ TargetTransformInfo *TTI,
+ const TargetLibraryInfo &TLI, AssumptionCache *AC,
+ DominatorTree &DT) {
+ constexpr unsigned RegMaxNumber = 4;
+ constexpr unsigned RedValsMaxNumber = 128;
+
+ assert(RK == ReductionOrdering::Ordered && "Expected ordered reduction");
+ assert(ReducedVals.size() == 1 &&
+ "Expected single group from matchOrderedReduction");
+
+ IRBuilder<TargetFolder> Builder(ReductionRoot->getContext(),
+ TargetFolder(DL));
+ Instruction *RdxRootInst = cast<Instruction>(ReductionRoot);
+ Builder.SetInsertPoint(RdxRootInst);
+
+ SmallVector<Value *> Candidates(ReducedVals.back());
+
+ // Intersect the fast-math-flags from all reduction operations.
+ FastMathFlags RdxFMF;
+ RdxFMF.set();
+ for (Value *RdxVal : Candidates)
+ for (Instruction *Op : ReducedValsToOps.at(RdxVal))
+ if (auto *FPMO = dyn_cast<FPMathOperator>(Op))
+ RdxFMF &= FPMO->getFastMathFlags();
----------------
alexey-bataev wrote:
reassoc reductions are handled by the different code, these are associative reductions. Why llvm.vector.partial.reduce.fadd is better? Plus, this is unrelated change
https://github.com/llvm/llvm-project/pull/189451
More information about the llvm-commits
mailing list