From: Sander de Smalen Date: Fri, 6 Nov 2020 09:03:23 +0000 (+0000) Subject: [VPlan] NFC: Change VFRange to take ElementCount X-Git-Tag: llvmorg-13-init~6885 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a3bb9ea6c0da96053c83561340d3c55a889324a;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 4925bb1..27edfd6 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7183,11 +7183,12 @@ static void AddRuntimeUnrollDisableMetaData(Loop *L) { bool LoopVectorizationPlanner::getDecisionAndClampRange( const std::function &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); diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 81a9d67..56b19b5 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -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;