Towards -OmL: A Deep Learning Based Approach for Outperforming Compiler Defaults
Hafsah Shahzad, Ahmed Sanaullah, Sanjay Arora, Ulrich Drepper, Martin Herbordt · 2025
Compilers offer default optimization levels (e.g., -Oz, -O3) to generate high performance code based on developer goals such as size, speed, or energy efficiency. As prior work has shown, however, these default levels often generate code that leaves substantial room for improvement. While per-application tuning of compiler heuristics can yield performance benefits, it is time-consuming and lacks generality. A preferred solution is one where a single deep learning model can (i) surpass performance of compiler defaults and (ii) is sufficiently practical to be integrated into the compiler as its own option, e.g., -OmL.In this work, we first train such a deep learning model for code size reduction (-OzmL). Our reinforcement learning (RL) based approach achieves an average reduction in code size of 1.40% over GCC 13’s -Ozand yields 1.37% better byte reduction as compared to state-of-the-art efforts. Across a large, diverse set of functions from standard benchmarks, this model optimizes 36.7% of the functions achieving an average 8.45% code size reduction on top of -Ozfor those functions. As expected with any model, however, there are still some functions whose performance degrades when compared to -Oz. We therefore propose a classifier to be used in tandem with the model to reduce such performance regressions, reducing them by 99%. Results demonstrate the viability of a practical and learning-based -OmLoptimization level in production compilers.