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

Time-Series based phase-ordering selection for code-size reduction

Zhenbang Peng, Yi Zhang, Mingjie Xing, Yanjun Wu, Chen Zhao

Abstract

The phase-ordering problem in compilers—determining the optimal sequence of optimization passes—remains a significant challenge due to the complex interdependencies between transformations. This paper introduces PPO-LSTM, a reinforcement learning approach that combines Proximal Policy Optimization (PPO) with Long Short-Term Memory (LSTM) networks. By capturing the historical context of optimization sequences, PPO-LSTM achieves a 5.7% greater reduction in code size and up to 6x faster convergence compared to standard RL methods.

Introduction

Modern compilers like LLVM utilize hundreds of optimization passes to improve code performance and reduce size. However, the effectiveness of these passes is highly sensitive to their execution order. A sequence that optimizes one program may be suboptimal for another, a challenge known as the phase-ordering problem. While standard reinforcement learning (RL) has been applied to this domain, most existing models treat optimization as a memoryless process where decisions are based solely on the current code state. This ignores the temporal dynamics where previous passes significantly influence the potential impact of future ones.

Methodology

To address the limitations of memoryless RL, the authors propose a hybrid architecture integrating PPO with an LSTM layer. PPO provides a stable policy gradient method for learning optimization strategies, while the LSTM layer maintains a "memory" of the previous 20 optimization steps. This allows the agent to account for the path-dependent nature of code transformations.

The PPO-LSTM training workflow integrating a rollout buffer and the LSTM-enhanced network.

The system was implemented using the CompilerGym framework on LLVM 17.0.0. The agent operates within a 117-pass action space and observes the code via "Autophase," a 56-dimensional vector of static features. The reward function is defined by the reduction in Intermediate Representation (IR) instruction count relative to the standard LLVM -Oz baseline.

Key Results

The integration of temporal context yielded significant improvements in both learning efficiency and optimization quality.

Convergence Speed

PPO-LSTM demonstrated a dramatic increase in training efficiency. On individual functions like bzip2, the model converged 50 iterations faster than standard PPO. Across entire benchmarks, the PPO-LSTM agent reached optimal performance in approximately 500 iterations, whereas the baseline PPO required 3,000 iterations—a 6x speedup.

Optimization Performance

Empirical results show that PPO-LSTM consistently outperforms standard PPO and the hand-tuned -Oz baseline. The model achieved an additional 5.758% reduction in code size across the benchmark suite compared to standard PPO. In cross-validation on the chstone benchmark, it reached a 1.093x improvement over -Oz.

Comparison of code-size reduction rates between PPO and PPO-LSTM across various benchmarks.

Conclusion and Future Work

While PPO-LSTM shows superior performance, the authors observed reward oscillations during training. This is likely due to the conflicting effects of certain passes on different functions within the same file. Future research will focus on function-level tuning to provide more granular optimization sequences and techniques to stabilize reward metrics across diverse software projects.

Summary updated

BibTeX
@inproceedings{peng2024time,
  author = {Zhenbang Peng and Yi Zhang and Mingjie Xing and Yanjun Wu and Chen Zhao},
  title = {{Time-Series based phase-ordering selection for code-size reduction}},
  booktitle = {SEKE},
  year = {2024},
  doi = {10.18293/seke2024-122},
}
Figure