]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match: Combine patterns into five for.
authorKael Andrew Alonzo Franco <kaelfandrew@gmail.com>
Tue, 28 Jul 2026 16:37:18 +0000 (12:37 -0400)
committerKael Andrew Alonzo Franco <kaelfandrew@gmail.com>
Tue, 28 Jul 2026 16:37:18 +0000 (12:37 -0400)
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 <kaelfandrew@gmail.com>
gcc/match.pd

index 62d080931253bb44517f7d2de726bbc1c959a702..f6ecee41509e360e430da5e0339f998c069495ba 100644 (file)
@@ -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