https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98299
--- Comment #3 from Gabriel Ravier <gabravier at gmail dot com> --- PS: The optimization seems to already occur for simpler cases such as powers of 2, e.g. : int f1(int n) { while (n >= 64) n -= 64; return n; } is optimized into `return (n <= 63) ? n : (n & 63);`.