@@ -2971,32 +2971,33 @@ void InnerLoopVectorizer::createVectorLoopSkeleton(StringRef Prefix) {
2971
2971
SplitBlock (LoopMiddleBlock, LoopMiddleBlock->getTerminator (), DT, LI,
2972
2972
nullptr , Twine (Prefix) + " scalar.ph" );
2973
2973
2974
- auto *ScalarLatchTerm = OrigLoop->getLoopLatch ()->getTerminator ();
2975
-
2976
2974
// Set up the middle block terminator. Two cases:
2977
- // 1) If we know that we must execute the scalar epilogue, emit an
2978
- // unconditional branch.
2975
+ // 1) If we know that we must execute the scalar epilogue, retain the existing
2976
+ // unconditional branch from the middle block to the scalar preheader. In that
2977
+ // case, there's no edge from the middle block to exit blocks and thus no
2978
+ // need to update the immediate dominator of the exit blocks.
2979
+ if (Cost->requiresScalarEpilogue (VF.isVector ())) {
2980
+ assert (
2981
+ LoopMiddleBlock->getSingleSuccessor () == LoopScalarPreHeader &&
2982
+ " middle block should have the scalar preheader as single successor" );
2983
+ return ;
2984
+ }
2985
+
2979
2986
// 2) Otherwise, we must have a single unique exit block (due to how we
2980
2987
// implement the multiple exit case). In this case, set up a conditional
2981
2988
// branch from the middle block to the loop scalar preheader, and the
2982
2989
// exit block. completeLoopSkeleton will update the condition to use an
2983
2990
// iteration check, if required to decide whether to execute the remainder.
2984
2991
BranchInst *BrInst =
2985
- Cost->requiresScalarEpilogue (VF.isVector ())
2986
- ? BranchInst::Create (LoopScalarPreHeader)
2987
- : BranchInst::Create (LoopExitBlock, LoopScalarPreHeader,
2988
- Builder.getTrue ());
2992
+ BranchInst::Create (LoopExitBlock, LoopScalarPreHeader, Builder.getTrue ());
2993
+ auto *ScalarLatchTerm = OrigLoop->getLoopLatch ()->getTerminator ();
2989
2994
BrInst->setDebugLoc (ScalarLatchTerm->getDebugLoc ());
2990
2995
ReplaceInstWithInst (LoopMiddleBlock->getTerminator (), BrInst);
2991
2996
2992
2997
// Update dominator for loop exit. During skeleton creation, only the vector
2993
2998
// pre-header and the middle block are created. The vector loop is entirely
2994
2999
// created during VPlan exection.
2995
- if (!Cost->requiresScalarEpilogue (VF.isVector ()))
2996
- // If there is an epilogue which must run, there's no edge from the
2997
- // middle block to exit blocks and thus no need to update the immediate
2998
- // dominator of the exit blocks.
2999
- DT->changeImmediateDominator (LoopExitBlock, LoopMiddleBlock);
3000
+ DT->changeImmediateDominator (LoopExitBlock, LoopMiddleBlock);
3000
3001
}
3001
3002
3002
3003
PHINode *InnerLoopVectorizer::createInductionResumeValue (
0 commit comments