https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98961
Bug ID: 98961 Summary: Failure to optimize successive comparisons with 0 into clz 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 f(int i, int j) { return i == 0 || j == 0; } This can be optimized to `return (__builtin_clz(i) | __builtin_clz(j)) >> 5;` (if `clz(0)` returns 0). LLVM does this transformation, but GCC does not. On x86, for example, with lzcnt, while this does not seem to be a net win in terms of performance (at least, not for this code alone), it also simply not a loss. As it is a win in terms of code size (which should make it a net win in most situations), I think that should make it a net win overall in actual code. See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10588