Superoptimization
Superoptimization searches for a short or fast replacement for a small program fragment. Candidate generation and semantic validation are separate problems.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 3
- Reading time
- 1 min
In this article3 chapters
Decide what equivalence means
For deterministic total bit-vector fragments \(P,Q\), a candidate is rejected if a solver finds
\[ \exists x\quad \operatorname{eval}(P,x)\ne\operatorname{eval}(Q,x). \]
An unsatisfiable query proves equivalence in the modeled domain. Real compiler IRs also have definedness, flags and sometimes nondeterministic values. A refinement check may require agreement on source-defined executions and constrain when the replacement can introduce new undefined behavior. The solver’s arithmetic and memory abstractions must reflect the exact IR semantics.
Instruction selection gives a baseline restricted to declared patterns and costs. Translation validation can justify a concrete candidate obtained by a broader search under explicit arithmetic semantics.
A valid identity can have different costs
At positive width \(w\), unsigned addition of a value to itself agrees with left shift by one modulo \(2^w\), for widths where that shift amount is valid. For example, at eight bits an input of 129 maps to 2 in either form. Cost depends on the target and context. A shorter instruction encoding can be desirable even if latency is unchanged. A fragment that exposes more instruction-level parallelism may win over an instruction-count minimum.
A candidate needs a separate equivalence check
Enumerative synthesis grows candidates by a grammar. Stochastic superoptimization explores modifications and can use executions on sample inputs to reject candidates quickly. A sample cannot establish a universal equality. A validation stage can prove it or return a counterexample and send search back to the candidate space. Program synthesis uses a related loop. Equality saturation keeps known equivalences together, while verified compilers can establish the validity of entire passes.[1][2]