GRACE: Cluster-Specific Sequence Reuse for Compiler Auto-Tuning

Haolin Pan, Chao Zha, Jinyuan Dong, Mingjie Xing, Yanjun Wu

TL;DR

GRACE is a novel compiler auto-tuning framework that bridges the gap between slow iterative compilation and rigid machine learning predictions by introducing cluster-specific sequence reuse. By grouping similar programs offline based on how they respond to optimization and evolving a small, specialized set of optimization pass sequences (a "coreset") for each group, GRACE achieves significant code-size and speed improvements in under a second at deployment time.

What Problem Does This Paper Address?

Modern compilers like LLVM rely on fixed, hand-tuned heuristics to order optimization passes (e.g., -O3 for speed or -Oz for code size). However, these one-size-fits-all pipelines rarely achieve optimal performance because the ideal sequence of passes varies wildly from program to program.

To solve this, researchers use Iterative Compilation (IC), which searches the massive space of pass combinations to find the best sequence for a specific program. While highly effective, IC is computationally expensive and too slow for practical, day-to-day deployment. On the flip side, learning-based methods try to predict the best sequence instantly using machine learning models, but their accuracy drops significantly when encountering unseen programs. Recent "coreset" methods try to find a small, global pool of sequences that work well generally, but a single global pool lacks the flexibility to handle diverse program behaviors.

Methods

GRACE introduces a four-stage hierarchical sequence discovery framework divided into an offline training phase and an online deployment phase:

Figure 1: The GRACE framework.
  1. Candidate and Pass Pool Construction (Offline): GRACE analyzes a training corpus to find pairs of compiler passes that work well together (pass synergy). It uses these pairs to build a synergy graph, runs a genetic algorithm to find high-performing sequences, and filters them down to a promising candidate set ($C_{seq}$) and a constrained pool of useful passes ($P_{pool}$).
  2. Program Embeddings and Clustering (Offline): Instead of clustering programs based purely on their source code syntax, GRACE uses contrastive learning to group programs by their optimization-response similarity—i.e., how similarly their instruction counts drop when standard compiler flags (-O1, -O2, -O3, -Os, -Oz) are applied. Programs are then partitioned into $k$ distinct clusters using K-Means.
  3. Cluster-Specific Coreset Evolution (Offline): For each program cluster, GRACE runs a separate genetic algorithm to evolve a single, highly specialized representative pass sequence. This collection of representative sequences forms the final compact "coreset."
  4. Test-Time Application with Refinement (Online/Deployment): When a new, unseen program arrives, GRACE simply runs the small coreset of precomputed sequences on it, picks the best performer, and optionally applies lightweight local refinements (like prefix searches or localized genetic tweaks) to squeeze out extra performance under a strictly bounded time budget.

Datasets

The authors utilized large-scale datasets from CompilerGym, adhering to a strict train-test split to evaluate cross-domain generalization.

  • Training Set: Composed of 19,603 uncurated programs from massive repositories, including github-v0, linux-v0, and poj104-v1.
  • Test Set: Composed of 335 programs, including held-out uncurated programs and entirely distinct, curated benchmark suites such as cbench-v1, mibench-v1, chstone-v0, and npb-v0.

A structural similarity scan ensured no near-duplicate leakage existed between the training and testing sets.

Key Insights and Ideas

  • Behavior Over Syntax: A core insight of GRACE is that how a program behaves under basic optimization is a far better indicator of its optimization needs than what its code looks like syntactically.
  • The Power of the Coreset: Predicting a single "perfect" sequence is incredibly difficult for machine learning models. GRACE reframes the problem: it transfers a small, high-quality set of candidate sequences to the test phase, relying on fast empirical evaluation to make the final choice.
  • Bootstrapping Evolution: Running genetic algorithms from scratch for every cluster is inefficient. By initializing the cluster-level search with globally effective priors ($C_{seq}$), GRACE ensures the evolutionary search converges quickly on high-quality sequences.

Key Results

The authors evaluated GRACE against standard compiler baselines and state-of-the-art auto-tuning methods across two LLVM versions (10.0.0 and 18.1.6).

  • Code-Size Optimization: Relative to LLVM's standard -Oz flag, GRACE reduced the LLVM IR instruction count by an average of 9.92% on LLVM 10 and 10.30% on LLVM 18. Crucially, it achieved this while keeping deployment tuning time under 1 second per program.
  • Execution Performance: When optimized for speed relative to -O3, GRACE achieved an average predicted cycle reduction of 26.84% (LLVM 10) and 27.54% (LLVM 18).
Figure 3: Average predicted cycle reduction (%) relative to opt -O3 on LLVM 10.0.0. Higher values indicate better execution- oriented optimization. GRACE is shown with two coreset sizes (𝑘= 100 and 𝑘= 1000).

When tested on physical hardware, these cycle reductions translated to actual wall-clock geometric-mean speedups of 2.7× on Intel Xeon and 1.1× on AMD EPYC processors for runnable cBench programs.

Limitations and Future Work

While powerful, GRACE has a few notable limitations:

  • Data Dependency: The quality of the cluster-specific coresets heavily depends on how representative and diverse the offline training corpus is.
  • Not Zero-Cost: Unlike pure ML prediction models, GRACE still requires compiling and running a small set of sequences at test time, which introduces a small, albeit strictly bounded, overhead.
  • Scope: The study focused primarily on code size and execution cycles within the LLVM ecosystem. The authors note that extending GRACE to handle multi-objective tuning (e.g., balancing code size and energy efficiency) and evaluating it across other compiler infrastructures remain important avenues for future research.

Summary updated

BibTeX
@misc{pan2025grace,
  author = {Haolin Pan and Chao Zha and Jinyuan Dong and Mingjie Xing and Yanjun Wu},
  title = {{GRACE: Cluster-Specific Sequence Reuse for Compiler Auto-Tuning}},
  year = {2025},
  eprint = {2510.13176},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.13176},
}
Figure