diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 0fd425c23c7aa..22662abc460bb 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8679,14 +8679,14 @@ void LoopVectorizationPlanner::attachRuntimeChecks( void LoopVectorizationPlanner::addMinimumIterationCheck( VPlan &Plan, ElementCount VF, unsigned UF, ElementCount MinProfitableTripCount) const { - const uint32_t *BranchWeigths = + const uint32_t *BranchWeights = hasBranchWeightMD(*OrigLoop->getLoopLatch()->getTerminator()) ? &MinItersBypassWeights[0] : nullptr; VPlanTransforms::addMinimumIterationCheck( Plan, VF, UF, MinProfitableTripCount, CM.requiresScalarEpilogue(VF.isVector()), CM.foldTailByMasking(), - /*CheckNeededWithTailFolding=*/false, OrigLoop, BranchWeigths, + OrigLoop, BranchWeights, OrigLoop->getLoopPredecessor()->getTerminator()->getDebugLoc(), PSE); } diff --git a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp index 3101b42625c53..62e3e90e75054 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp @@ -1038,9 +1038,8 @@ void VPlanTransforms::attachCheckBlock(VPlan &Plan, Value *Cond, void VPlanTransforms::addMinimumIterationCheck( VPlan &Plan, ElementCount VF, unsigned UF, ElementCount MinProfitableTripCount, bool RequiresScalarEpilogue, - bool TailFolded, bool CheckNeededWithTailFolding, Loop *OrigLoop, - const uint32_t *MinItersBypassWeights, DebugLoc DL, - PredicatedScalarEvolution &PSE) { + bool TailFolded, Loop *OrigLoop, const uint32_t *MinItersBypassWeights, + DebugLoc DL, PredicatedScalarEvolution &PSE) { // Generate code to check if the loop's trip count is less than VF * UF, or // equal to it in case a scalar epilogue is required; this implies that the // vector trip count is zero. This check also covers the case where adding one @@ -1071,30 +1070,9 @@ void VPlanTransforms::addMinimumIterationCheck( VPBuilder Builder(EntryVPBB); VPValue *TripCountCheck = Plan.getFalse(); const SCEV *Step = GetMinTripCount(); - if (TailFolded) { - if (CheckNeededWithTailFolding) { - // vscale is not necessarily a power-of-2, which means we cannot guarantee - // an overflow to zero when updating induction variables and so an - // additional overflow check is required before entering the vector loop. - - VPValue *StepVPV = Builder.createExpandSCEV(Step); - - // Get the maximum unsigned value for the type. - VPValue *MaxUIntTripCount = - Plan.getConstantInt(cast(TripCountTy)->getMask()); - VPValue *DistanceToMax = - Builder.createSub(MaxUIntTripCount, TripCountVPV); - - // Don't execute the vector loop if (UMax - n) < (VF * UF). - // FIXME: Should only check VF * UF, but currently checks Step=max(VF*UF, - // minProfitableTripCount). - TripCountCheck = - Builder.createICmp(ICmpInst::ICMP_ULT, DistanceToMax, StepVPV, DL); - } else { - // TripCountCheck = false, folding tail implies positive vector trip - // count. - } - } else { + // TripCountCheck = false, folding tail implies positive vector trip + // count. + if (!TailFolded) { // TODO: Emit unconditional branch to vector preheader instead of // conditional branch with known condition. TripCount = SE.applyLoopGuards(TripCount, OrigLoop); diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h index 7c5d44daf003f..f0af6360bf9e4 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h @@ -158,13 +158,11 @@ struct VPlanTransforms { bool TailFolded); // Create a check to \p Plan to see if the vector loop should be executed. - static void - addMinimumIterationCheck(VPlan &Plan, ElementCount VF, unsigned UF, - ElementCount MinProfitableTripCount, - bool RequiresScalarEpilogue, bool TailFolded, - bool CheckNeededWithTailFolding, Loop *OrigLoop, - const uint32_t *MinItersBypassWeights, DebugLoc DL, - PredicatedScalarEvolution &PSE); + static void addMinimumIterationCheck( + VPlan &Plan, ElementCount VF, unsigned UF, + ElementCount MinProfitableTripCount, bool RequiresScalarEpilogue, + bool TailFolded, Loop *OrigLoop, const uint32_t *MinItersBypassWeights, + DebugLoc DL, PredicatedScalarEvolution &PSE); /// Add a check to \p Plan to see if the epilogue vector loop should be /// executed.