Exploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the Performance Impact
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.
Wed 18 JunDisplayed time zone: Seoul change
10:30 - 12:10 | Compilers 1PLDI Research Papers at Grand Ball Room 2 Chair(s): Bor-Yuh Evan Chang University of Colorado Boulder & Amazon | ||
10:30 20mTalk | Partial Evaluation, Whole-Program Compilation PLDI Research Papers DOI Pre-print | ||
10:50 20mTalk | Exploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the Performance Impact PLDI Research Papers Lucian Popescu INESC-ID; Instituto Superior Técnico - University of Lisbon; Politehnica University of Bucharest, Nuno P. Lopes INESC-ID; Instituto Superior Técnico - University of Lisbon Link to publication DOI | ||
11:10 20mTalk | Relaxing Alias Analysis: Exploring the Unexplored Space PLDI Research Papers DOI | ||
11:30 20mTalk | Webs and Flow-Directed Well-Typedness Preserving Program Transformations PLDI Research Papers Benjamin Quiring University of Maryland, David Van Horn University of Maryland, John Reppy University of Chicago, Olin Shivers Northeastern University DOI | ||
11:50 20mTalk | Slotted E-Graphs: First-Class Support for (Bound) Variables in E-Graphs PLDI Research Papers Rudi Schneider Technische Universität Berlin, Marcus Rossel Barkhausen Institut, Amir Shaikhha University of Edinburgh, Andrés Goens University of Amsterdam, Thomas Koehler CNRS - ICube Lab, Michel Steuwer Technische Universität Berlin DOI Pre-print File Attached |