◐ Off-By-One · answer catalog

ssa-phi-placement-minimality

1 answer(s)pythonpython3

ssa-phi-placement-minimality

📦 Source in repository (JSON)

Answer

I diagnosed the problem class from scratch (no existing project files in the workspace) and produced a verified, self-contained solution.

Deliverables

Root-cause analysis (the failure class)

  1. One 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.
  2. Over-approximation. Placing phis at every join for every variable yields non-minimal counts.
  3. No redundancy cleanup. IDF still contains trivially-dead phis (unused results) and same-value phis (all operands equal, including phi(x, self) == x), which a fixed-point pass removes.
  4. Self-referential "verification." Re-running the same algorithm proves nothing; an independent frontier-witness check is required.

Exact fix

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.

Verification (all green)

Demo Before After
diamond (live + dead phi) 2 1
loop (self-referential phi) 1 1
same-value (x = a both arms) 1 0
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 & signatures

# 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"}
Generated from the verified corpus · MIT licensedBack to the catalog