https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112382
Bug ID: 112382 Summary: `(a&b) != a` where a is known to have one known bit set is not optimized to ((~b&a)>>shift) & 1 Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` int f(int a, int b) { a &= 0x10; return (a&b) < a; } int f1(unsigned a, unsigned b) { a &= 0x10; return (a&b) != a; } int f2(unsigned a, unsigned b) { a &= 0x10; unsigned c = (a&b) ^ a; return c>>4; } int f3(unsigned a, unsigned b) { unsigned c = (~b)&a; return (c>>4) & 1; } ``` These all should produce the same code. Right now f2 and f3 produce the best code on x86 (especially with BMI enabled) and aarch64 note f to f1 is really PR 112093 .