paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Exploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the Performance Impact

利用 C/C++ 程序中的未定义行为进行优化:性能影响研究
PLDI 9(PLDI)2025匹配度 2/10 · 论文属于编译器/程序语言中未定义行为与优化研究,与用户核心关注的方向(静态分析、LLM/Agent、浮点程序分析、贝叶斯程序分析及其交叉)没有直接关系;虽属 PL 领域,但并非当前研究画像的核心。引用 2 inbox
Lucian Popescu, Nuno P. Lopes
crossref: 2026-09-10

AI 速览

一句话:首个大规模实证研究表明,在 C/C++ 中利用未定义行为进行优化带来的端到端性能提升甚微。

C/C++ 将大量情形定义为未定义行为(UB),编译器社区长期认为利用 UB 可实现关键优化,但此前缺乏严格的大规模实证;与此同时,为提升安全性,消除 UB 的呼声渐高。本文首次系统研究利用 UB 优化对 C/C++ 应用性能的影响。作者基于广泛使用 UB 进行优化的 LLVM,在多个 CPU 架构上针对一组基准和 UB 类别进行评测,比较利用与不利用相关 UB 假设时的端到端性能。结果发现,在所评估范围内性能收益很小;少数性能回退情形通常可通过改进优化算法或启用链接时优化恢复。

问题
C/C++ 中大量未定义行为是否真能带来显著的编译器优化收益,此前缺乏严格的大规模跨架构实证。
方法
基于 LLVM,在多个 CPU 架构和 UB 类别上对基准程序进行端到端性能评测,比较利用与不利用 UB 的优化效果。
评估
结果显示端到端性能提升总体很小;性能回退可通过小幅优化算法改进或链接时优化恢复。
原文摘要(Abstract)

The C and C++ languages define hundreds of cases as having undefined behavior (UB). These include, for example, corner cases where different CPU architectures disagree on the semantics of an instruction and the language does not want to force a specific implementation (e.g., shift by a value larger than the bitwidth). Another class of UB involves errors that the language chooses not to detect because it would be too expensive or impractical, such as dereferencing out-of-bounds pointers. Although there is a common belief within the compiler community that UB enables certain optimizations that would not be possible otherwise, no rigorous large-scale studies have been conducted on this subject. At the same time, there is growing interest in eliminating UB from programming languages to improve security. In this paper, we present the first comprehensive study that examines the performance impact of exploiting UB in C and C++ applications across multiple CPU architectures. Using LLVM, a compiler known for its extensive use of UB for optimizations, we demonstrate that, for the benchmarks and UB categories that we evaluated, the end-to-end performance gains are minimal. Moreover, when performance regresses, it can often be recovered through small improvements to optimization algorithms or by using link-time optimizations.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot3140,
  title = {Exploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the Performance Impact},
  author = {Lucian Popescu and Nuno P. Lopes},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {9},
  number = {PLDI},
  year = {2025},
  doi = {10.1145/3729260}
}