Exploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the Performance Impact
We presented the first comprehensive study on the performance impact of exploiting undefined behavior (UB) in C and C++ programs. First, we cataloged 18 individual UB aspects exploited by LLVM, a compiler that is widely known for its extensive use of UB. We then implemented flags in the compiler that disable exploitation of each UB aspect by strengthening the semantics (e.g., define division by zero as a well-defined trap instead of UB).
The results show that, in the cases we evaluated, the performance gains from exploiting UB are minimal [выделение моё]. Furthermore, in the cases where performance regresses, it can often be recovered by either small to moderate changes to the compiler or by using link-time optimizations