@@ -530,6 +530,9 @@ class InnerLoopVectorizer {
530530 // / Returns (and creates if needed) the trip count of the widened loop.
531531 Value *getOrCreateVectorTripCount (BasicBlock *InsertBlock);
532532
533+ // Create a check to see if the vector loop should be executed
534+ Value *createIterationCountCheck (ElementCount VF, unsigned UF) const ;
535+
533536 // / Emit a bypass check to see if the vector trip count is zero, including if
534537 // / it overflows.
535538 void emitIterationCountCheck (BasicBlock *Bypass);
@@ -2370,13 +2373,8 @@ void InnerLoopVectorizer::introduceCheckBlockInVPlan(BasicBlock *CheckIRBB) {
23702373 }
23712374}
23722375
2373- void InnerLoopVectorizer::emitIterationCountCheck (BasicBlock *Bypass) {
2374- Value *Count = getTripCount ();
2375- // Reuse existing vector loop preheader for TC checks.
2376- // Note that new preheader block is generated for vector loop.
2377- BasicBlock *const TCCheckBlock = LoopVectorPreHeader;
2378- IRBuilder<> Builder (TCCheckBlock->getTerminator ());
2379-
2376+ Value *InnerLoopVectorizer::createIterationCountCheck (ElementCount VF,
2377+ unsigned UF) const {
23802378 // Generate code to check if the loop's trip count is less than VF * UF, or
23812379 // equal to it in case a scalar epilogue is required; this implies that the
23822380 // vector trip count is zero. This check also covers the case where adding one
@@ -2385,7 +2383,13 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
23852383 auto P = Cost->requiresScalarEpilogue (VF.isVector ()) ? ICmpInst::ICMP_ULE
23862384 : ICmpInst::ICMP_ULT;
23872385
2386+ // Reuse existing vector loop preheader for TC checks.
2387+ // Note that new preheader block is generated for vector loop.
2388+ BasicBlock *const TCCheckBlock = LoopVectorPreHeader;
2389+ IRBuilder<> Builder (TCCheckBlock->getTerminator ());
2390+
23882391 // If tail is to be folded, vector loop takes care of all iterations.
2392+ Value *Count = getTripCount ();
23892393 Type *CountTy = Count->getType ();
23902394 Value *CheckMinIters = Builder.getFalse ();
23912395 auto CreateStep = [&]() -> Value * {
@@ -2434,7 +2438,12 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
24342438 // Don't execute the vector loop if (UMax - n) < (VF * UF).
24352439 CheckMinIters = Builder.CreateICmp (ICmpInst::ICMP_ULT, LHS, CreateStep ());
24362440 }
2441+ return CheckMinIters;
2442+ }
24372443
2444+ void InnerLoopVectorizer::emitIterationCountCheck (BasicBlock *Bypass) {
2445+ BasicBlock *const TCCheckBlock = LoopVectorPreHeader;
2446+ Value *CheckMinIters = createIterationCountCheck (VF, UF);
24382447 // Create new preheader for vector loop.
24392448 LoopVectorPreHeader = SplitBlock (TCCheckBlock, TCCheckBlock->getTerminator (),
24402449 static_cast <DominatorTree *>(nullptr ), LI,
0 commit comments