一句话:从相反角度评估编译器优化:开发者手动优化可能反使GCC/LLVM生成更低效代码并暴露缺陷。
编译器优化本应提升生成代码效率,但既有编译器测试工作很少从开发者手动优化这一实际场景出发检验优化效果。本文提出一种简单评估方法:先通过程序变换将源程序变为与原程序等价或效率更低的版本,再分别编译并比较两版生成代码的性能,从而把原程序视为“优化后”版本。作者用该方法评估工业编译器 GCC 和 LLVM,发现原程序中额外的手动优化不仅可能无益,还可能对编译器优化产生反作用,导致最终生成代码整体更低效。评估中总结并报告了 53 个 LLVM 与 18 个 GCC 缺陷,其中分别有 37 个和 17 个被确认或修复。
Optimizations, a critical element within the compiler pipeline, is responsible for improving the efficiency of generated code. In this paper, we take a different angle to evaluate compiler optimizations than all existing works in compiler testing literature. In particular, we consider a specific scenario in software development, that is, when developers manually optimize a program to improve its performance, do compilers actually generate more efficient code with the help of developers' optimizations? To answer this question, we develop a simple approach which consists of (1) transforming a program into the same or less efficient version of the original program, and then (2) comparing the performance of the generated code from each version of the source code. Consequently, the original program can be treated as an optimized version of the transformed program. We use the approach to evaluate GCC and LLVM, two industry compilers, and observe that the extra optimizations presented in the original programs can be not only unhelpful, but more seriously counterproductive to both GCC and LLVM, resulting in the less efficient code generated overall. Out of our evaluation results, we summarized and reported 53 LLVM and 18 GCC defects, out of which 37 and 17 have been confirmed or fixed.
DOI 原文 ·
@inproceedings{paperbot8387,
title = {Efficient Code Causes Inefficiency in Compiler Optimizations},
author = {Hongyu Chen},
booktitle = {ASE},
year = {2024},
doi = {10.1145/3691620.3695369}
}