Skip to content

Commit 9241f0a

Browse files
committed
[VPlan] Remove createReduction. NFCI
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 fc8b2bf commit 9241f0a

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

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

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

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

llvm/lib/Transforms/Utils/LoopUtils.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,24 +1345,6 @@ Value *llvm::createSimpleReduction(VectorBuilder &VBuilder, Value *Src,
13451345
return VBuilder.createSimpleReduction(Id, SrcTy, Ops);
13461346
}
13471347

1348-
Value *llvm::createReduction(IRBuilderBase &B,
1349-
const RecurrenceDescriptor &Desc, Value *Src,
1350-
PHINode *OrigPhi) {
1351-
// TODO: Support in-order reductions based on the recurrence descriptor.
1352-
// All ops in the reduction inherit fast-math-flags from the recurrence
1353-
// descriptor.
1354-
IRBuilderBase::FastMathFlagGuard FMFGuard(B);
1355-
B.setFastMathFlags(Desc.getFastMathFlags());
1356-
1357-
RecurKind RK = Desc.getRecurrenceKind();
1358-
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK))
1359-
return createAnyOfReduction(B, Src, Desc, OrigPhi);
1360-
if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK))
1361-
return createFindLastIVReduction(B, Src, Desc);
1362-
1363-
return createSimpleReduction(B, Src, RK);
1364-
}
1365-
13661348
Value *llvm::createOrderedReduction(IRBuilderBase &B,
13671349
const RecurrenceDescriptor &Desc,
13681350
Value *Src, Value *Start) {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,21 @@ Value *VPInstruction::generate(VPTransformState &State) {
666666
RecurrenceDescriptor::isAnyOfRecurrenceKind(RK) ||
667667
RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK)) &&
668668
!PhiR->isInLoop()) {
669-
ReducedPartRdx =
670-
createReduction(Builder, RdxDesc, ReducedPartRdx, OrigPhi);
669+
// TODO: Support in-order reductions based on the recurrence descriptor.
670+
// All ops in the reduction inherit fast-math-flags from the recurrence
671+
// descriptor.
672+
IRBuilderBase::FastMathFlagGuard FMFG(Builder);
673+
Builder.setFastMathFlags(RdxDesc.getFastMathFlags());
674+
675+
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK))
676+
ReducedPartRdx =
677+
createAnyOfReduction(Builder, ReducedPartRdx, RdxDesc, OrigPhi);
678+
else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK))
679+
ReducedPartRdx =
680+
createFindLastIVReduction(Builder, ReducedPartRdx, RdxDesc);
681+
else
682+
ReducedPartRdx = createSimpleReduction(Builder, ReducedPartRdx, RK);
683+
671684
// If the reduction can be performed in a smaller type, we need to extend
672685
// the reduction to the wider type before we branch to the original loop.
673686
if (PhiTy != RdxDesc.getRecurrenceType())
@@ -2297,7 +2310,7 @@ void VPReductionRecipe::execute(VPTransformState &State) {
22972310
NextInChain = NewRed;
22982311
} else {
22992312
PrevInChain = State.get(getChainOp(), /*IsScalar*/ true);
2300-
NewRed = createReduction(State.Builder, RdxDesc, NewVecOp);
2313+
NewRed = createSimpleReduction(State.Builder, NewVecOp, Kind);
23012314
if (RecurrenceDescriptor::isMinMaxRecurrenceKind(Kind))
23022315
NextInChain = createMinMaxOp(State.Builder, RdxDesc.getRecurrenceKind(),
23032316
NewRed, PrevInChain);

0 commit comments

Comments
 (0)