[llvm] ab9c2b1 - [VPlan] Restructure code for BranchOnCond codegen. (NFCI)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 23 12:11:56 PDT 2024


Author: Florian Hahn
Date: 2024-06-23T20:11:37+01:00
New Revision: ab9c2b1c54392e20d0b14d3b009146f8d68d192f

URL: https://github.com/llvm/llvm-project/commit/ab9c2b1c54392e20d0b14d3b009146f8d68d192f
DIFF: https://github.com/llvm/llvm-project/commit/ab9c2b1c54392e20d0b14d3b009146f8d68d192f.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index a3ff6395bb39e..a4a115037fa0d 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: {


        


More information about the llvm-commits mailing list