https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106244
Bug ID: 106244 Summary: Failure to optimize (1 << x) & 1 to `x == 0` if separated into multiple statements Product: gcc Version: 13.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: --- #include <stdint.h> int8_t f(int8_t x) { int8_t sh = 1 << x; return sh & 1; } This can be optimized to `return x == 0;`. This transformation is done by LLVM, but not by GCC. PS: For some reason GCC manages to do this optimization if I replace `f` with `return (1 << x) & 1;` instead of having it spelled out in 2 statements.