]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/103356 Add missing (~a) == b folding for _Bool
authorAndrew Pinski <apinski@marvell.com>
Sat, 26 Nov 2022 07:37:40 +0000 (07:37 +0000)
committerAndrew Pinski <apinski@marvell.com>
Sat, 26 Nov 2022 18:00:43 +0000 (18:00 +0000)
The following makes sure to fold (~a) ==  b to a ^ b for truth
values.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

PR tree-optimization/103356

gcc/ChangeLog:

* match.pd: ((~a) == b -> a ^ b): New pattern.

gcc/testsuite/ChangeLog:

* gcc.dg/pr103356-1.c: New test.

gcc/match.pd
gcc/testsuite/gcc.dg/pr103356-1.c [new file with mode: 0644]

index a4d1386fd9f63b4a32142534a9b5ccfdf3784eb4..67a0a682f31e7fa85c73eb6d71835fa1b526a74f 100644 (file)
@@ -1999,6 +1999,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       && TYPE_PRECISION (TREE_TYPE (@0)) == 1)
   (convert (eq @0 @1))))
 
+/* (~a) == b is a ^ b for truth valued a and b.  */
+(simplify
+ (eq:c (bit_not:s truth_valued_p@0) truth_valued_p@1)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+      && TYPE_PRECISION (TREE_TYPE (@0)) == 1)
+  (convert (bit_xor @0 @1))))
+
 /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */
 (simplify
  (bit_ior:c (bit_and:cs @0 (bit_not @2)) (bit_and:cs @1 @2))
diff --git a/gcc/testsuite/gcc.dg/pr103356-1.c b/gcc/testsuite/gcc.dg/pr103356-1.c
new file mode 100644 (file)
index 0000000..61d0b81
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1" } */
+
+_Bool foo (_Bool a, _Bool b)
+{
+  return a == (!b);
+}
+
+/* { dg-final { scan-tree-dump "\[ab\]_\[0-9\]+\\(D\\) \\\^ \[ba\]_\[0-9\]+\\(D\\)" "forwprop1" } } */