[llvm] [VPlan] Lower BranchOnTwoConds to chain of 2 simple branches. (PR #174016)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 8 13:08:21 PST 2026


================
@@ -3757,42 +3757,39 @@ void VPlanTransforms::expandBranchOnTwoConds(VPlan &Plan) {
 
   // Expand BranchOnTwoConds instructions into explicit CFG with
   // single-condition branches, by introducing a new branch in VPBB that jumps
-  // to a new intermediate block if either condition is true and to the
-  // third successor otherwise. The intermediate block jumps to the first or
-  // second successor, depending on the first condition.
+  // to the first successor if the first condition is true, and a new
+  // intermediate block otherwise. The intermediate block jumps to the second
+  // successor if the second condition is true, otherwise to the third
+  // successor.
   for (VPInstruction *Br : WorkList) {
     assert(Br->getNumOperands() == 2 &&
            "BranchOnTwoConds must have exactly 2 conditions");
     DebugLoc DL = Br->getDebugLoc();
-    VPBasicBlock *Latch = Br->getParent();
-    const auto Successors = to_vector(Latch->getSuccessors());
+    VPBasicBlock *Cond0BB = Br->getParent();
+    const auto Successors = to_vector(Cond0BB->getSuccessors());
     assert(Successors.size() == 3 &&
            "BranchOnTwoConds must have exactly 3 successors");
 
     for (VPBlockBase *Succ : Successors)
-      VPBlockUtils::disconnectBlocks(Latch, Succ);
+      VPBlockUtils::disconnectBlocks(Cond0BB, Succ);
 
-    VPValue *EarlyExitingCond = Br->getOperand(0);
-    VPValue *LateExitingCond = Br->getOperand(1);
-    VPBlockBase *EarlyExitBB = Successors[0];
-    VPBlockBase *LateExitBB = Successors[1];
-    VPBlockBase *Header = Successors[2];
+    VPValue *Cond0 = Br->getOperand(0);
+    VPValue *Cond1 = Br->getOperand(1);
+    VPBlockBase *Succ0 = Successors[0];
+    VPBlockBase *Succ1 = Successors[1];
+    VPBlockBase *Succ2 = Successors[2];
 
-    VPBasicBlock *MiddleSplit = Plan.createVPBasicBlock("middle.split");
-    MiddleSplit->setParent(LateExitBB->getParent());
+    VPBasicBlock *Cond1BB =
+        Plan.createVPBasicBlock(Cond0BB->getName() + ".cond.1");
+    Cond1BB->setParent(Succ1->getParent());
----------------
fhahn wrote:

Yep, there's no need to set the parent; removed the code, added an assert  that none of the blocks have parents, thanks

https://github.com/llvm/llvm-project/pull/174016


More information about the llvm-commits mailing list