From: Florian Hahn Date: Sat, 8 Apr 2023 12:04:08 +0000 (+0100) Subject: [VPlan] Require VFRange.End to be a power-of-2. (NFCI) X-Git-Tag: upstream/17.0.6~12254 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c7a34d355a61396d438ea095e1e6996cde1ef880;p=platform%2Fupstream%2Fllvm.git [VPlan] Require VFRange.End to be a power-of-2. (NFCI) This removes the need to convert the end of the range to the next power-of-2 for the end iterator after 4bd3fda5124962 and was suggested as follow-up TODO in D147468. --- diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 914fc4e..1d6dfdd 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8067,9 +8067,9 @@ bool LoopVectorizationPlanner::getDecisionAndClampRange( /// buildVPlan(). void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF, ElementCount MaxVF) { - auto MaxVFPlusOne = MaxVF.getWithIncrement(1); - for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFPlusOne);) { - VFRange SubRange = {VF, MaxVFPlusOne}; + auto MaxVFTimes2 = MaxVF * 2; + for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) { + VFRange SubRange = {VF, MaxVFTimes2}; VPlans.push_back(buildVPlan(SubRange)); VF = SubRange.End; } @@ -8700,9 +8700,9 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF, auto &ConditionalAssumes = Legal->getConditionalAssumes(); DeadInstructions.insert(ConditionalAssumes.begin(), ConditionalAssumes.end()); - auto MaxVFPlusOne = MaxVF.getWithIncrement(1); - for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFPlusOne);) { - VFRange SubRange = {VF, MaxVFPlusOne}; + auto MaxVFTimes2 = MaxVF * 2; + for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) { + VFRange SubRange = {VF, MaxVFTimes2}; VPlans.push_back(buildVPlanWithVPRecipes(SubRange, DeadInstructions)); VF = SubRange.End; } diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index e49ac0a..b344fd1 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -80,12 +80,12 @@ const SCEV *createTripCountSCEV(Type *IdxTy, PredicatedScalarEvolution &PSE); /// A range of powers-of-2 vectorization factors with fixed start and /// adjustable end. The range includes start and excludes end, e.g.,: -/// [1, 9) = {1, 2, 4, 8} +/// [1, 16) = {1, 2, 4, 8} struct VFRange { // A power of 2. const ElementCount Start; - // Need not be a power of 2. If End <= Start range is empty. + // A power of 2. If End <= Start range is empty. ElementCount End; bool isEmpty() const { @@ -98,6 +98,8 @@ struct VFRange { "Both Start and End should have the same scalable flag"); assert(isPowerOf2_32(Start.getKnownMinValue()) && "Expected Start to be a power of 2"); + assert(isPowerOf2_32(End.getKnownMinValue()) && + "Expected End to be a power of 2"); } /// Iterator to iterate over vectorization factors in a VFRange. @@ -121,13 +123,8 @@ struct VFRange { iterator begin() { return iterator(Start); } iterator end() { - ElementCount EndVF = End; - // Make sure the end iterator is a power-of-2 so != comparisons with end - // work as expected. - if (!isPowerOf2_64(End.getKnownMinValue())) - EndVF = ElementCount::get(NextPowerOf2(End.getKnownMinValue()), - End.isScalable()); - return iterator(EndVF); + assert(isPowerOf2_32(End.getKnownMinValue())); + return iterator(End); } };