Preprint
Large Language Models

Can Large Language Models Recover Semantic Optimization Opportunities That Compilers Miss?

Hailong Jiang, Feng Yu, Emran Hossain, Jianfeng Zhu, Mengfei Ren, Qiang Guan, Chunwei Xia
August 4, 2026

0

Citations

0

Influential Citations

Venue

2026

Year

Abstract

Optimizing compilers miss profitable transformations when their enabling semantics are absent from the analyzed program representation. We ask whether large language models (LLMs) can recover such semantics from heterogeneous C/C++ context and realize them as validated, contract-preserving artifacts. We introduce SeGaBench, an executable benchmark containing 100 synthetic and 20 source-backed cases spanning low-level assumptions, data-structure invariants, and high-level semantic lifting. Each case includes hidden enabling semantics, an oracle artifact, correctness and semantic validators, and a reproducible performance protocol. We evaluate five LLMs using five independent responses per case. The strongest model produces correct artifacts in 94.8% of responses, achieves at least 1.05x speedup in 83.3%, and obtains a performance success on 93.3% of cases. Nevertheless, correct artifacts often close only part of the oracle gap. These results show that LLMs can complement compiler analysis as speculative semantic proposers, provided that their artifacts are validated and evaluated.

Analysis

Why This Paper Matters

Traditional optimizing compilers rely on static analysis to discover transformation opportunities, but they often miss optimizations that require semantic knowledge not explicitly present in the code. This paper addresses a critical gap: can large language models (LLMs) recover these hidden semantics from the surrounding context and generate valid optimizations? The authors introduce SeGaBench, a rigorous benchmark that tests this capability, providing a standardized way to evaluate LLMs as semantic proposers.

The significance lies in the potential to augment compiler pipelines with LLM-driven speculative optimization. If LLMs can reliably propose correct and beneficial transformations, they could complement existing compiler passes, unlocking performance gains that are currently unattainable. The paper's focus on validation and reproducibility ensures that the proposed artifacts are not just plausible but actually correct and performance-improving.

Technical Contributions

  • SeGaBench: A novel benchmark with 120 cases (100 synthetic, 20 source-backed) covering three categories: low-level assumptions, data-structure invariants, and high-level semantic lifting. Each case includes hidden enabling semantics, an oracle artifact, and validators.
  • Validation Framework: Each case provides correctness and semantic validators, ensuring that generated artifacts preserve program behavior and are actually correct.
  • Performance Protocol: A reproducible performance measurement protocol to assess speedups, making results comparable across models and runs.
  • Evaluation of Five LLMs: The study evaluates five different LLMs with multiple responses per case, providing a robust statistical comparison.

Results

The strongest model achieved impressive results: 94.8% correct artifacts, 83.3% responses with at least 1.05x speedup, and 93.3% performance success across cases. This indicates that LLMs can indeed recover semantic optimization opportunities that compilers miss. However, the paper notes that correct artifacts often only partially close the oracle gap, meaning there is still room for improvement. The benchmark's design allows for fine-grained analysis of where LLMs succeed and fail, which is valuable for future research.

Significance

This work has broad implications for the AI and compiler communities. It demonstrates a practical application of LLMs in systems optimization, moving beyond code generation to code transformation. The idea of using LLMs as speculative semantic proposers, with validation by traditional tools, could lead to hybrid compiler designs that leverage the strengths of both. It also opens up new research directions in understanding how LLMs reason about program semantics and how to improve their reliability in safety-critical contexts. The benchmark itself is a valuable resource for evaluating future models and techniques.