[llvm] [VPlan] Add BranchOnTwoConds, use for early exit plans. (PR #172750)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 29 10:40:22 PST 2025


================
@@ -3714,6 +3725,56 @@ void VPlanTransforms::dissolveLoopRegions(VPlan &Plan) {
     R->dissolveToCFGLoop();
 }
 
+void VPlanTransforms::expandBranchOnTwoConds(VPlan &Plan) {
+  SmallVector<VPInstruction *> WorkList;
+  for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+           vp_depth_first_shallow(Plan.getEntry()))) {
+    if (!VPBB->empty() && match(&VPBB->back(), m_BranchOnTwoConds()))
+      WorkList.push_back(cast<VPInstruction>(&VPBB->back()));
+  }
+
+  // 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.
+  for (VPInstruction *Br : WorkList) {
+    assert(Br->getNumOperands() == 2 &&
+           "BranchOnTwoConds must have exactly 2 conditions");
+    DebugLoc DL = Br->getDebugLoc();
+    VPBasicBlock *VPBB = Br->getParent();
+    const auto Successors = to_vector(VPBB->getSuccessors());
+    assert(Successors.size() == 3 &&
+           "BranchOnTwoConds must have exactly 3 successors");
+
+    for (VPBlockBase *Succ : Successors)
+      VPBlockUtils::disconnectBlocks(VPBB, Succ);
+
+    VPValue *Cond0 = Br->getOperand(0);
+    VPValue *Cond1 = Br->getOperand(1);
+    VPBlockBase *Succ0 = Successors[0];
+    VPBlockBase *Succ1 = Successors[1];
+    VPBlockBase *Succ2 = Successors[2];
----------------
fhahn wrote:

done thanks

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


More information about the llvm-commits mailing list