From ab9c2b1c54392e20d0b14d3b009146f8d68d192f Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 23 Jun 2024 20:11:36 +0100 Subject: [PATCH] [VPlan] Restructure code for BranchOnCond codegen. (NFCI) Reoder code to exit early if the BranchOnCond isn't in an exiting block. This delays retrieving the parent region, which may not be present. Split off from https://github.com/llvm/llvm-project/pull/92651. --- llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index a3ff6395bb39..a4a115037fa0 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -442,20 +442,20 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) { return nullptr; Value *Cond = State.get(getOperand(0), VPIteration(Part, 0)); - VPRegionBlock *ParentRegion = getParent()->getParent(); - VPBasicBlock *Header = ParentRegion->getEntryBasicBlock(); - // Replace the temporary unreachable terminator with a new conditional // branch, hooking it up to backward destination for exiting blocks now and // to forward destination(s) later when they are created. BranchInst *CondBr = Builder.CreateCondBr(Cond, Builder.GetInsertBlock(), nullptr); - - if (getParent()->isExiting()) - CondBr->setSuccessor(1, State.CFG.VPBB2IRBB[Header]); - CondBr->setSuccessor(0, nullptr); Builder.GetInsertBlock()->getTerminator()->eraseFromParent(); + + if (!getParent()->isExiting()) + return CondBr; + + VPRegionBlock *ParentRegion = getParent()->getParent(); + VPBasicBlock *Header = ParentRegion->getEntryBasicBlock(); + CondBr->setSuccessor(1, State.CFG.VPBB2IRBB[Header]); return CondBr; } case VPInstruction::BranchOnCount: {