Superoptimization is the process where a compiler automatically finds the optimal sequence for a loop-free sequence of instructions.

– Wikipedia

Compilers are good at making mechanical transformations that make code faster. Unfortunately, most of them are not as good at non-trivial reasoning, so they can’t invent a completely novel approach to solving your problem.

When designing a library for floating-point calculations, I had to implement a function that takes a float f and produces a float corresponding to the lowest set bit in f. For example, if f=1.01101⋅210 in binary, it would return 0.00001⋅210=25.

This can be implemented with bit twiddling, but the straightforward algorithm breaks for powers of two, so I had to insert an if: