Re:Exploiting Undefined Behavior in C/C++ Programs: The Perf...
by mwkaufma on Friday April 25, 2025 @12:58PM
(#43795976)
Reading e.g. the 13% perf regression in simdjson from disabling UB:
"can" is doing a lot of heavy-lifting here. Guaranteeing expected optimizations "will" be applied are hard-enough, without leaving it entirely to an easily-derailed indirect side-effect.
[ Parent
| on HN ]
Re:Exploiting Undefined Behavior in C/C++ Programs: The Perf...
by UebVar on Friday April 25, 2025 @01:25PM
(#43796294)
This is "can" has exactly the same meaning as in "UB can make your programms faster". You could replace it with "it does, at least with clang". LTO is, in this regard, the same as UB, and unlike guaranteed optimizations, such as the single member optimization, or the empty base optimization.
Re:Exploiting Undefined Behavior in C/C++ Programs: The Perf...
by mwkaufma on Friday April 25, 2025 @01:56PM
(#43796655)
Concretely, here, the UB-exploitation in question in this case is assuming that the "this" pointer in C++ is aligned and non-null, meaning it's a pervasive annotation throughout C++ codebases, not an edge-case.
Relying on LTO to "discover" this annotation through interprocedural analysis -- based on my experience of looking at LTO in practice -- will not be as comprehensive, and even when it works it accomplishes its task in an achingly-slow and expensive way.
This is a real devil-is-in-the-details case.