[llvm-branch-commits] [llvm] [VPlan][Predicator] Preserve some uniform control flow (PR #217485)

Ashutosh Nema via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 7 04:24:30 PDT 2026


================
@@ -1257,3 +1257,52 @@ void vputils::detail::pullOutPermutationsImpl(
     }
   }
 }
+
+// Implements the algorithm described in "Simple and Efficient Construction of
+// Static Single Assignment Form" by Braun et al.
+VPValue *vputils::reconstructSSA(VPBasicBlock *VPBB,
+                                 DenseMap<VPBasicBlock *, VPValue *> &Defs,
+                                 bool CreateWidenPhis) {
+  assert(!Defs.empty() && "Defs shouldn't be empty");
+  assert(VPBB->getPlan() && "VPBB isn't reachable from entry");
+  if (VPValue *Def = Defs.lookup(VPBB))
+    return Def;
+  // If the entry block is reached and there's still no def, then Defs is
+  // missing a definition that covers this path.
+  assert(VPBB->getNumPredecessors() && "Not all paths have def");
+
+  if (VPBlockBase *Pred = VPBB->getSinglePredecessor())
+    return reconstructSSA(cast<VPBasicBlock>(Pred), Defs, CreateWidenPhis);
+
+  // Multiple predecessors, create a join.
+  Type *Ty = Defs.begin()->second->getScalarType();
+  VPPhiAccessors *Phi;
+  VPSingleDefRecipe *PhiR;
+  if (CreateWidenPhis) {
+    Phi = new VPWidenPHIRecipe(Ty);
----------------
nema-ashutosh wrote:

This may break with -force-vector-interleave=2, the widened PHI introduced here are cloned for each part, but they are never remapped, causing part 1 to use values from part 0 ?

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


More information about the llvm-branch-commits mailing list