[Paper Review] Simple, Light, Yet Formally Verified, Global Common Subexpression Elimination and Loop-Invariant Code Motion
This paper presents a lightweight, formally verified approach to global common subexpression elimination and loop-invariant code motion in the CompCert verified compiler by composing an unrolling pass with a certified global subexpression elimination phase. The method achieves significant performance improvements over vanilla CompCert with minimal proof complexity, narrowing the gap with state-of-the-art optimizing compilers while maintaining formal correctness through modular, composable proofs.
We present an approach for implementing a formally certified loop-invariant code motion optimization by composing an unrolling pass and a formally certified yet efficient global subexpression elimination.This approach is lightweight: each pass comes with a simple and independent proof of correctness.Experiments show the approach significantly narrows the performance gap between the CompCert certified compiler and state-of-the-art optimizing compilers.Our static analysis employs an efficient yet verified hashed set structure, resulting in fast compilation.
Motivation & Objective
- To close the performance gap between the CompCert verified compiler and state-of-the-art optimizing compilers like gcc and clang.
- To implement complex optimizations such as loop-invariant code motion with minimal, composable, and formally verified proofs.
- To maintain formal correctness while avoiding the complexity and performance overhead of full SSA-based middle-ends.
- To enable efficient compilation through a verified hashed set data structure for global subexpression elimination.
- To provide a modular, composable, and scalable optimization pipeline that avoids monolithic correctness proofs.
Proposed method
- The approach composes a loop unrolling pass with a formally verified global common subexpression elimination phase.
- Loop-invariant expressions are moved out of loops by unrolling the first iteration and reusing the computed values via common subexpression elimination.
- A verified, efficient hashed set data structure is used to accelerate subexpression detection and enable fast compilation.
- Each optimization pass is proved correct independently using simple local simulation arguments, avoiding complex global invariants.
- The method avoids full SSA construction, reducing code size and proof complexity compared to SSA-based optimizations.
- The approach is implemented in CompCert and leverages Coq for formal verification with a minimal trusted computing base.
Experimental results
Research questions
- RQ1Can loop-invariant code motion be implemented in a verified compiler without requiring a full SSA-based middle-end?
- RQ2Can a formally verified global common subexpression elimination pass be implemented with minimal proof complexity and high performance?
- RQ3Does composing simple, independently verified passes yield better performance and maintainability than monolithic optimization passes?
- RQ4Can the performance gap between verified compilers and industrial optimizing compilers be significantly reduced through lightweight, composable optimizations?
- RQ5Is it feasible to achieve high optimization quality in a verified compiler using only verified data structures and modular proofs?
Key findings
- The proposed approach significantly narrows the performance gap between CompCert and state-of-the-art optimizing compilers like gcc and clang.
- The global common subexpression elimination pass, built on a verified hashed set, achieves fast compilation times despite formal verification.
- The entire optimization pipeline, including loop-invariant code motion, is implemented with only 1,500 lines of verified code for the hashed set and 2,700 lines for subexpression elimination.
- The method avoids the 53,000-line SSA middle-end used in prior CompCert extensions, reducing complexity and maintenance cost.
- The correctness proofs are modular and lightweight, with the subexpression elimination proof being only 2,700 lines despite handling complex data flow.
- The approach outperforms previous verified approaches like Tristan and Leroy’s lazy code motion, which had cubic-time analysis and was never integrated due to high cost.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.