diff options
author | Kerry McLaughlin <kerry.mclaughlin@arm.com> | 2021-04-06 13:28:14 +0100 |
---|---|---|
committer | Kerry McLaughlin <kerry.mclaughlin@arm.com> | 2021-04-06 14:45:34 +0100 |
commit | 7344f3d39a0dc934b22ee43b4f92160fc3ea2db6 (patch) | |
tree | 30f6447910ac063008122bfa7c90dadde63d595d /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | 88c2454057b6cd1b122f7fadde666e6b8ea6ebd3 (diff) | |
download | llvm-7344f3d39a0dc934b22ee43b4f92160fc3ea2db6.zip llvm-7344f3d39a0dc934b22ee43b4f92160fc3ea2db6.tar.gz llvm-7344f3d39a0dc934b22ee43b4f92160fc3ea2db6.tar.bz2 |
[LoopVectorize] Add strict in-order reduction support for fixed-width vectorization
Previously we could only vectorize FP reductions if fast math was enabled, as this allows us to
reorder FP operations. However, it may still be beneficial to vectorize the loop by moving
the reduction inside the vectorized loop and making sure that the scalar reduction value
be an input to the horizontal reduction, e.g:
%phi = phi float [ 0.0, %entry ], [ %reduction, %vector_body ]
%load = load <8 x float>
%reduction = call float @llvm.vector.reduce.fadd.v8f32(float %phi, <8 x float> %load)
This patch adds a new flag (IsOrdered) to RecurrenceDescriptor and makes use of the changes added
by D75069 as much as possible, which already teaches the vectorizer about in-loop reductions.
For now in-order reduction support is off by default and controlled with the `-enable-strict-reductions` flag.
Reviewed By: david-arm
Differential Revision: https://reviews.llvm.org/D98435
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index d2482fe..7f1bbeb 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1070,6 +1070,17 @@ Value *llvm::createTargetReduction(IRBuilderBase &B, return createSimpleTargetReduction(B, TTI, Src, Desc.getRecurrenceKind()); } +Value *llvm::createOrderedReduction(IRBuilderBase &B, + RecurrenceDescriptor &Desc, Value *Src, + Value *Start) { + auto Kind = Desc.getRecurrenceKind(); + assert(Kind == RecurKind::FAdd && "Unexpected reduction kind"); + assert(Src->getType()->isVectorTy() && "Expected a vector type"); + assert(!Start->getType()->isVectorTy() && "Expected a scalar type"); + + return B.CreateFAddReduce(Start, Src); +} + void llvm::propagateIRFlags(Value *I, ArrayRef<Value *> VL, Value *OpValue) { auto *VecOp = dyn_cast<Instruction>(I); if (!VecOp) |