https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96226
Bug ID: 96226 Summary: Failure to optimize shift+not to rotate 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: --- int32_t f(int32_t x) { return ~(1 << (x & 0x1F)); } This can be transformed to doing a rotate of -2 and x. This transformation is done by LLVM, but not by GCC. PS: GCC seems capable of doing this optimization, but only if `x & 0x1F` is replaced with `x`, which either means that GCC is underoptimizing this or that LLVM is somehow wrong.