Quadrupling code performance with a "useless" if

120 points by purplesyringa


ibookstein

It looks like annotating the if-statement with the C++20 [[unlikely]] attribute is sufficient to prevent clang from eliminating it: https://clang.godbolt.org/z/r4xYWfPfe

I haven't checked other compilers though.

mikejsavage

FYI this is called "value speculation" elsewhere: https://mazzo.li/posts/value-speculation.html

sardaukar

This article made me wonder if people will even care about this kind of blog post in 2 or 3 years, when fewer and fewer coders will actually care about their LLMs' output.