https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112095
Bug ID: 112095 Summary: `((~x) & y) ^ (x | y)` is x Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: pinskia at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` int f(int x, int y) { return ((~x) & y) ^ (x | y); // x } int g(int x, int y) { return ((~x) | y) ^ (x & y); // ~x } ``` These should simplify to what is in the comments. So something like: (simplify (bit_xor:c (bit_ior:c @0 @1) (bit_and:c @2 @1)) (with { bool wascmp; } (if (bitwise_inverted_equal_p (@0, @2, wascmp) && (!wascmp || element_precision (type) == 1)) @0))) The above pattern will catch both.