MetaphIR: Corpus-Scale Applicability Analysis for LLVM Peephole Optimizations
Hongxu Xu, Xintong Zhou, Chunhao Liao, Chengnian Sun
Key points
From the paper's conclusion- We introduce MetaphIR, a system pairing a domain-specific language for expressing LLVM peephole optimizations with an indexed search engine over large IR corpora.
Abstract
Peephole optimizations replace short source instruction sequences with more efficient equivalents, typically guarded by preconditions such as requiring a constant operand to be a power of two. Since every new rewrite adds maintenance burden and compile-time cost, compiler developers need to know how often real-world programs both match the source pattern and satisfy its preconditions before committing to an implementation. Existing workflows fall short: structural search over an intermediate representation (IR) corpus of 4.8 million functions ignores preconditions and therefore overcounts, whereas implementing the rewrite and recompiling the corpus yields exact counts only after paying the engineering cost, with each run of the corpus's on-demand recompilation pipeline taking a median of 47 minutes. This delay is especially limiting when generalizing a rewrite, as developers often iterate over multiple variants to trade off coverage against complexity. We introduce MetaphIR, a system pairing a domain-specific language for expressing LLVM peephole optimizations with an indexed search engine over large IR corpora. Using a syntax modeled on LLVM's C++ matchers, MetaphIR patterns augment LLVM IR with holes and Boolean preconditions over matched values. To answer queries at interactive speed, MetaphIR builds compact per-function summaries ahead of time and uses abstract interpretation over those summaries to soundly filter out functions that cannot satisfy a query's constraints. Across twenty recent peephole optimizations from LLVM's InstCombine pass, MetaphIR recovers the exact set of functions where each rewrite applies in isolation, achieving 100% precision and recall. Queries complete in a median of 1.27 seconds---a 22x speedup over a full corpus scan---enabling developers to quickly gauge an optimization's reach and generality prior to implementation.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- APG: Agentic Static-Analysis Infrastructure on LLVM-IR Graph DatabasesarXiv · 2026
- Pattern-Driven Evaluation of LLM Code Optimization: Isolating Compiler-Transcendent Semantic ReasoningarXiv · 2026
- Seeking Evidence of Further Optimization: Detecting Missed Optimizations through Compiler’s Native AnalysesProceedings of the ACM on Programming Languages · 2026
- Spotlights: Discovering Improvement Opportunities in Software RepositoriesarXiv · 2026
- OptiMine: Scalable and Precise Code Optimization for Android Apps via LLM-Driven Semantic AnalysisProceedings of the ACM on Software Engineering · 2026
- FrontierRefactor: Benchmarking Multi-Scale Performance-Oriented Codebase RefactoringarXiv · 2026