A thorough examination of the performance effects of using undefined behaviour in compiler optimizations.

Method:

  1. Modifying clang to not use UB where this is possible
  2. Run a large suite of benchmarks on different architectures, compare results for modified and unmodified clang
  3. Do statistics on the results
  4. Examine performance deviations
  5. Discuss factors which could bias results.

Very good science!

Result in short:

Only on ARM and if no link-time optimization is used, a systematic small positive performance effect can be seen. For Intel and AMD CPUs, there are no systematic improvements.

Average effects are typically below 2%, which is the typical effect of system and measurement noise. Often, effects are even negative. In some cases, benchmarks show large differences, and many of these can be fixed by simple modifications to the compiler or program.

    • mina86@lemmy.wtf
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 hours ago

      It is a product of its time. If the same research was made 30 years ago, I bet there would be a stark difference to results today. LTO wasn’t as feasible. Compilers were less capable of removing redundant checks. Branch prediction in x86 processors was still a hot new thing. And on top of it all, there was less knowledge about language development.