Skip to content

Commit 67f1c03

Browse files
authored
[VPlan] Remove createReduction. NFCI (#131336)
This is split off from #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 54cb405 commit 67f1c03

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
@@ -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: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,8 @@ Value *llvm::createSimpleReduction(VectorBuilder &VBuilder, Value *Src,
13361336
const RecurrenceDescriptor &Desc) {
13371337
RecurKind Kind = Desc.getRecurrenceKind();
13381338
assert(!RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind) &&
1339-
"AnyOf reduction is not supported.");
1339+
!RecurrenceDescriptor::isFindLastIVRecurrenceKind(Kind) &&
1340+
"AnyOf or FindLastIV reductions are not supported.");
13401341
Intrinsic::ID Id = getReductionIntrinsicID(Kind);
13411342
auto *SrcTy = cast<VectorType>(Src->getType());
13421343
Type *SrcEltTy = SrcTy->getElementType();
@@ -1345,24 +1346,6 @@ Value *llvm::createSimpleReduction(VectorBuilder &VBuilder, Value *Src,
13451346
return VBuilder.createSimpleReduction(Id, SrcTy, Ops);
13461347
}
13471348

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-
13661349
Value *llvm::createOrderedReduction(IRBuilderBase &B,
13671350
const RecurrenceDescriptor &Desc,
13681351
Value *Src, Value *Start) {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,21 @@ Value *VPInstruction::generate(VPTransformState &State) {
672672
RecurrenceDescriptor::isAnyOfRecurrenceKind(RK) ||
673673
RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK)) &&
674674
!PhiR->isInLoop()) {
675-
ReducedPartRdx =
676-
createReduction(Builder, RdxDesc, ReducedPartRdx, OrigPhi);
675+
// TODO: Support in-order reductions based on the recurrence descriptor.
676+
// All ops in the reduction inherit fast-math-flags from the recurrence
677+
// descriptor.
678+
IRBuilderBase::FastMathFlagGuard FMFG(Builder);
679+
Builder.setFastMathFlags(RdxDesc.getFastMathFlags());
680+
681+
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK))
682+
ReducedPartRdx =
683+
createAnyOfReduction(Builder, ReducedPartRdx, RdxDesc, OrigPhi);
684+
else if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK))
685+
ReducedPartRdx =
686+
createFindLastIVReduction(Builder, ReducedPartRdx, RdxDesc);
687+
else
688+
ReducedPartRdx = createSimpleReduction(Builder, ReducedPartRdx, RK);
689+
677690
// If the reduction can be performed in a smaller type, we need to extend
678691
// the reduction to the wider type before we branch to the original loop.
679692
if (PhiTy != RdxDesc.getRecurrenceType())
@@ -2306,7 +2319,7 @@ void VPReductionRecipe::execute(VPTransformState &State) {
23062319
NextInChain = NewRed;
23072320
} else {
23082321
PrevInChain = State.get(getChainOp(), /*IsScalar*/ true);
2309-
NewRed = createReduction(State.Builder, RdxDesc, NewVecOp);
2322+
NewRed = createSimpleReduction(State.Builder, NewVecOp, Kind);
23102323
if (RecurrenceDescriptor::isMinMaxRecurrenceKind(Kind))
23112324
NextInChain = createMinMaxOp(State.Builder, RdxDesc.getRecurrenceKind(),
23122325
NewRed, PrevInChain);

0 commit comments

Comments
 (0)