arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2501.00655cs.SEcs.LGcs.PL
收藏

使用LLM发现编译器中遗漏的代码大小优化

Finding Missed Code Size Optimizations in Compilers using LLMs

Meta;FAIR at Meta(Meta FAIR研究院)

Davide Italiano, Chris Cummins

AI总结:

本文提出一种结合LLM与差分测试的简单方法,用于发现C/C++、Rust和Swift编译器中遗漏的代码大小优化,已报告24个已确认缺陷。

摘要:

编译器非常复杂,人们已投入大量精力对其进行测试。随机程序生成和差分测试等技术已被证明非常有效,并在生产编译器中发现了数千个缺陷。大部分精力都花在验证编译器是否为给定输入生成正确代码上,而对确保编译器生成高性能代码的关注较少。在这项工作中,我们将差分测试应用于识别编译器中遗漏的优化机会这一任务。我们开发了一种新颖的测试方法,将大型语言模型(LLM)与一系列差分测试策略相结合,并用它们在C/C++编译器中寻找遗漏的代码大小优化。我们方法的优势在于其简单性。我们将生成随机代码这一复杂任务交给现成的LLM,并使用启发式方法和分析来识别异常的编译器行为。我们的方法实现所需代码不到150行。这种简单性使其具有可扩展性。只需更改目标编译器和初始LLM提示,我们就能将该方法从C/C++移植到Rust和Swift,并在两者中都发现了缺陷。迄今为止,我们已在生产编译器中报告了24个已确认的缺陷,并得出结论:LLM辅助测试是检测现实世界编译器中优化缺陷的一条有前景的途径。

英文摘要:

Compilers are complex, and significant effort has been expended on testing them. Techniques such as random program generation and differential testing have proved highly effective and have uncovered thousands of bugs in production compilers. The majority of effort has been expended on validating that a compiler produces correct code for a given input, while less attention has been paid to ensuring that the compiler produces performant code. In this work we adapt differential testing to the task of identifying missed optimization opportunities in compilers. We develop a novel testing approach which combines large language models (LLMs) with a series of differential testing strategies and use them to find missing code size optimizations in C / C++ compilers. The advantage of our approach is its simplicity. We offload the complex task of generating random code to an off-the-shelf LLM, and use heuristics and analyses to identify anomalous compiler behavior. Our approach requires fewer than 150 lines of code to implement. This simplicity makes it extensible. By simply changing the target compiler and initial LLM prompt we port the approach from C / C++ to Rust and Swift, finding bugs in both. To date we have reported 24 confirmed bugs in production compilers, and conclude that LLM-assisted testing is a promising avenue for detecting optimization bugs in real world compilers.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑