https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115896
Bug ID: 115896 Summary: Failure to optimize shift+compare involving constants to and+compare Product: gcc Version: 14.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> bool f1(int8_t a) { int8_t b = a << 4; return b == -128; } bool f2(int8_t a) { return (a & 15) == 8; } f1 and f2 are equivalent, according to LLVM, but GCC outputs different code for both and doesn't consider them equivalent if one does `f1(a) == f2(a)`. This transformation would be useful for those canonicalization reasons (and also because f2 seems at first glance better for further optimization), but furthermore, while the emitted code is roughly equivalent on platforms like x86, it seems faster on various other platforms such as ARM, PowerPC, RISC-V, MIPS, 68k and AVR, and in general also results in shorter code.