[llvm] [VPlan] Model control flow of early exits and preserve SSA (PR #201784)

Andrei Elovikov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 9 09:03:40 PDT 2026


================
@@ -4364,10 +4358,64 @@ static bool handleUncountableExitsWithSideEffects(
   return true;
 }
 
+static VPValue *repairSSA(VPValue *Src, VPBasicBlock *SrcVPBB, VPValue *Other,
+                          VPBasicBlock *VPBB, VPDominatorTree &VPDT,
+                          DenseMap<VPBlockBase *, VPPhi *> &Phis) {
+
+  if (VPDT.dominates(SrcVPBB, VPBB))
+    return Src;
+  if (VPDT.dominates(VPBB, SrcVPBB))
+    return Other;
+  if (VPPhi *Phi = Phis.lookup(VPBB))
+    return Phi;
+
+  SmallVector<VPValue *> InVals;
+  for (auto *Pred : VPBB->predecessors())
+    InVals.push_back(
+        repairSSA(Src, SrcVPBB, Other, cast<VPBasicBlock>(Pred), VPDT, Phis));
+  if (all_equal(InVals))
+    return InVals[0];
+
+  VPPhi *Phi = VPBuilder(VPBB, VPBB->getFirstNonPhi()).createScalarPhi(InVals);
+  Phis[VPBB] = Phi;
+  return Phi;
+}
+
+/// Insert phi nodes to maintain SSA starting from \p VPBB, such that the
+/// resulting value is \p \Src on all paths that go through \p SrcVPBB, and \p
+/// Other otherwise.
----------------
eas wrote:

What I meant is that we have a very specific pattern how edges are removed/added, so we know where new phis are possibly required.

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


More information about the llvm-commits mailing list