public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1779] tree-optimization/106379 - add missing ~(a ^ b) folding for _Bool
Date: Thu, 21 Jul 2022 11:24:10 +0000 (GMT)	[thread overview]
Message-ID: <20220721112410.3552E3856099@sourceware.org> (raw)

https://gcc.gnu.org/g:375668e0508fbe173af1ed519d8ae2b79f388d94

commit r13-1779-g375668e0508fbe173af1ed519d8ae2b79f388d94
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jul 21 13:20:47 2022 +0200

    tree-optimization/106379 - add missing ~(a ^ b) folding for _Bool
    
    The following makes sure to fold ~(a ^ b) to a == b for truth
    values (but not vectors, we'd have to check for vector support of
    equality).  That turns the PR106379 testcase into a ranger one.
    
    Note that while we arrive at ~(a ^ b) in a convoluted way from
    original !a == !b one can eventually write the expression this
    way directly as well.
    
            PR tree-optimization/106379
            * match.pd (~(a ^ b) -> a == b): New pattern.
    
            * gcc.dg/pr106379-1.c: New testcase.

Diff:
---
 gcc/match.pd                      | 6 ++++++
 gcc/testsuite/gcc.dg/pr106379-1.c | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 8bbc0dbd5cd..88a1a5aa9cc 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1938,6 +1938,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
   (bit_not (bit_xor (view_convert @0) @1))))
 
+/* ~(a ^ b) is a == b for truth valued a and b.  */
+(simplify
+ (bit_not (bit_xor:s truth_valued_p@0 truth_valued_p@1))
+ (if (!VECTOR_TYPE_P (type))
+  (convert (eq @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/pr106379-1.c b/gcc/testsuite/gcc.dg/pr106379-1.c
new file mode 100644
index 00000000000..7f2575e02dc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr106379-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" } } */


                 reply	other threads:[~2022-07-21 11:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220721112410.3552E3856099@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).