]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match: Simplify patterns for `a != b` implies a or b is non-zero
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 29 Apr 2026 21:34:32 +0000 (14:34 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 30 Apr 2026 15:24:49 +0000 (08:24 -0700)
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>
gcc/match.pd

index df960a0cf29ffc4b6bfe64af583597c3a750b1be..62c43b31117a660636201092e7b065d8357fa408 100644 (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.  */