@@ -949,47 +949,20 @@ void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV,
949949 }
950950}
951951
952- // / Replace \p VPBB with a VPIRBasicBlock wrapping \p IRBB. All recipes from \p
953- // / VPBB are moved to the end of the newly created VPIRBasicBlock. VPBB must
954- // / have a single predecessor, which is rewired to the new VPIRBasicBlock. All
955- // / successors of VPBB, if any, are rewired to the new VPIRBasicBlock.
956- static void replaceVPBBWithIRVPBB (VPBasicBlock *VPBB, BasicBlock *IRBB) {
957- VPIRBasicBlock *IRVPBB = VPBB->getPlan ()->createVPIRBasicBlock (IRBB);
958- for (auto &R : make_early_inc_range (*VPBB)) {
959- assert (!R.isPhi () && " Tried to move phi recipe to end of block" );
960- R.moveBefore (*IRVPBB, IRVPBB->end ());
961- }
962-
963- VPBlockUtils::reassociateBlocks (VPBB, IRVPBB);
964- // VPBB is now dead and will be cleaned up when the plan gets destroyed.
965- }
966-
967952// / Generate the code inside the preheader and body of the vectorized loop.
968953// / Assumes a single pre-header basic-block was created for this. Introduce
969954// / additional basic-blocks as needed, and fill them all.
970955void VPlan::execute (VPTransformState *State) {
971956 // Initialize CFG state.
972957 State->CFG .PrevVPBB = nullptr ;
973958 State->CFG .ExitBB = State->CFG .PrevBB ->getSingleSuccessor ();
974- BasicBlock *VectorPreHeader = State->CFG .PrevBB ;
975- State->Builder .SetInsertPoint (VectorPreHeader->getTerminator ());
976959
977960 // Disconnect VectorPreHeader from ExitBB in both the CFG and DT.
961+ BasicBlock *VectorPreHeader = State->CFG .PrevBB ;
978962 cast<BranchInst>(VectorPreHeader->getTerminator ())->setSuccessor (0 , nullptr );
979963 State->CFG .DTU .applyUpdates (
980964 {{DominatorTree::Delete, VectorPreHeader, State->CFG .ExitBB }});
981965
982- // Replace regular VPBB's for the vector preheader, middle and scalar
983- // preheader blocks with VPIRBasicBlocks wrapping their IR blocks. The IR
984- // blocks are created during skeleton creation, so we can only create the
985- // VPIRBasicBlocks now during VPlan execution rather than earlier during VPlan
986- // construction.
987- BasicBlock *MiddleBB = State->CFG .ExitBB ;
988- BasicBlock *ScalarPh = MiddleBB->getSingleSuccessor ();
989- replaceVPBBWithIRVPBB (getVectorPreheader (), VectorPreHeader);
990- replaceVPBBWithIRVPBB (getMiddleBlock (), MiddleBB);
991- replaceVPBBWithIRVPBB (getScalarPreheader (), ScalarPh);
992-
993966 LLVM_DEBUG (dbgs () << " Executing best plan with VF=" << State->VF
994967 << " , UF=" << getUF () << ' \n ' );
995968 setName (" Final VPlan" );
@@ -998,6 +971,8 @@ void VPlan::execute(VPTransformState *State) {
998971 // Disconnect the middle block from its single successor (the scalar loop
999972 // header) in both the CFG and DT. The branch will be recreated during VPlan
1000973 // execution.
974+ BasicBlock *MiddleBB = State->CFG .ExitBB ;
975+ BasicBlock *ScalarPh = MiddleBB->getSingleSuccessor ();
1001976 auto *BrInst = new UnreachableInst (MiddleBB->getContext ());
1002977 BrInst->insertBefore (MiddleBB->getTerminator ());
1003978 MiddleBB->getTerminator ()->eraseFromParent ();
0 commit comments