public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "MCC CS" <mcccs@gmx.com>
To: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Optimize more boolean functions
Date: Mon, 27 Aug 2018 15:31:00 -0000	[thread overview]
Message-ID: <trinity-6cb20b7e-e9aa-4a98-bcb3-f57f5351b663-1535383853209@3c-app-mailcom-bs04> (raw)
In-Reply-To: <CAFiYyc1dz+pdP4Zo0Th1HTpa63PCP+i=KrfF9rsmf-xmo_z_vw@mail.gmail.com>

Added :s to the second pattern, updated dates. Thank you so much for
your reviews!


2018-08-27 MCC CS <deswurstes@users.noreply.github.com>

	gcc/
	PR tree-optimization/87009
	* match.pd: Add boolean optimizations.

2018-08-27 MCC CS <deswurstes@users.noreply.github.com>

	gcc/testsuite/
	PR tree-optimization/87009
	* gcc.dg/pr87009.c: New test.

Index: gcc/match.pd
===================================================================
--- gcc/match.pd (revision 263646)
+++ gcc/match.pd (working copy)
@@ -776,6 +776,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(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)))
+
/* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */
#if GIMPLE
(simplify
@@ -981,6 +986,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(bit_and:c (bit_ior:c @0 @1) (bit_xor:c @1 (bit_not @0)))
(bit_and @0 @1))

+/* (~x | y) & (x | ~y) -> ~(x ^ y) */
+(simplify
+ (bit_and (bit_ior:cs (bit_not @0) @1) (bit_ior:cs @0 (bit_not @1)))
+ (bit_not (bit_xor @0 @1)))
+
+/* (~x | y) ^ (x | ~y) -> x ^ y */
+(simplify
+ (bit_xor (bit_ior:c (bit_not @0) @1) (bit_ior:c @0 (bit_not @1)))
+ (bit_xor @0 @1))
+
/* ~x & ~y -> ~(x | y)
~x | ~y -> ~(x & y) */
(for op (bit_and bit_ior)
Index: gcc/testsuite/gcc.dg/pr87009.c
===================================================================
--- gcc/testsuite/gcc.dg/pr87009.c (nonexistent)
+++ gcc/testsuite/gcc.dg/pr87009.c (working copy)
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-original" } */
+/* { dg-final { scan-tree-dump-times "return s \\^ x;" 4 "original" } } */
+
+int f1 (int x, int s)
+{
+ return ~(~(x|s)|x)|~(~(x|s)|s);
+}
+
+int f2 (int x, int s)
+{
+ return ~(~(~x&s)&~(x&~s));
+}
+
+int f3 (int x, int s)
+{
+ return ~((x|~s)&(~x|s));
+}
+
+int f4 (int x, int s)
+{
+ return (x|~s)^(~x|s);
+}

  reply	other threads:[~2018-08-27 15:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-20 15:07 MCC CS
2018-08-20 17:38 ` Marc Glisse
2018-08-21 17:20   ` MCC CS
2018-08-27 10:05     ` Richard Biener
2018-08-27 11:52       ` Marc Glisse
2018-08-27 15:16         ` Richard Biener
2018-08-27 15:31           ` MCC CS [this message]
2018-08-27  8:53 MCC CS
2018-08-28 15:34 MCC CS
2018-08-28 20:24 ` Jeff Law

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=trinity-6cb20b7e-e9aa-4a98-bcb3-f57f5351b663-1535383853209@3c-app-mailcom-bs04 \
    --to=mcccs@gmx.com \
    --cc=gcc-patches@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).