[VPlan] Allow building a VPlan to may fail.
Update the planning code constructing VPlan to allow building VPlans to fail. This allows us to gradually shift some legality checks to VPlan construction. The first candidate is checking if all users of first-order recurrence phis can be sunk past the recipe computing the previous value. The new functionality will be used by D142886 which is approved and will be landed shortly. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D142885
This commit is contained in:
@@ -350,9 +350,12 @@ private:
|
||||
|
||||
/// Build a VPlan using VPRecipes according to the information gather by
|
||||
/// Legal. This method is only used for the legacy inner loop vectorizer.
|
||||
VPlanPtr
|
||||
buildVPlanWithVPRecipes(VFRange &Range,
|
||||
SmallPtrSetImpl<Instruction *> &DeadInstructions);
|
||||
/// \p Range's largest included VF is restricted to the maximum VF the
|
||||
/// returned VPlan is valid for. If no VPlan can be built for the input range,
|
||||
/// set the largest included VF to the maximum VF for which no plan could be
|
||||
/// built.
|
||||
std::optional<VPlanPtr> tryToBuildVPlanWithVPRecipes(
|
||||
VFRange &Range, SmallPtrSetImpl<Instruction *> &DeadInstructions);
|
||||
|
||||
/// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,
|
||||
/// according to the information gathered by Legal when it checked if it is
|
||||
|
||||
@@ -7589,6 +7589,12 @@ LoopVectorizationPlanner::plan(ElementCount UserVF, unsigned UserIC) {
|
||||
LLVM_DEBUG(dbgs() << "LV: Using user VF " << UserVF << ".\n");
|
||||
CM.collectInLoopReductions();
|
||||
buildVPlansWithVPRecipes(UserVF, UserVF);
|
||||
if (!hasPlanWithVF(UserVF)) {
|
||||
LLVM_DEBUG(dbgs() << "LV: No VPlan could be built for " << UserVF
|
||||
<< ".\n");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
LLVM_DEBUG(printPlans(dbgs()));
|
||||
return {{UserVF, 0, 0}};
|
||||
} else
|
||||
@@ -7626,6 +7632,11 @@ LoopVectorizationPlanner::plan(ElementCount UserVF, unsigned UserIC) {
|
||||
// Select the optimal vectorization factor.
|
||||
VectorizationFactor VF = CM.selectVectorizationFactor(VFCandidates);
|
||||
assert((VF.Width.isScalar() || VF.ScalarCost > 0) && "when vectorizing, the scalar cost must be non-zero.");
|
||||
if (!hasPlanWithVF(VF.Width)) {
|
||||
LLVM_DEBUG(dbgs() << "LV: No VPlan could be built for " << VF.Width
|
||||
<< ".\n");
|
||||
return std::nullopt;
|
||||
}
|
||||
return VF;
|
||||
}
|
||||
|
||||
@@ -8722,7 +8733,8 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
|
||||
auto MaxVFTimes2 = MaxVF * 2;
|
||||
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
|
||||
VFRange SubRange = {VF, MaxVFTimes2};
|
||||
VPlans.push_back(buildVPlanWithVPRecipes(SubRange, DeadInstructions));
|
||||
if (auto Plan = tryToBuildVPlanWithVPRecipes(SubRange, DeadInstructions))
|
||||
VPlans.push_back(std::move(*Plan));
|
||||
VF = SubRange.End;
|
||||
}
|
||||
}
|
||||
@@ -8853,7 +8865,7 @@ static void addUsersInExitBlock(VPBasicBlock *HeaderVPBB,
|
||||
}
|
||||
}
|
||||
|
||||
VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
|
||||
std::optional<VPlanPtr> LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
|
||||
VFRange &Range, SmallPtrSetImpl<Instruction *> &DeadInstructions) {
|
||||
|
||||
SmallPtrSet<const InterleaveGroup<Instruction> *, 1> InterleaveGroups;
|
||||
|
||||
Reference in New Issue
Block a user