From: Andrew Pinski Date: Wed, 29 Apr 2026 21:34:32 +0000 (-0700) Subject: match: Simplify patterns for `a != b` implies a or b is non-zero X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c65691bc5a2873e0e2ffbfcaa80eb9bdc6e1f7b8;p=thirdparty%2Fgcc.git match: Simplify patterns for `a != b` implies a or b is non-zero This simplified the patterns by using a for loop. Also noticed that the `:c` on the inner ne/eq is not needed as it will match the same canonicalization as the inner bit_ior too so removes that too. This removes a little more 300 lines from the generated gimple-match*.cc files too. Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd (`(a !=/== b) &\| ((a|b) ==/!= 0)`): Simplify patterns using for loop and remove the `:c` on the inner ne/eq. Signed-off-by: Andrew Pinski --- diff --git a/gcc/match.pd b/gcc/match.pd index df960a0cf29..62c43b31117 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7068,29 +7068,29 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) #if GIMPLE /* Given two integers a and b: (a != b) & ((a|b) != 0) -> (a != b) - (a != b) | ((a|b) != 0) -> ((a|b) != 0) - (a == b) & ((a|b) == 0) -> ((a|b) == 0) (a == b) | ((a|b) == 0) -> (a == b) + + (a == b) & ((a|b) == 0) -> ((a|b) == 0) + (a != b) | ((a|b) != 0) -> ((a|b) != 0) + (a != b) & ((a|b) == 0) -> false (a == b) | ((a|b) != 0) -> true */ -(simplify - (bit_and:c (ne:c @0 @1) (ne (bit_ior @0 @1) integer_zerop)) - (ne @0 @1)) -(simplify - (bit_ior:c (ne:c @0 @1) (ne (bit_ior@2 @0 @1) integer_zerop@3)) - (ne @2 @3)) -(simplify - (bit_and:c (eq:c @0 @1) (eq (bit_ior@2 @0 @1) integer_zerop@3)) - (eq @2 @3)) -(simplify - (bit_ior:c (eq:c @0 @1) (eq (bit_ior @0 @1) integer_zerop)) - (eq @0 @1)) -(simplify - (bit_and:c (ne:c @0 @1) (eq (bit_ior @0 @1) integer_zerop)) - { constant_boolean_node (false, type); }) -(simplify - (bit_ior:c (eq:c @0 @1) (ne (bit_ior @0 @1) integer_zerop)) - { constant_boolean_node (true, type); }) +(for bitop (bit_and bit_ior) + neeq (ne eq) + (simplify + (bitop:c (neeq @0 @1) (neeq (bit_ior @0 @1) integer_zerop)) + (neeq @0 @1))) +(for bitop (bit_and bit_ior) + neeq (eq ne) + (simplify + (bitop:c (neeq @0 @1) (neeq (bit_ior@2 @0 @1) integer_zerop@3)) + (neeq @2 @3))) +(for bitop (bit_and bit_ior) + neeql (ne eq) + neeqr (eq ne) + (simplify + (bitop (neeql @0 @1) (neeqr (bit_ior @0 @1) integer_zerop)) + { constant_boolean_node (bitop==BIT_AND_EXPR, type); })) #endif /* These was part of minmax phiopt. */