[VPlan] NFC: Change VFRange to take ElementCount

This patch changes the type of Start, End in VFRange to be an ElementCount
instead of `unsigned`. This is done as preparation to make VPlans for
scalable vectors, but is otherwise NFC.

Reviewed By: dmgreen, fhahn, vkmr

Differential Revision: https://reviews.llvm.org/D90715
This commit is contained in:
Sander de Smalen 2020-11-06 09:03:23 +00:00
parent 0c782c214b
commit 4a3bb9ea6c
2 changed files with 33 additions and 15 deletions

View File

@ -7183,11 +7183,12 @@ static void AddRuntimeUnrollDisableMetaData(Loop *L) {
bool LoopVectorizationPlanner::getDecisionAndClampRange(
const std::function<bool(ElementCount)> &Predicate, VFRange &Range) {
assert(Range.End > Range.Start && "Trying to test an empty VF range.");
bool PredicateAtRangeStart = Predicate(ElementCount::getFixed(Range.Start));
assert(!Range.isEmpty() && "Trying to test an empty VF range.");
bool PredicateAtRangeStart = Predicate(Range.Start);
for (unsigned TmpVF = Range.Start * 2; TmpVF < Range.End; TmpVF *= 2)
if (Predicate(ElementCount::getFixed(TmpVF)) != PredicateAtRangeStart) {
for (ElementCount TmpVF = Range.Start * 2;
ElementCount::isKnownLT(TmpVF, Range.End); TmpVF *= 2)
if (Predicate(TmpVF) != PredicateAtRangeStart) {
Range.End = TmpVF;
break;
}
@ -7201,8 +7202,10 @@ bool LoopVectorizationPlanner::getDecisionAndClampRange(
/// vectorization decision can potentially shorten this sub-range during
/// buildVPlan().
void LoopVectorizationPlanner::buildVPlans(unsigned MinVF, unsigned MaxVF) {
for (unsigned VF = MinVF; VF < MaxVF + 1;) {
VFRange SubRange = {VF, MaxVF + 1};
auto MaxVFPlusOne = ElementCount::getFixed(MaxVF).getWithIncrement(1);
for (ElementCount VF = ElementCount::getFixed(MinVF);
ElementCount::isKnownLT(VF, MaxVFPlusOne);) {
VFRange SubRange = {VF, MaxVFPlusOne};
VPlans.push_back(buildVPlan(SubRange));
VF = SubRange.End;
}
@ -7659,8 +7662,10 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(unsigned MinVF,
for (Instruction *I : DeadInstructions)
SinkAfter.erase(I);
for (unsigned VF = MinVF; VF < MaxVF + 1;) {
VFRange SubRange = {VF, MaxVF + 1};
auto MaxVFPlusOne = ElementCount::getFixed(MaxVF).getWithIncrement(1);
for (ElementCount VF = ElementCount::getFixed(MinVF);
ElementCount::isKnownLT(VF, MaxVFPlusOne);) {
VFRange SubRange = {VF, MaxVFPlusOne};
VPlans.push_back(buildVPlanWithVPRecipes(SubRange, NeedDef,
DeadInstructions, SinkAfter));
VF = SubRange.End;
@ -7837,7 +7842,7 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
}
// Adjust the recipes for any inloop reductions.
if (Range.Start > 1)
if (Range.Start.isVector())
adjustRecipesForInLoopReductions(Plan, RecipeBuilder);
// Finally, if tail is folded by masking, introduce selects between the phi
@ -7856,10 +7861,10 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
std::string PlanName;
raw_string_ostream RSO(PlanName);
ElementCount VF = ElementCount::getFixed(Range.Start);
ElementCount VF = Range.Start;
Plan->addVF(VF);
RSO << "Initial VPlan for VF={" << VF;
for (VF *= 2; VF.getKnownMinValue() < Range.End; VF *= 2) {
for (VF *= 2; ElementCount::isKnownLT(VF, Range.End); VF *= 2) {
Plan->addVF(VF);
RSO << "," << VF;
}
@ -7885,8 +7890,9 @@ VPlanPtr LoopVectorizationPlanner::buildVPlan(VFRange &Range) {
VPlanHCFGBuilder HCFGBuilder(OrigLoop, LI, *Plan);
HCFGBuilder.buildHierarchicalCFG();
for (unsigned VF = Range.Start; VF < Range.End; VF *= 2)
Plan->addVF(ElementCount::getFixed(VF));
for (ElementCount VF = Range.Start; ElementCount::isKnownLT(VF, Range.End);
VF *= 2)
Plan->addVF(VF);
if (EnableVPlanPredication) {
VPlanPredicator VPP(*Plan);

View File

@ -65,10 +65,22 @@ class VPlanSlp;
/// [1, 9) = {1, 2, 4, 8}
struct VFRange {
// A power of 2.
const unsigned Start;
const ElementCount Start;
// Need not be a power of 2. If End <= Start range is empty.
unsigned End;
ElementCount End;
bool isEmpty() const {
return End.getKnownMinValue() <= Start.getKnownMinValue();
}
VFRange(const ElementCount &Start, const ElementCount &End)
: Start(Start), End(End) {
assert(Start.isScalable() == End.isScalable() &&
"Both Start and End should have the same scalable flag");
assert(isPowerOf2_32(Start.getKnownMinValue()) &&
"Expected Start to be a power of 2");
}
};
using VPlanPtr = std::unique_ptr<VPlan>;