Skip to content

Commit 7bd096b

Browse files
lukel97pawosm-arm
authored andcommitted
[VPlan] Remove createReduction. NFCI (llvm#131336)
This is split off from llvm#131300. A VPReductionRecipe will never have a AnyOf or FindLastIV recurrence, so when it calls createReduction it always calls createSimpleReduction. If we replace the call then it leaves createReduction with one user in VPInstruction::ComputeReductionResult, which we can inline and then remove.
1 parent 11ad62c commit 7bd096b

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

llvm/include/llvm/Transforms/Utils/LoopUtils.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,6 @@ Value *createAnyOfReduction(IRBuilderBase &B, Value *Src,
425425
Value *createFindLastIVReduction(IRBuilderBase &B, Value *Src,
426426
const RecurrenceDescriptor &Desc);
427427

428-
/// Create a generic reduction using a recurrence descriptor \p Desc
429-
/// Fast-math-flags are propagated using the RecurrenceDescriptor.
430-
Value *createReduction(IRBuilderBase &B, const RecurrenceDescriptor &Desc,
431-
Value *Src, PHINode *OrigPhi = nullptr);
432-
433428
/// Create an ordered reduction intrinsic using the given recurrence
434429
/// descriptor \p Desc.
435430
Value *createOrderedReduction(IRBuilderBase &B,

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,8 @@ Value *llvm::createSimpleReduction(VectorBuilder &VBuilder, Value *Src,
13111311
const RecurrenceDescriptor &Desc) {
13121312
RecurKind Kind = Desc.getRecurrenceKind();
13131313
assert(!RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind) &&
1314-
"AnyOf reduction is not supported.");
1314+
!RecurrenceDescriptor::isFindLastIVRecurrenceKind(Kind) &&
1315+
"AnyOf or FindLastIV reductions are not supported.");
13151316
Intrinsic::ID Id = getReductionIntrinsicID(Kind);
13161317
auto *SrcTy = cast<VectorType>(Src->getType());
13171318
Type *SrcEltTy = SrcTy->getElementType();
@@ -1320,24 +1321,6 @@ Value *llvm::createSimpleReduction(VectorBuilder &VBuilder, Value *Src,
13201321
return VBuilder.createSimpleReduction(Id, SrcTy, Ops);
13211322
}
13221323

1323-
Value *llvm::createReduction(IRBuilderBase &B,
1324-
const RecurrenceDescriptor &Desc, Value *Src,
1325-
PHINode *OrigPhi) {
1326-
// TODO: Support in-order reductions based on the recurrence descriptor.
1327-
// All ops in the reduction inherit fast-math-flags from the recurrence
1328-
// descriptor.
1329-
IRBuilderBase::FastMathFlagGuard FMFGuard(B);
1330-
B.setFastMathFlags(Desc.getFastMathFlags());
1331-
1332-
RecurKind RK = Desc.getRecurrenceKind();
1333-
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK))
1334-
return createAnyOfReduction(B, Src, Desc, OrigPhi);
1335-
if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK))
1336-
return createFindLastIVReduction(B, Src, Desc);
1337-
1338-
return createSimpleReduction(B, Src, RK);
1339-
}
1340-
13411324
Value *llvm::createOrderedReduction(IRBuilderBase &B,
13421325
const RecurrenceDescriptor &Desc,
13431326
Value *Src, Value *Start) {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,21 @@ Value *VPInstruction::generate(VPTransformState &State) {
633633
RecurrenceDescriptor::isAnyOfRecurrenceKind(RK) ||
634634
RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK)) &&
635635
!PhiR->isInLoop()) {
636-
ReducedPartRdx =
637-
createReduction(Builder, RdxDesc, ReducedPartRdx, OrigPhi);
636+
// TODO: Support in-order reductions based on the recurrence descriptor.
637+
// All ops in the reduction inherit fast-math-flags from the recurrence
638+
// descriptor.
639+
IRBuilderBase::FastMathFlagGuard FMFG(Builder);
640+
Builder.setFastMathFlags(RdxDesc.getFastMathFlags());
641+
642+
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK))
643+
ReducedPartRdx =
644+
createAnyOfReduction(Builder, ReducedPartRdx, RdxDesc, OrigPhi);
645+
else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK))
646+
ReducedPartRdx =
647+
createFindLastIVReduction(Builder, ReducedPartRdx, RdxDesc);
648+
else
649+
ReducedPartRdx = createSimpleReduction(Builder, ReducedPartRdx, RK);
650+
638651
// If the reduction can be performed in a smaller type, we need to extend
639652
// the reduction to the wider type before we branch to the original loop.
640653
if (PhiTy != RdxDesc.getRecurrenceType())
@@ -2252,7 +2265,7 @@ void VPReductionRecipe::execute(VPTransformState &State) {
22522265
NextInChain = NewRed;
22532266
} else {
22542267
PrevInChain = State.get(getChainOp(), /*IsScalar*/ true);
2255-
NewRed = createReduction(State.Builder, RdxDesc, NewVecOp);
2268+
NewRed = createSimpleReduction(State.Builder, NewVecOp, Kind);
22562269
if (RecurrenceDescriptor::isMinMaxRecurrenceKind(Kind))
22572270
NextInChain = createMinMaxOp(State.Builder, RdxDesc.getRecurrenceKind(),
22582271
NewRed, PrevInChain);

0 commit comments

Comments
 (0)