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

Machine Learning in Compiler Optimisation

Zheng Wang, Michael F. P. O'BoylearXiv 2018

Introduction

Compiler optimization has traditionally been a domain of expert-crafted heuristics—simple rules of thumb used to decide how to transform code for better performance. However, as hardware complexity outpaces human ability to manually tune these rules, the field has shifted toward machine learning (ML). This paper surveys how data-driven models are replacing brittle heuristics, allowing compilers to automatically adapt to diverse architectures like multi-core CPUs and heterogeneous GPUs.

The Problem: The Growing Software Gap

Two primary challenges have made manual compiler tuning unsustainable:

  1. The Software Gap: Hardware potential is increasing faster than software's ability to exploit it. The rise of multi-core processors and GPUs introduces optimization decisions that are too complex for simple static rules.
  2. Architectural Volatility: New hardware generations arrive so rapidly that human experts cannot manually update heuristics for every new architectural quirk in time.

Optimization is essentially an exploration of a massive search space. ML provides the tools to navigate this space automatically, treating code improvement as a predictable optimization problem rather than a manual guessing game.

The Supervised Learning Workflow

The transition to ML-based compilation generally follows a three-step supervised learning workflow:

The three-step supervised learning workflow for compiler optimization: feature engineering, model training, and deployment.
  1. Feature Engineering: Characterizing a program into a numerical "feature vector." These vectors capture essential program traits such as instruction counts, branch density, or cache miss rates.
  2. Learning a Model: Training an algorithm (such as a Decision Tree, SVM, or Neural Network) on a diverse set of programs. The goal is to correlate specific features with the most effective optimization decisions.
  3. Deployment: Applying the trained model to predict the best settings for a brand-new, unseen program during the compilation process.

Methodologies: Cost Functions vs. Direct Prediction

Researchers typically employ one of two primary methodologies when integrating models into the compiler pipeline:

Comparison of cost function-based guidance versus direct predictive modeling for compiler decisions.
  • Building a Cost Function: The model learns to estimate the "quality" (e.g., speed, power consumption, or binary size) of a specific optimization. The compiler evaluates several potential versions of the code and selects the one with the highest predicted score.
  • Direct Prediction: The model acts as a classifier. By analyzing the code features, it immediately outputs the best optimization factor, such as a specific loop unrolling depth or a thread coarsening factor.

Beyond supervised learning, the survey also explores Online Learning (Evolutionary Algorithms and Reinforcement Learning) for searching large spaces without prior data, and Unsupervised Learning (PCA and Clustering) for reducing feature complexity.

Key Insights and Performance Results

A central takeaway is that ML serves as automation, not magic; it does not invent new optimizations but decides when and how to apply existing ones. The success of these models often depends more on the quality of the features than the specific algorithm used. A significant breakthrough was the use of "reaction-based features," where a program's performance response to a few trial optimizations is used as a feature itself.

Empirical results demonstrate the power of this approach:

  • Thread Coarsening: ML models achieved speedups between 1.11x and 1.33x across different GPU architectures by automatically tuning parallelism.
  • Loop Unrolling: Early models correctly predicted the best unroll factor for 65% of loops, leading to a 5% average improvement on SPEC benchmarks—a notable gain for mature compilers.
  • Phase Ordering: ML techniques have pruned exhaustive search spaces for compiler pass ordering by up to 89%, making iterative compilation feasible for production use.

Limitations and Future Directions

Despite its success, ML in compilation faces several hurdles. The "Black Box" problem makes it difficult for developers to understand why a model chose a specific optimization. Additionally, generating high-quality training data is computationally expensive, requiring programs to be compiled and executed thousands of times.

The future of the field lies in Deep Learning and Automatic Feature Generation. By leveraging massive code repositories like GitHub, researchers aim to remove the "human in the loop" entirely, allowing compilers to learn directly from raw source code or Abstract Syntax Trees (ASTs) without manual feature engineering.

Summary updated

BibTeX
@misc{wang2018machine,
  author = {Zheng Wang and Michael F. P. O'Boyle},
  title = {{Machine Learning in Compiler Optimisation}},
  year = {2018},
  eprint = {1805.03441},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1805.03441},
}
Figure