https://gcc.gnu.org/g:a73b5e72fa52289d8dd718edd10047c822c0c6cd

commit r17-2757-ga73b5e72fa52289d8dd718edd10047c822c0c6cd
Author: Kael Andrew Alonzo Franco <[email protected]>
Date:   Tue Jul 28 12:37:18 2026 -0400

    match: Combine patterns into five for.
    
    This merges 10 simplify patterns so genmatch outputs
    less C++ code.
    
    Bootstrapped and regtested on x86_64-pc-linux-gnu.
    
    gcc/ChangeLog:
    
            * match.pd: Combine patterns into five for.
    
    Signed-off-by: Kael Andrew Franco <[email protected]>

Diff:
---
 gcc/match.pd | 86 ++++++++++++++++++++++++++----------------------------------
 1 file changed, 37 insertions(+), 49 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 62d080931253..f6ecee41509e 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1655,15 +1655,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        && (!wascmp || element_precision (type) == 1))
    @0)))
 
-/* ~(~a & b)  -->  a | ~b  */
-(simplify
- (bit_not (bit_and:cs (bit_not @0) @1))
- (bit_ior @0 (bit_not @1)))
-
-/* ~(~a | b) --> a & ~b */
-(simplify
- (bit_not (bit_ior:cs (bit_not @0) @1))
- (bit_and @0 (bit_not @1)))
+/* ~(~a & b) --> a | ~b
+   ~(~a | b) --> a & ~b  */
+(for iop (bit_and bit_ior)
+     res (bit_ior bit_and)
+ (simplify
+  (bit_not (iop:cs (bit_not @0) @1))
+  (res @0 (bit_not @1))))
 
 /* (a ^ b) & ((b ^ c) ^ a) --> (a ^ b) & ~c */
 (simplify
@@ -1928,30 +1926,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (bit_xor:c (bit_ior:c @0 @1) (bit_ior:c @0 (bit_not @1)))
  (bit_not @0))
 
-/* (x & y) | ~(x | y) -> ~(x ^ y) */
-(simplify
- (bit_ior:c (bit_and:s @0 @1) (bit_not:s (bit_ior:s @0 @1)))
- (bit_not (bit_xor @0 @1)))
+/* (x & y) | ~(x | y) -> ~(x ^ y)
+   (x ^ y) | ~(x | y) -> ~(x & y)  */
+(for lop (bit_and bit_xor)
+     res (bit_xor bit_and)
+ (simplify
+  (bit_ior:c (lop:s @0 @1) (bit_not:s (bit_ior:s @0 @1)))
+  (bit_not (res @0 @1))))
 
 /* (~x | y) ^ (x ^ y) -> x | ~y */
 (simplify
  (bit_xor:c (bit_ior:cs (bit_not @0) @1) (bit_xor:s @0 @1))
  (bit_ior @0 (bit_not @1)))
 
-/* (x ^ y) | ~(x | y) -> ~(x & y) */
-(simplify
- (bit_ior:c (bit_xor:s @0 @1) (bit_not:s (bit_ior:s @0 @1)))
- (bit_not (bit_and @0 @1)))
-
-/* (x & y) ^ (x | y) -> x ^ y */
-(simplify
- (bit_xor:c (bit_and @0 @1) (bit_ior @0 @1))
- (bit_xor @0 @1))
-
-/* (x ^ y) ^ (x | y) -> x & y */
-(simplify
- (bit_xor:c (bit_xor @0 @1) (bit_ior @0 @1))
- (bit_and @0 @1))
+/* (x & y) ^ (x | y) -> x ^ y
+   (x ^ y) ^ (x | y) -> x & y  */
+(for lop (bit_and bit_xor)
+     res (bit_xor bit_and)
+ (simplify
+  (bit_xor:c (lop @0 @1) (bit_ior @0 @1))
+  (res @0 @1)))
 
 /* (x & y) + (x ^ y) -> x | y */
 /* (x & y) | (x ^ y) -> x | y */
@@ -1966,34 +1960,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (plus:c (bit_and @0 @1) (bit_ior @0 @1))
  (plus @0 @1))
 
-/* (x + y) - (x | y) -> x & y */
-(simplify
- (minus (plus @0 @1) (bit_ior @0 @1))
- (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
-      && !TYPE_SATURATING (type))
-  (bit_and @0 @1)))
-
-/* (x + y) - (x & y) -> x | y */
-(simplify
- (minus (plus @0 @1) (bit_and @0 @1))
- (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
-      && !TYPE_SATURATING (type))
-  (bit_ior @0 @1)))
+/* (x + y) - (x | y) -> x & y
+   (x + y) - (x & y) -> x | y  */
+(for rop (bit_ior bit_and)
+     res (bit_and bit_ior)
+ (simplify
+  (minus (plus @0 @1) (rop @0 @1))
+  (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
+       && !TYPE_SATURATING (type))
+   (res @0 @1))))
 
 /* (x | y) - y -> (x & ~y) */
 (simplify
  (minus (bit_ior:cs @0 @1) @1)
  (bit_and @0 (bit_not @1)))
 
-/* (x | y) - (x ^ y) -> x & y */
-(simplify
- (minus (bit_ior @0 @1) (bit_xor @0 @1))
- (bit_and @0 @1))
-
-/* (x | y) - (x & y) -> x ^ y */
-(simplify
- (minus (bit_ior @0 @1) (bit_and @0 @1))
- (bit_xor @0 @1))
+/* (x | y) - (x ^ y) -> x & y
+   (x | y) - (x & y) -> x ^ y  */
+(for rop (bit_xor bit_and)
+     res (bit_and bit_xor)
+ (simplify
+  (minus (bit_ior @0 @1) (rop @0 @1))
+  (res @0 @1)))
 
 /* (x | y) & ~(x & y) -> x ^ y */
 (simplify

Reply via email to