Skip to content

Commit dbb4f5c

Browse files
committed
[VPlan] Set VF scale factor in tryToCreatePartialReduction (NFCI).
Split off unrelated change from approved #168291 to land separately as suggested.
1 parent 691b04d commit dbb4f5c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8247,8 +8247,8 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
82478247
// If the PHI is used by a partial reduction, set the scale factor.
82488248
bool UseInLoopReduction = CM.isInLoopReduction(Phi);
82498249
bool UseOrderedReductions = CM.useOrderedReductions(RdxDesc);
8250-
unsigned ScaleFactor =
8251-
getScalingForReduction(RdxDesc.getLoopExitInstr()).value_or(1);
8250+
// Will be updated later to >1 if reduction is partial.
8251+
unsigned ScaleFactor = 1;
82528252

82538253
return new VPReductionPHIRecipe(
82548254
Phi, RdxDesc.getRecurrenceKind(), *StartV, *BackedgeValue,
@@ -8327,6 +8327,9 @@ VPRecipeBuilder::tryToCreatePartialReduction(VPInstruction *Reduction,
83278327
cast<VPReductionRecipe>(BinOpRecipe)->isPartialReduction()))
83288328
std::swap(BinOp, Accumulator);
83298329

8330+
if (auto *RedPhiR = dyn_cast<VPReductionPHIRecipe>(Accumulator))
8331+
RedPhiR->setVFScaleFactor(ScaleFactor);
8332+
83308333
assert(ScaleFactor ==
83318334
vputils::getVFScaleFactor(Accumulator->getDefiningRecipe()) &&
83328335
"all accumulators in chain must have same scale factor");

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,13 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe,
24742474
return Partial ? Partial->VFScaleFactor : 1;
24752475
}
24762476

2477+
/// Set the VFScaleFactor for this reduction phi. Can only be set to a factor
2478+
/// > 1.
2479+
void setVFScaleFactor(unsigned ScaleFactor) {
2480+
assert(ScaleFactor > 1 && "must set to scale factor > 1");
2481+
Style = RdxUnordered{ScaleFactor};
2482+
}
2483+
24772484
/// Returns the number of incoming values, also number of incoming blocks.
24782485
/// Note that at the moment, VPWidenPointerInductionRecipe only has a single
24792486
/// incoming value, its start value.

0 commit comments

Comments
 (0)