https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98304
Bug ID: 98304 Summary: Failure to optimize bitwise arithmetic pattern Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: gabravier at gmail dot com Target Milestone: --- int f1(int n) { return n - (((n > 63) ? n : 63) & -64); } This can be optimized to `return (n <= 63) ? n : (n & 63);` (and presumably the same optimization should be doable with other powers of 2). PS: I found this optimization while looking at how this : int f1(int n) { while (n >= 64) n -= 64; return n; } is optimized. LLVM outputs the first example I gave here, while GCC outputs the optimization I gave here.