Skip to content
0:00 / 0:00

#undefinedbehavior#compileroptimizations#llvm

C++Now 2018: John Regehr “Closing Keynote: Undefined Behavior and Compiler Optimizations”

CppNow

39K subscribers • 49 videos on Hallway • Conference channel

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • A classic. People kept recommending it from 2018 to 2021.
  • Presented by John Regehr, Professor of Computer Science at the University of Utah

Advanced. Deep dive for people who know the field.

10K views8 years ago2 recommendations

Systems programmingProgramming languagesCompilers and interpretersPerformance and optimizationC++

John Regehr explains how compilers exploit undefined behavior in intermediate representations to perform optimizations and discusses sequential memory models.

cppnow.org — Presentation Slides, PDFs, Source Code and other presenter materials are available at: cppnow.org/history/2018/talks/ — This talk is about the inner lives of compiler optimizations. First, I'll explain how undefined behavior (UB) is alive and well in compiler intermediate representations, where it can be exploited to give the optimizer the freedom to perform desirable transformations. Perhaps surprisingly, UB at this level doesn't have that much to do with UB in the original source code. Second -- and closely related -- I'll talk about sequential memory models. C++ occupies a tricky design point: on one hand, it wants to be able to assume that a pointer originating in one block of memory cannot be used to refer to another block, but on the other hand any pointer can be turned into an integer, manipulated arbitrarily, and then turned back into a pointer. These conflicting demands have interesting implications for a compiler's optimization rules and some of the implications are still being figured out. Finally, I'll speculate about the future of compiler optimizations: many optimizations will be formally verified and some will also be generated automatically. The result will be compilers that are less buggy and more effective at optimizing. — John Regehr is a professor of computer science at the University of Utah, USA. His research group creates tools for making software more efficient and correct. For example, one of his projects, Csmith, generates random C programs that have been used to find more than 500 previously unknown bugs in production-quality C compilers. Outside of work John likes to explore the mountains and deserts of Utah with his family. — Videos Filmed & Edited by Bash Films: BashFilms.com --- *--* ---

Why it's here

2 people recommend this

What people say. Recommended as an excellent explanation of how compilers exploit undefined behavior at the intermediate representation level.

u/Saefrochin r/rust • Recommends

On “Is the statement "Rust is largly unoptimized for speed and has untapped speed potential" true and where is the source?”

In addition to mutable-noalias, Rust in general just provides a more optimizable pointer model. Stacked Borrows is still experimental but at this point I would be surprised if there is a final decision to do something much different. In any case, Stacked Borrows stipulates a provenance model which is very friendly to optimizers, as opposed to C and C++ which currently don't have a provenance model at all. Compilers try to shoehorn one in because without one it's hard to imagine how you can put anything which has its address taken into a register. link to this video

u/tasminimain r/C_Programming • Recommends

On “Three modest proposals for the C standard WG14”

…situation completely with unpredictable results" -- and even then they have a rather, hm lets say audacious interpretation of that sentence. They are, however, wrong in several ways, in the sense that the resulting situation is extremely problematic. * the most useful transformations are done at the intermediate representation level ( see for ex link to this video ) so one of the way to exploit the UB that are defined at programming language level is to simply forward "them" blindly (their consequences, the related constraints that can be immediately deduced from the hypothesis of the absence of UB in the program, etc.) to the intermediate repr. However, I argue that doing this is just lazy and *terr…