https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110111
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- f1: _6 = b_2(D) ^ c_3(D); _7 = a_1(D) & _6; _4 = c_3(D) ^ _7; Which was done due to: /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */ (simplify (bit_ior:c (bit_and:cs @0 (bit_not @2)) (bit_and:cs @1 @2)) (bit_xor (bit_and (bit_xor @0 @1) @2) @0)) Note if we move this over to bitwise_inverted_equal_p (which we should), we will lose also: ``` bool f(int a, int b, int t) { bool x = a == 0; bool y = b == 1; bool m = t == 2; bool mp = !m; return (x & mp) | (y & m); } ``` Which is currently handled. We should check for `element_precision (type) == 1` too. So something like: (simplify (bit_ior (bit_and:c@and1 @0 @3) (bit_and:c@and2 @1 @2)) (with { bool wascmp; } (if (bitwise_inverted_equal_p (@0, @2, wascmp)) (switch /* For 1bit, wascmp can be true and we can just convert it into `m ? y : x` */ (if (INTEGRAL_TYPE_P (type) && element_precision (type) == 1) (cond @3 @0 @1)) (if (!wascmp && element_precision (type) != 1 && single_use (@and1) && single_use (@and2)) (bit_xor (bit_and (bit_xor @0 @1) @2) @0)) ) ) ) ) ) /* 1bit `((x ^ y) & m) ^ x` should just be convert into `m ? y : x` early */ (simplify (bit_xor:c (bit_and:c (bit_xor:c @0 @1) @2) @0) (if (INTEGRAL_TYPE_P (type) && element_precision (type) == 1) (cond @2 @0 @1)))