Nice blog post from Dan Luu about the overhead of integer overflow checking:

One thing to keep in mind is that the overflow checking that we did for Clang is really not tuned for performance. Our implementation replaces each operation with a checked version: the LLVM x.with.overflow intrinsics. No problem so far! But then, every check is immediately followed by a branch to error handler. This is nice because it gives very precise information about what overflowed, but it is not the performant implementation. To do this right, you want to OR together a whole expressions' worth (or more) of overflow flags and then put a branch at the end. But now you have to go back and figure out what happened if you want to print a good diagnostic. Since our primary focus was diagnostics and not performance, we didn't do that stuff. So Clang integer overflow checking is not that fast.

Of course there are other problems too, such as the poor register allocation decision in Dan's post. Another major problem is that LLVM lacks a solid value range analysis that could be used to remove provably unnecessary overflow checks. So basically there's a lot of room for improvement.

Anyhow Dan's blog doesn't allow comments so I wanted to leave this somewhere.

Also I am psyched that Souper (our LLVM superoptimizer) will soon understand the x.with.overflow intrinsics and sooner or later we can expect it to do a somewhat decent job of getting rid of unnecessary checks.
Shared publiclyView activity