arXiv:2505.11480cs.CLcs.AI2025-05被引 8

用大模型优化汇编代码,速度比编译器还快。

SuperCoder: Assembly Program Superoptimization with Large Language Models

  • 用大模型生成优化后的汇编代码,保持功能不变
  • 新模型平均提速1.46倍,正确率高达95%
  • 适合想提升程序性能的开发者和研究者

超优化旨在将程序改写为更快版本,理想情况下是最快可能的版本,同时保持输入输出行为一致。本文探索大语言模型(LLM)能否作为超优化器,生成在端到端运行时间上优于行业标准编译器优化代码的汇编程序。我们构建了首个大规模基准测试,包含8,072个平均130行的汇编程序,远超以往仅限2-15行无循环直行代码的数据集。对23个LLM进行评估,最强基线Claude-opus-4在测试中通过率为51.5%,相比gcc -O3平均提速1.43倍。为进一步提升性能,我们采用强化学习微调模型,优化结合正确性和加速效果的奖励函数。从Qwen2.5-Coder-7B-Instruct(正确率61.4%,平均提速1.10倍)出发,微调后的SuperCoder模型达到95.0%正确率与1.46倍平均提速,通过Best-of-N采样和迭代精炼实现进一步提升。结果首次证明,大模型可应用于汇编程序超优化,为超越编译器启发式方法的程序性能优化研究奠定基础。

原文摘要 · Abstract (English)

Superoptimization is the task of transforming a program into a faster one, and ideally the very fastest possible one, while preserving its input-output behavior. In this work, we investigate whether large language models (LLMs) can serve as superoptimizers, generating assembly programs that outperform code already optimized by industry-standard compilers in end-to-end runtime. We construct the first large-scale benchmark for this problem, consisting of 8,072 assembly programs averaging 130 lines, in contrast to prior datasets restricted to 2-15 straight-line, loop-free programs. We evaluate 23 LLMs on this benchmark and find that the strongest baseline, Claude-opus-4, achieves a 51.5% test-passing rate and a 1.43x average speedup over gcc -O3. To further enhance performance, we fine-tune models with reinforcement learning, optimizing a reward function that integrates correctness and performance speedup. Starting from Qwen2.5-Coder-7B-Instruct (61.4% correctness, 1.10x speedup), the fine-tuned model SuperCoder attains 95.0% correctness and 1.46x average speedup, with additional improvement enabled by Best-of-N sampling and iterative refinement. Our results demonstrate, for the first time, that LLMs can be applied as superoptimizers for assembly programs, establishing a foundation for future research in program performance optimization beyond compiler heuristics.

代码优化大模型汇编加速

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