一句话:提出以死代码消除为透镜自动发现编译器遗漏优化的通用方法,并在GCC/LLVM上发现大量问题。
编译器优化日益复杂,自动发现遗漏优化十分困难;现有方法要么定位不准确,要么仅针对特定分析。本文提出一种简单通用的新方法:在程序基本块中插入“优化标记”,据此计算活跃/死基本块,并依据编译器消除死块的程度来识别遗漏优化。其核心洞察是死代码消除(DCE)高度依赖整个优化流水线,可借此系统量化编译器的优化能力。作者对GCC和LLVM进行了广泛分析,给出了关于其优化能力的定量与定性见解,并发现多种遗漏优化,最终提交84个缺陷报告,其中62个已被确认或修复。
Compilers are foundational software development tools and incorporate increasingly sophisticated optimizations. Due to their complexity, it is difficult to systematically identify opportunities for improving them. Indeed, the automatic discovery of missed optimizations has been an important and significant challenge. The few existing approaches either cannot accurately pinpoint missed optimizations or target only specific analyses. This paper tackles this challenge by introducing a novel, effective approach that --- in a simple and general manner --- automatically identifies a wide range of missed optimizations. Our core insight is to leverage dead code elimination (DCE) to both analyze how well compilers optimize code and identify missed optimizations: (1) insert "optimization markers" in the basic blocks of a given program, (2) compute the program's live/dead basic blocks using the "optimization markers", and (3) identify missed optimizations from how well compilers eliminate dead blocks. We essentially exploit that, since DCE heavily depends on the rest of the optimization pipeline, through the lens of DCE, one can systematically quantify how well compilers optimize code. We conduct an extensive analysis of GCC and LLVM using our approach, which (1) provides quantitative and qualitative insights regarding their optimization capabilities, and (2) uncovers a diverse set of missed optimizations. Our results also lead to 84 bug reports for GCC and LLVM, of which 62 have already been confirmed or fixed, demonstrating our work's strong practical utility. We expect that the simplicity and generality of our approach will make it widely applicable for understanding compiler performance and finding missed optimizations. This work opens and initiates this promising direction.