Sparse Conditional Constant Propagation

Combine executable-edge discovery with SSA value facts so impossible branches do not spoil a constant at a merge.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Evaluate only operands from executable edges
  2. Instruction facts and reachability feed each other

Evaluate only operands from executable edges

Suppose a condition is known true. The true branch defines \(x_1=5\), and the other branch defines \(x_2=8\). At their join, consider only the first input to \(x_3=\phi(x_1,x_2)\), because the second edge is infeasible. The result stays five. Ordinary constant propagation considering both syntactic paths would merge to an unknown value.

Instruction facts and reachability feed each other

When an edge first becomes executable, revisit the target block and its phi nodes. When a definition changes value information, revisit its users. An unknown branch condition makes both successors possible. A not-yet-evaluated value is a separate lattice state and need not force that conclusion immediately. Monotone facts give a terminating worklist computation in the finite lattice. Basic constant propagation supplies the value order. SSA phi functions tell which edges supply each operand.[1][2]

References

  1. Andrew C. Myers, Cornell CS 4120: Compiler Course Notes ↩
  2. LLVM Project, LLVM Language Reference Manual ↩