LOOPRAG: Enhancing Loop Transformation Optimization with Retrieval-Augmented Large Language Models

Yijie Zhi, Yayu Cao, Jianhua Dai, Xiaoyang Han, Jingwen Pu +3 more
12/12/2025
cs.PLcs.AIcs.DC
rag

No confident code implementation found for this paper.

Abstract

Loop transformations are semantics-preserving optimization techniques, widely used to maximize objectives such as parallelism. Despite decades of research, applying the optimal composition of loop transformations remains challenging due to inherent complexities, including cost modeling for optimization objectives.

Show full abstract

Recent studies have explored the potential of Large Language Models (LLMs) for code optimization. However, our key observation is that LLMs often struggle with effective loop transformation optimization, frequently leading to errors or suboptimal optimization, thereby missing opportunities for performance improvements. To bridge this gap, we propose LOOPRAG, a novel retrieval-augmented generation framework designed to guide LLMs in performing effective loop optimization on Static Control Part. We introduce a parameter-driven method to harness loop properties, which trigger various loop transformations, and generate diverse yet legal example codes serving as a demonstration source. To effectively obtain the most informative demonstrations, we propose a loop-aware algorithm based on loop features, which balances similarity and diversity for code retrieval. To enhance correct and efficient code generation, we introduce a feedback-based iterative mechanism that incorporates compilation, testing and performance results as feedback to guide LLMs. Each optimized code undergoes mutation, coverage and differential testing for equivalence checking. We evaluate LOOPRAG on PolyBench, TSVC and LORE benchmark suites, and compare it against compilers (GCC-Graphite, Clang-Polly, Perspective and ICX) and representative LLMs (DeepSeek and GPT-4). The results demonstrate average speedups over base compilers of up to 11.20$\times$, 14.34$\times$, and 9.29$\times$ for PolyBench, TSVC, and LORE, respectively, and speedups over base LLMs of up to 11.97$\times$, 5.61$\times$, and 11.59$\times$.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{zhi2025looprag,
  title  = {LOOPRAG: Enhancing Loop Transformation Optimization with Retrieval-Augmented Large Language Models},
  author = {Yijie Zhi and Yayu Cao and Jianhua Dai and Xiaoyang Han and Jingwen Pu and Qingran Wu and Sheng Cheng and Ming Cai},
  year   = {2025},
  eprint = {2512.15766},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2512.15766v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2512.15766.svg)](https://codeofpaper.com/paper/2512.15766)

Discussion