https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111108
Bug ID: 111108 Summary: (a|c) == (a|c) should be convert into (a&~c) == (a&~c) IFF ~c simplifies Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` #define C 0x1 unsigned g(unsigned X, unsigned Y) { return (X | C) == (Y | C); } unsigned g1(unsigned X, unsigned Y) { return (X & ~C) == (Y & ~C); } unsigned g2(unsigned X, unsigned Y) { return ((X | C) & ~C) == ((Y | C) & ~C); } ``` These all functions are the same as (X|C) == (Y|C) is saying the only bits of X and Y which you want to compare is ~C. Note I suspect we could also do this for non-constant C but that would normally produce worse code but maybe we could see if both X & ~C and Y & ~C simplifies (due to non-zero bits ...).