public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4311] tree-optimization/103356 Add missing (~a) == b folding for _Bool Date: Sat, 26 Nov 2022 18:00:59 +0000 (GMT) [thread overview] Message-ID: <20221126180059.921773858C52@sourceware.org> (raw) https://gcc.gnu.org/g:f9378e3cc390f9bcc310ce206c6773a817aff2ca commit r13-4311-gf9378e3cc390f9bcc310ce206c6773a817aff2ca Author: Andrew Pinski <apinski@marvell.com> Date: Sat Nov 26 07:37:40 2022 +0000 tree-optimization/103356 Add missing (~a) == b folding for _Bool 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. Diff: --- gcc/match.pd | 7 +++++++ gcc/testsuite/gcc.dg/pr103356-1.c | 9 +++++++++ 2 files changed, 16 insertions(+) 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" } } */
reply other threads:[~2022-11-26 18:00 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=20221126180059.921773858C52@sourceware.org \ --to=pinskia@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: linkBe 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).