* [PATCH] tree-optimization/103356 Add missing (~a) == b folding for _Bool
@ 2022-11-26 16:41 apinski
2022-11-26 17:49 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: apinski @ 2022-11-26 16:41 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
From: Andrew Pinski <apinski@marvell.com>
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 103356
gcc/ChangeLog:
* match.pd: ((~a) == b -> a ^ b): New pattern.
gcc/testsuite/ChangeLog:
* gcc.dg/pr103356-1.c: New test.
---
gcc/match.pd | 7 +++++++
gcc/testsuite/gcc.dg/pr103356-1.c | 9 +++++++++
2 files changed, 16 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/pr103356-1.c
diff --git a/gcc/match.pd b/gcc/match.pd
index a4d1386fd9f..67a0a682f31 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -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
index 00000000000..61d0b81da22
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103356-1.c
@@ -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" } } */
--
2.17.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tree-optimization/103356 Add missing (~a) == b folding for _Bool
2022-11-26 16:41 [PATCH] tree-optimization/103356 Add missing (~a) == b folding for _Bool apinski
@ 2022-11-26 17:49 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-11-26 17:49 UTC (permalink / raw)
To: apinski; +Cc: gcc-patches
> Am 26.11.2022 um 17:42 schrieb apinski--- via Gcc-patches <gcc-patches@gcc.gnu.org>:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> 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.
Ok.
Richard
> Thanks,
> Andrew Pinski
>
> PR 103356
>
> gcc/ChangeLog:
>
> * match.pd: ((~a) == b -> a ^ b): New pattern.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/pr103356-1.c: New test.
> ---
> gcc/match.pd | 7 +++++++
> gcc/testsuite/gcc.dg/pr103356-1.c | 9 +++++++++
> 2 files changed, 16 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/pr103356-1.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index a4d1386fd9f..67a0a682f31 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -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
> index 00000000000..61d0b81da22
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr103356-1.c
> @@ -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" } } */
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-26 17:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26 16:41 [PATCH] tree-optimization/103356 Add missing (~a) == b folding for _Bool apinski
2022-11-26 17:49 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).