一句话:提出检索增强LLM框架LOOPRAG,通过参数化示例生成、循环感知检索与反馈迭代提升循环变换优化。
循环变换是编译器中重要的语义保持优化,但最优变换组合的选取受依赖分析和代价建模复杂性制约。现有大语言模型在循环变换优化上常产生错误或次优结果。为此,本文提出LOOPRAG,一个面向静态控制部分(SCoP)的检索增强生成框架。该方法用参数驱动方式刻画循环属性并触发多种循环变换,生成多样且合法的示例代码作为演示源;提出基于循环特征的检索算法,在相似性与多样性间取得平衡;并引入编译、测试与性能反馈的迭代机制,引导LLM生成正确且高效的代码。生成的优化代码还经过变异、覆盖率和差分测试进行等价性检查。在PolyBench、TSVC和LORE基准上,与GCC-Graphite、Clang-Polly、Perspective、ICX及DeepSeek、GPT-4等对比,相对编译器最高加速分别为11.20×、14.34×和9.29×,相对基础LLM最高加速分别为11.97×、5.61×和11.59×。
Loop transformations are semantics-preserving optimization techniques applied at the source level, widely used in compilers to maximize objectives such as vectorization and parallelism. Despite decades of research, applying the optimal composition of loop transformations remains challenging due to inherent complexities, including dependency analysis and cost modeling for optimization objectives. 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 significant 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 (SCoP). 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 generated by LOOPRAG undergoes mutation, coverage and differential testing to perform 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 compilers of up to 11.20×, 14.34×, and 9.29× for PolyBench, TSVC, and LORE, respectively, and speedups over base LLMs of up to 11.97×, 5.61×, and 11.59×.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{abs-2512-15766,
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 Qinran Wu and Sheng Cheng and Ming Cai},
booktitle = {ASPLOS},
year = {2026},
doi = {10.1145/3779212.3790183}
}