Skip to content

Commit 2483a29

Browse files
committed
!fixup, Update inferScalarType and not clear the VF of plan.
1 parent 36e1032 commit 2483a29

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9469,13 +9469,17 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
94699469
CostCtx, Range);
94709470
}
94719471

9472-
// Update VF after convertToAbstractRecipes. Cannot set the VF here since
9472+
// Update VF after `convertToAbstractRecipes`. Cannot set the VF here since
94739473
// `handleUncountableEarlyExit` will check the VF of the plan, need to set
94749474
// before it and update.
94759475
// TODO: Use a better method that only set the VF for plan once.
9476-
Plan->clearVF();
9477-
for (ElementCount VF : Range)
9478-
Plan->addVF(VF);
9476+
SmallVector<ElementCount, 2> VFToRemove;
9477+
for (ElementCount VF : Plan->vectorFactors())
9478+
if (!Range.contains(VF))
9479+
VFToRemove.push_back(VF);
9480+
9481+
for (ElementCount VF : VFToRemove)
9482+
Plan->removeVF(VF);
94799483

94809484
// Interleave memory: for each Interleave Group we marked earlier as relevant
94819485
// for this VPlan, replace the Recipes widening its memory instructions with a

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3797,7 +3797,7 @@ class VPlan {
37973797
VFs.insert(VF);
37983798
}
37993799

3800-
void clearVF() { VFs.clear(); }
3800+
void removeVF(ElementCount VF) { VFs.remove(VF); }
38013801

38023802
bool hasVF(ElementCount VF) const { return VFs.count(VF); }
38033803
bool hasScalableVF() const {

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
273273
[](const VPWidenCastRecipe *R) { return R->getResultType(); })
274274
.Case<VPScalarCastRecipe>(
275275
[](const VPScalarCastRecipe *R) { return R->getResultType(); })
276+
.Case<VPExtendedReductionRecipe>(
277+
[](const VPExtendedReductionRecipe *R) {
278+
return R->getResultType();
279+
})
280+
.Case<VPMulAccumulateReductionRecipe>(
281+
[](const VPMulAccumulateReductionRecipe *R) {
282+
return R->getResultType();
283+
})
276284
.Case<VPExpandSCEVRecipe>([](const VPExpandSCEVRecipe *R) {
277285
return R->getSCEV()->getType();
278286
})

llvm/lib/Transforms/Vectorize/VPlanHelpers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ struct VFRange {
7878
return End.getKnownMinValue() <= Start.getKnownMinValue();
7979
}
8080

81+
bool contains(const ElementCount &VF) const {
82+
return VF.getKnownMinValue() >= Start.getKnownMinValue() &&
83+
VF.getKnownMinValue() < End.getKnownMinValue();
84+
}
85+
8186
VFRange(const ElementCount &Start, const ElementCount &End)
8287
: Start(Start), End(End) {
8388
assert(Start.isScalable() == End.isScalable() &&

0 commit comments

Comments
 (0)