TL;DR
Even the most aggressive compilers miss optimization opportunities when high-level semantic context is missing from the source code. This paper introduces SeGaBench, a new benchmark showing that advanced Large Language Models (LLMs) can act as "speculative semantic proposers" to recover these hidden optimization opportunities. While the best model achieved an impressive 83.3% end-to-end optimization success rate, performance varies wildly across models, underscoring the absolute necessity of automated validation pipelines.
What Problem Does This Paper Address?
Modern C/C++ compilers are incredibly powerful, utilizing advanced pipelines and optimizations like Link-Time Optimization (LTO) and Profile-Guided Optimization (PGO). However, they suffer from a fundamental limitation: they can only optimize based on the explicit code representation within their analyzed scope.
Compilers routinely miss highly profitable transformations because they lack high-level semantic context. For example, a compiler cannot safely vectorize a loop if it cannot prove that two memory regions won't overlap (aliasing). Similarly, it won't replace a slow loop with a fast specialized algorithm unless it knows a data structure maintains a specific invariant (like being pre-sorted). This crucial context is often scattered across documentation, tests, or distant caller functions.
The authors investigate a compelling question: Can LLMs bridge this "semantic gap" by reading the broader program context, inferring missing optimization-enabling semantics, and realizing them as valid, high-performance code modifications?
Methods
The authors formalize this challenge into a three-stage pipeline evaluated through a blind, single-turn protocol:
- Semantic Identification (RQ1): Can the LLM correctly identify the hidden semantic fact (e.g., non-aliasing pointers) and point to its evidence in the context?
- Artifact Realization (RQ2): Can the model translate that insight into a valid, contract-preserving source-level change (a "semantic artifact" like a
restrictkeyword, a runtime guard, or an algorithmic rewrite)? - Performance Realization (RQ3): Does the resulting patch actually deliver a measurable speedup over a strong compiler baseline (
-O3 + LTO + PGO)?
Rather than letting the LLM replace the compiler, the authors propose a division of labor: the LLM acts as a speculative proposer, while automated functional and semantic validators ensure the code remains correct before the compiler handles downstream code generation.
Datasets
The paper introduces SeGaBench (Semantic Gap Benchmark), an executable benchmark containing 120 cases split into two suites:
- Synthetic Suite (100 cases): Purpose-built code isolating 50 distinct optimization archetypes across three semantic categories.
- Real-World Suite (20 cases): Source-backed application hotspots extracted from six widely used High-Performance Computing (HPC) projects: HPCG, LAMMPS, LULESH, miniFE, RAJAPerf, and XSBench.
Every case falls into one of three semantic types:
- Low-Level Assumptions (LLA): Facts about memory alignment, non-aliasing, or bounded loop trip counts.
- Data-Structure Invariants (DSI): Global relations like sortedness, uniqueness, or diagonal matrix structures.
- High-Level Semantic Lifting (HSL): Recognizing low-level loops as standard algorithmic operations (e.g., prefix scans or reductions) to allow full rewrites.
Key Insights and Ideas
- Optimization is Not a Uniform LLM Capability: There is a massive performance chasm between top-tier models and smaller or older models. While the best models excel at both reasoning and code generation, weaker models fail dramatically at turning semantic insights into compilable code.
- The "Oracle Gap": Even when an LLM successfully generates a correct, speedup-yielding patch, it often closes only a fraction of the performance gap achieved by the human-designed "oracle" solution.
- The Real-World Transfer Gap: Models perform significantly better on isolated synthetic cases than on real-world HPC code. Median speedups dropped sharply from synthetic benchmarks (up to 7.29×) to real-world cases (1.04× to 1.29×), showing that real production context is vastly more challenging.
- Syntax Compliance $\neq$ Correctness: Models can easily output structured, clean-looking code patches that completely fail compilation or violate program correctness. This highlights why LLM-driven optimization must be paired with rigorous validation.
Key Results
The authors evaluated five LLMs (including GPT-5.6 Sol, DeepSeek-V4-Pro, and Llama-3.3-70B) generating five independent responses per case.
- Top Performer: GPT-5.6 Sol dominated the benchmark, achieving a 95.0% semantic recovery rate and generating correct artifacts in 94.8% of responses. On a single-turn basis, it achieved a $\ge 1.05\times$ speedup on 83.3% of requests, which improved to 93.3% when allowed 5 samples.
- The Competition: DeepSeek-V4-Pro performed strongly with a 63.8% single-request success rate, while GPT-5.4-mini hit 41.7%. Weaker models like Llama-3.3-70B-Turbo and Ternary-Bonsai-27B struggled, succeeding less than 6% of the time.
- Speedup by Type: Low-level assumptions yielded the highest median speedups for top models (e.g., 3.10× for GPT-5.6), while high-level semantic lifting benefits varied heavily depending on the specific case.
Limitations and Future Work
- Scope: SeGaBench is currently limited to C/C++ and heavily weighted toward HPC applications. Its real-world suite may not fully represent production software in other domains (e.g., web backends or mobile apps).
- Hardware & Environment Bias: All performance benchmarks were executed on a single hardware platform (Apple M4 Mac mini). Absolute speedups and model rankings could shift on x86 architectures or GPUs.
- Human-in-the-Loop Evaluation: Judging whether a model successfully identified a semantic fact (RQ1) still relies on blinded human reviewers. The authors note that future iterations should aim for machine-checkable contracts and fully automated candidate selection.
Summary updated