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 <andrew.pinski@oss.qualcomm.com>
This commit is contained in:
Andrew Pinski
2026-04-29 14:34:32 -07:00
parent 319c0f0249
commit c65691bc5a

View File

@@ -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. */