[llvm] [VPlan] Use control flow to implement MaskedCond and preserve SSA (PR #201784)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 25 02:34:30 PDT 2026
================
@@ -1131,3 +1130,39 @@ void vputils::detail::pullOutPermutationsImpl(
}
}
}
+
+/// Implements the algorithm described in "Simple and Efficient Construction of
+/// Static Single Assignment Form" by Braun et al.
+static VPValue *reconstructSSAImpl(VPBasicBlock *VPBB,
+ DenseMap<VPBlockBase *, VPValue *> &Defs) {
+ if (VPValue *Def = Defs.lookup(VPBB))
+ return Def;
+
+ if (VPBlockBase *Pred = VPBB->getSinglePredecessor())
+ return reconstructSSAImpl(cast<VPBasicBlock>(Pred), Defs);
+
+ // Multiple predecessors, create a join.
+ Type *Ty = Defs.begin()->second->getScalarType();
+ auto *Phi = new VPPhi({}, {}, {}, "", Ty);
+ VPBB->insert(Phi, VPBB->getFirstNonPhi());
+ Defs[VPBB] = Phi;
+ for (auto *Pred : VPBB->predecessors())
+ Phi->addIncoming(reconstructSSAImpl(cast<VPBasicBlock>(Pred), Defs));
+
+ // Fold away trivial phis.
+ // TODO: Remove phi users which have become trivial too.
+ if (all_equal(Phi->incoming_values())) {
+ VPValue *Common = Phi->getIncomingValue(0);
+ Phi->replaceAllUsesWith(Common);
+ Phi->eraseFromParent();
+ Defs[VPBB] = Common;
+ return Common;
+ }
+
+ return Phi;
+}
+
+VPValue *vputils::reconstructSSA(DenseMap<VPBlockBase *, VPValue *> Defs,
----------------
lukel97 wrote:
Yeah it allows the caller to construct a DenseMap inline, instead of having to declare a temporary variable.
https://github.com/llvm/llvm-project/pull/201784
More information about the llvm-commits
mailing list