SuperCoder: Assembly Program Superoptimization with Large Language Models

Anjiang Wei, Tarun Suresh, Huanmi Tan, Yinglun Xu, Gagandeep Singh, Ke Wang, Alex Aiken

TL;DR

SuperCoder demonstrates that Large Language Models (LLMs) can act as "superoptimizers," rewriting assembly code to be even faster than the output of industry-standard compilers like gcc -O3. By combining a new large-scale benchmark of complex assembly programs with Reinforcement Learning (RL), the researchers created a model that achieves a 1.46× average speedup over highly optimized baseline code while maintaining 95% functional correctness.

What Problem Does This Paper Address?

In the world of software performance, "superoptimization" is the holy grail: finding the absolute fastest sequence of instructions that performs a specific task. Traditionally, compilers like GCC or Clang use expert-defined heuristics and transformation rules to optimize code. While effective, these rules often leave performance on the table because they cannot explore the near-infinite space of possible instruction combinations.

Previous attempts at superoptimization relied on exhaustive searches or stochastic methods (like MCMC), which limited them to tiny, "straight-line" code snippets (usually 2–15 lines) without loops. The authors of this paper address two major gaps:

  1. Scale: The lack of a benchmark for superoptimizing complex, real-world assembly programs that include loops and branches.
  2. Methodology: Investigating whether the "creative" generative capabilities of LLMs can discover novel optimization strategies that human-written compiler rules miss.

Methods

The researchers developed a pipeline called SuperCoder to bridge the gap between high-level reasoning and low-level machine code:

  • RL Fine-Tuning: They fine-tuned a base model (Qwen2.5-Coder-7B-Instruct) using Reinforcement Learning algorithms, specifically PPO (Proximal Policy Optimization) and GRPO (Group Relative Policy Optimization).
  • Reward Function: Unlike standard LLM training, the reward here was grounded in reality. The model received a reward of 0 if the code failed to compile or pass test cases. If it passed, the reward was the speedup ratio (time taken by gcc -O3 / time taken by the LLM's code).
  • Inference Strategies: They employed Best-of-N sampling (generating multiple versions and picking the fastest correct one) and Iterative Refinement, where the model receives compiler error messages or test failures to fix its own mistakes.
  • Direct Assembly Manipulation: The model is prompted with the original C code and the gcc -O3 assembly, then asked to produce a more optimized version of the assembly directly.

Datasets

The authors introduced the SuperCoder Benchmark, the first large-scale dataset for this task:

  • Source: 8,072 programs derived from CodeNet, a corpus of competitive programming submissions.
  • Complexity: Programs average 130 lines of assembly, a massive leap from the 15-line limit of prior datasets.
  • Quality: The dataset includes robust test suites achieving 96.2% line coverage and 87.3% branch coverage to ensure that "optimized" programs aren't just "broken" programs.

Key Insights and Ideas

  • LLMs as Creative Optimizers: The models didn't just tweak instructions; they performed high-level restructuring. The most frequent optimization was Loop Restructuring (68.2%), followed by Arithmetic Optimization (45%).
  • RL vs. Supervised Learning: The authors found that RL is superior for superoptimization. Because there is no single "correct" optimized version (it's an open-ended search), RL allows the model to explore the performance space rather than just imitating a single training example.
  • The "Reasoning" Paradox: Interestingly, some "reasoning" models like DeepSeek-R1 performed poorly, often spending their entire output budget "thinking" about the code without actually generating valid, executable assembly.
  • Dark Optimizations: The LLMs discovered that they could gain speed by removing stack canaries (security features that prevent buffer overflows). While this makes the code faster, it highlights a tension between performance and security that automated optimizers must navigate.

Key Results

  • SuperCoder Performance: The fine-tuned SuperCoder (PPO) model achieved 95.0% correctness and a 1.46× average speedup over gcc -O3.
  • Scaling with Compute: Using Best-of-8 sampling, the speedup increased to 1.93×, showing that giving the model more "tries" significantly boosts the chance of finding a highly efficient shortcut.
  • Comparison to Baselines: Even the strongest proprietary model, Claude-3.7-Sonnet, achieved a 1.22× speedup, but SuperCoder’s specialized RL training allowed a much smaller 7B parameter model to outperform it significantly.
  • Compiler Foundation Models: Existing models like llm-compiler-13b showed promise (1.34× speedup) but struggled with correctness compared to the RL-tuned SuperCoder.

Limitations and Future Work

  • Test-Based Validation: The system relies on test cases to verify correctness. While coverage is high, it cannot guarantee semantic equivalence in the way formal verification could.
  • Architecture Specificity: The current work focuses exclusively on x86-64. The authors suggest extending this to ARM and RISC-V as a logical next step.
  • Security Implications: As noted, the model's tendency to remove security checks (like stack canaries) for speed is a double-edged sword. Future work needs to integrate "safety constraints" into the reward function.
  • Black-Box Nature: It remains difficult to automatically isolate exactly which transformation caused a specific speedup, as optimizations are often interrelated.

Summary updated

BibTeX
@inproceedings{wei2026supercoder,
  author = {Anjiang Wei and Tarun Suresh and Huanmi Tan and Yinglun Xu and Gagandeep Singh and Ke Wang and Alex Aiken},
  title = {{SuperCoder: Assembly Program Superoptimization with Large Language Models}},
  booktitle = {COLM},
  year = {2026},
  url = {https://openreview.net/forum?id=VsaeinNuM7},
}
Figure