advanced

A phi with three sources in a block with two predecessors

A pass that folds an always-false branch into an unconditional jump was added to the middle-end. It deletes the unreachable successor and rewrites the terminator. The IR verifier started failing intermittently on functions with nested conditionals.

The symptom

The verifier reports phi in b7 has 3 sources but b7 has 2 predecessors. When the verifier is disabled — which someone tried — the program runs and produces a value read from a block that no longer exists on any path into b7.

Commit first

Name the phase. Then state the invariant a phi node carries, precisely enough that a checker could enforce it: a phi in block B must have exactly ___, in ___ order, and each source must be ___.