arXiv:2512.15766cs.PLcs.AI2025-12中稿 · ASPLOS 2026被引 3

用检索增强大模型提升循环优化效率,显著加速代码执行。

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

  • 引入循环特征驱动的检索机制,精准获取优化示例。
  • 通过编译测试反馈迭代生成,实现平均14.34倍性能提升。
  • 适合编译器研发与高性能计算开发者参考。

循环变换是保持语义不变的优化技术,广泛用于最大化并行性等目标。尽管研究多年,最优变换组合的应用仍因成本建模复杂而困难。现有研究尝试用大语言模型(LLM)进行代码优化,但常出现错误或次优结果,错失性能提升机会。为此,我们提出LOOPRAG,一种基于检索增强生成的框架,指导LLM对静态控制部分进行有效循环优化。通过参数化方法提取循环特性,生成多样且合法的示例代码作为示范;设计循环感知算法,在相似性与多样性间平衡,以获取最具信息量的示例。为提升生成正确性与效率,引入基于编译、测试和性能反馈的迭代机制,每个优化代码均通过变异、覆盖率与差分测试验证等价性。在PolyBench、TSVC和LORE基准套件上评估,相较基础编译器(GCC-Graphite、Clang-Polly、Perspective、ICX)分别获得最高11.20×、14.34×、9.29×加速,相较基础LLM(DeepSeek、GPT-4)最高达11.97×、5.61×、11.59×加速。

原文摘要 · Abstract (English)

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. 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$.

循环优化大模型编译器性能提升

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。