A Lightweight Machine Learning Approach for Loop Unrolling Decisions in GCC

Modern compilers such as GCC rely on hand-crafted, general-purpose heuristics to decide whether to completely unroll a loop — a decision that trades code size and instruction-cache pressure for reduced loop-control overhead and increased instruction-level parallelism. These heuristics are tuned to perform well on average across arbitrary codebases but are not adapted to the specific characteristics of an individual loop. We investigate whether a lightweight, interpretable machine learning model, trained on features extracted from GCC's GIMPLE intermediate representation, can predict the profitability of complete loop unrolling as accurately as GCC's built-in heuristic. Unlike prior work that targets LLVM or employs increasingly complex models (XGBoost, multi-layer neural networks, graph neural networks), we deliberately start from a minimal, fully interpretable Decision Tree classifier evaluated directly against ground-truth runtime measurements. We construct a dataset of 30 hand-written C functions, of which 21 yield a valid, non-trivially-resolved loop after -O2 (the remaining 9 are excluded because GCC resolves them entirely at compile time), measure the true speedup of -funroll-loops via repeated empirical timing, and extract a small set of static features from the corresponding GIMPLE dump. The resulting dataset is heavily imbalanced (19 UNROLL / 2 NO-UNROLL samples), against which a trivial majority-class baseline already achieves 90.5% accuracy. An unweighted Decision Tree matches this baseline exactly (90.5% under Leave-One-Out Cross-Validation), while the same model trained with scikit-learn's standard class_weight="balanced" setting collapses to 28.6% — a 61.9-percentage-point drop caused entirely by re-weighting two minority-class samples to roughly 9.5× the weight of each majority-class sample, which flips a single decision-tree branch responsible for the large majority of predictions. Direct inspection of GCC's own decision logic in tree-ssa-loop-ivcanon.cc further reveals that none of our five features correspond to num_branches_on_hot_path, the dominant factor in GCC's actual unrolling decision. We report both findings transparently: the class-imbalance sensitivity of a standard re-weighting technique on small datasets, and the missing branch-count feature relative to GCC's real heuristic, using them to motivate feature and evaluation design for subsequent iterations. All experiments, source code, and the generated dataset are made publicly available for reproducibility.

Authors

Publication Details

Journal
Zenodo (CERN European Organization for Nuclear Research)
Published
2026-08-20
DOI
https://doi.org/10.5281/zenodo.22035129
Primary Topic
Parallel Computing and Optimization Techniques
Type
preprint
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
preprint

A Lightweight Machine Learning Approach for Loop Unrolling Decisions in GCC

Mohammed Bakr
Zenodo (CERN European Organization for Nuclear Research)
Parallel Computing and Optimization Techniques
preprint

A Lightweight Machine Learning Approach for Loop Unrolling Decisions in GCC

Mohammed Bakr
preprint en

Abstract

Modern compilers such as GCC rely on hand-crafted, general-purpose heuristics to decide whether to completely unroll a loop — a decision that trades code size and instruction-cache pressure for reduced loop-control overhead and increased instruction-level parallelism. These heuristics are tuned to perform well on average across arbitrary codebases but are not adapted to the specific characteristics of an individual loop. We investigate whether a lightweight, interpretable machine learning model, trained on features extracted from GCC's GIMPLE intermediate representation, can predict the profitability of complete loop unrolling as accurately as GCC's built-in heuristic. Unlike prior work that targets LLVM or employs increasingly complex models (XGBoost, multi-layer neural networks, graph neural networks), we deliberately start from a minimal, fully interpretable Decision Tree classifier evaluated directly against ground-truth runtime measurements. We construct a dataset of 30 hand-written C functions, of which 21 yield a valid, non-trivially-resolved loop after -O2 (the remaining 9 are excluded because GCC resolves them entirely at compile time), measure the true speedup of -funroll-loops via repeated empirical timing, and extract a small set of static features from the corresponding GIMPLE dump. The resulting dataset is heavily imbalanced (19 UNROLL / 2 NO-UNROLL samples), against which a trivial majority-class baseline already achieves 90.5% accuracy. An unweighted Decision Tree matches this baseline exactly (90.5% under Leave-One-Out Cross-Validation), while the same model trained with scikit-learn's standard class_weight="balanced" setting collapses to 28.6% — a 61.9-percentage-point drop caused entirely by re-weighting two minority-class samples to roughly 9.5× the weight of each majority-class sample, which flips a single decision-tree branch responsible for the large majority of predictions. Direct inspection of GCC's own decision logic in tree-ssa-loop-ivcanon.cc further reveals that none of our five features correspond to num_branches_on_hot_path, the dominant factor in GCC's actual unrolling decision. We report both findings transparently: the class-imbalance sensitivity of a standard re-weighting technique on small datasets, and the missing branch-count feature relative to GCC's real heuristic, using them to motivate feature and evaluation design for subsequent iterations. All experiments, source code, and the generated dataset are made publicly available for reproducibility.

Zenodo (CERN European Organization for Nuclear Research)
Peace, Justice and strong institutions
Parallel Computing and Optimization Techniques
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.