https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96921
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Hmm, thinking about expanding this further: int f1(int n) { if (n&~63) __builtin_unreachable(); return 63 - n; } int f2(int n) { if (n&~63) __builtin_unreachable(); return 63 ^ n; } These two should be able to get the same code which happens on clang already. Something like (but with the expansion of the +!, etc.) (simplify (minus INTEGER_CST@0 SSA_NAME@1) (if (exact_power2(@0 + 1) && get_nonzero_bits(@1) == @0 (bit_xor @1 @0)))