Leveraging Large Language Models for Generalizing Peephole Optimizations

📅 2026-03-19
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Handcrafted generalization of peephole optimization rules is costly and error-prone, while existing automated approaches suffer from limited generalizability. This work proposes LPG, a novel framework that integrates large language models with formal verification to automatically synthesize correct and efficient optimization rules within a closed-loop pipeline. By leveraging semantic abstraction, symbolic constants, structural generalization, constraint relaxation, and bit-width/precision generalization, LPG achieves robust rule generalization. Evaluated on real-world LLVM cases, LPG successfully generalizes 90 out of 102 rules and substantially outperforms Hydra on an integer subset (74 vs. 35), demonstrating superior capabilities in generalization, correctness, and performance gains.

Technology Category

Application Category

📝 Abstract
Peephole optimizations are a core component of modern optimizing compilers. It rewrites specific instruction into semantically equivalent but more efficient forms. In practice, creating a new peephole optimization often starts from a concrete optimization instance and requires lifting it into a more general rewrite rule that matches a wider range of instruction patterns. This generalization step is critical to optimization effectiveness, but it is also difficult: producing rules that are both correct and sufficiently general typically demands substantial manual effort and domain expertise. Existing approaches such as Hydra attempt to automate this task with program synthesis, but their generalization capability is often limited by search-space explosion, under-generalization, and restricted support for diverse instruction domains. We present LPG, large language model aided peephole optimization generalization, a framework that uses large language models (LLMs) to generalize peephole optimizations. The design of LPG is motivated by the observation that LLMs are effective at semantic abstraction and exploratory reasoning, while formal analyses are necessary to ensure that generated rules are sound and profitable. Based on this observation, LPG adopts a closed-loop workflow that integrates LLM-driven symbolic constant generalization, structural generalization, constraint relaxation, and bitwidth/precision generalization with feedback from syntactic validation, semantic verification, and profitability checking. We evaluate LPG on real-world peephole optimization issues drawn from the LLVM ecosystem. Overall, LPG successfully generalizes 90 out of 102 optimizations. On the integer-focused subset that is directly comparable to Hydra, LPG generalizes 74 out of 81 optimizations, whereas Hydra generalizes 35.
Problem

Research questions and friction points this paper is trying to address.

peephole optimization
generalization
compiler optimization
rewrite rules
program synthesis
Innovation

Methods, ideas, or system contributions that make the work stand out.

peephole optimization
large language models
program generalization
compiler optimization
formal verification
🔎 Similar Papers
No similar papers found.
C
Chunhao Liao
University of Waterloo, Canada
H
Hongxu Xu
University of Waterloo, Canada
X
Xintong Zhou
University of Waterloo, Canada
Zhenyang Xu
Zhenyang Xu
University of Waterloo
testingdebuggingprogramming language
Chengnian Sun
Chengnian Sun
Associate Professor of Computer Science, University of Waterloo
Software EngineeringProgramming Languages