ssa-phi-placement-minimality
I diagnosed the problem class from scratch (no existing project files in the workspace) and produced a verified, self-contained solution.
~/SOLUTION.md — the requested markdown (title, root-cause analysis, exact fix, verification).~/ssa_phi.py — the complete, stdlib-only reference implementation, embedded byte-for-byte in the markdown.DF pass is not enough. Once a phi is placed at y, y becomes a definition site, so DF(y) must also be processed — this is the iterated dominance frontier (DF+). A single pass produces ill-formed SSA.phi(x, self) == x), which a fixed-point pass removes.Cytron pipeline: iterative dominators → DF via idom runner-walk → IDF worklist → SSA renaming (unique versions, ⊥ for defs missing on a path) → fixed-point elimination (dead + same-value with copy propagation) → minimality verification.
| Demo | Before | After |
|---|---|---|
| diamond (live + dead phi) | 2 | 1 |
| loop (self-referential phi) | 1 | 1 |
same-value (x = a both arms) |
1 | 0 |
phi 'x' at 'join' <- DF of ['else', 'then'], phi 'i' at 'header' <- DF of ['body', 'header'].{ DF(x) : x ∈ defsites(v) ∪ P }; the least such set is the IDF by definition, confirming minimum cardinality.cd ~ && python3 ssa_phi.py # exit 0
One subtlety documented in the solution: IDF is the least fixed point of the Cytron placement (not liveness-pruned), which is why a phi for a one-armed variable is inserted and then removed by the trivially-dead rule.
# Evidence - Problem class: ssa-phi-placement-minimality - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-10-02T10:10:29.852Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Given a control-flow graph of basic blocks with variable definitions and uses, compute the minimal set of phi functions to insert using the iterated dominance frontier, then eliminate redundant phis via trivially-dead and same-value coalescing rules. Report the phi count before and after elimination, and show that no smaller placement exists by confirming every remaining phi sits in the dominance frontier of a block that defines its variable.", "environment": "python3", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "ssa-phi-placement-minimality", "provider": "openrouter", "solved_at": "2026-10-02T10:10:29.852Z", "version": "3.11"}