NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Finding Missed Code Size Optimizations in Compilers using LLMs

Davide Italiano, Chris CumminsarXiv 2025 · DOI

Introduction

Compilers serve as the fundamental infrastructure of modern software development, yet their internal complexity makes them prone to subtle bugs. Traditionally, compiler testing—or "fuzzing"—has focused almost exclusively on correctness: ensuring that the generated machine code accurately reflects the source logic. However, a significant gap remains in performance and code-size optimization. For resource-constrained environments like mobile applications and embedded systems, binary size is a critical metric that compilers often fail to optimize fully.

Researchers at Meta recently introduced a streamlined approach to identify these missed optimizations. By leveraging Large Language Models (LLMs) to generate and mutate test cases, they developed a tool requiring fewer than 150 lines of code that successfully uncovered 24 confirmed code-size optimization bugs in production-grade compilers, including GCC, LLVM, Rust, and Swift.

The LLM-Driven Mutation Framework

The core innovation of this research is the replacement of massive, hand-maintained random program generators (like CSmith, which exceeds 40,000 lines of code) with an off-the-shelf LLM. The framework operates in an iterative loop designed to evolve simple code into complex test cases that challenge a compiler's optimization passes.

The iterative mutation testing methodology workflow, from seed code to violation detection.

The process begins with a Seed, typically a trivial program such as a function returning a constant. The system then enters a Mutation phase, where an LLM (specifically Llama 3.1) is prompted to modify the code based on randomly sampled instructions. These instructions might include adding pointer logic, complex conditionals, or nested loops.

Mutation Strategies and Differential Testing

To identify optimization failures, the researchers employed Differential Testing. This involves comparing the compiler's output against various baselines to find anomalies. Key strategies included:

  • Dead Code Injection: Adding code that is logically unreachable. If the final binary size increases, the compiler has failed to identify and strip the dead code.
  • Optimization Pipeline Comparison: Comparing the output of size-optimized settings (-Oz) against performance-optimized settings (-O3). In cases where -O3 produces a smaller binary, the size-optimizer has clearly missed an opportunity.
  • Cross-Version and Cross-Compiler Testing: Comparing new compiler releases against older versions to find regressions, or comparing different compilers (e.g., GCC vs. Clang) on identical source code.
An example of an LLM-generated code mutation adding a nested loop and complex conditions to a seed function.

As shown in the example above, the LLM is capable of generating syntactically correct yet complex logic that mimics human-written code. This "interpretability" is a major advantage over traditional fuzzers, as it allows compiler developers to more easily diagnose and fix the reported issues.

Key Results and Insights

The methodology proved remarkably effective, with a 96.45% success rate in generating compilable code. This high fidelity demonstrates that modern LLMs can follow complex language rules without the need for formal grammar definitions.

Significant Findings:

  • 24 Confirmed Bugs: The tool identified previously unknown optimization failures across all tested languages.
  • Major Regressions: The system flagged a case where GCC 15 produced a binary 36% larger than its predecessor, GCC 14, for the same logic.
  • Rapid Discovery: In the cases of Rust and Swift, the tool identified bugs within the first hour of automated testing.

The Throughput vs. Intelligence Trade-off

A critical insight from the study was the comparison between model sizes. While the Llama 3.1 405B model was "smarter"—triggering more violations per individual program—the 70B model was ultimately more productive. Due to its lower latency and higher throughput, the 70B model could test significantly more programs in the same timeframe, leading to a higher total count of discovered bugs.

Conclusion and Future Work

By offloading the "intelligence" of code generation to LLMs, the researchers have demonstrated that compiler testing can be both simpler and more portable. The ability to adapt the tool to new languages like Rust and Swift in a matter of minutes represents a significant shift in how we maintain software infrastructure. Future work aims to expand this methodology beyond code size to address runtime performance, further narrowing the gap between human-written intent and machine-executed efficiency.

Summary updated

BibTeX
@misc{italiano2025finding,
  author = {Davide Italiano and Chris Cummins},
  title = {{Finding Missed Code Size Optimizations in Compilers using LLMs}},
  year = {2025},
  eprint = {2501.00655},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.00655},
}
Figure