This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: match.pd: Optimize (x | y) & ~(x & y) and (x | y) & (~x ^ y)
- From: Richard Biener <rguenther at suse dot de>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Marc Glisse <marc dot glisse at inria dot fr>
- Date: Fri, 26 Jun 2015 11:28:17 +0200 (CEST)
- Subject: Re: match.pd: Optimize (x | y) & ~(x & y) and (x | y) & (~x ^ y)
- Authentication-results: sourceware.org; auth=none
- References: <20150626075918 dot GC10139 at redhat dot com>
On Fri, 26 Jun 2015, Marek Polacek wrote:
> The following patch adds optimizing of
> (x | y) & ~(x & y)
> and
> (x | y) & (~x ^ y)
> to a single operation.
>
> No +/-/* in those, so I think we don't have to worry about saturating types
> this time around.
>
> For some reason I had to use more :c's in the latter pattern than usual.
Yeah, I double-checked and indeed you can't remove any there.
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
Ok. (I suppose you always check whether the patterns are in fold-const.c
and remove them there if you spot them)
Thanks,
Richard.
> 2015-06-26 Marek Polacek <polacek@redhat.com>
>
> * match.pd ((x | y) & ~(x & y) -> x ^ y,
> (x | y) & (~x ^ y) -> x & y): New patterns.
>
> * gcc.dg/fold-and-1.c: New test.
> * gcc.dg/fold-and-2.c: New test.
>
> diff --git gcc/match.pd gcc/match.pd
> index 292ce6d..f242c99 100644
> --- gcc/match.pd
> +++ gcc/match.pd
> @@ -367,6 +367,16 @@ along with GCC; see the file COPYING3. If not see
> (minus (bit_ior @0 @1) (bit_and @0 @1))
> (bit_xor @0 @1))
>
> +/* (x | y) & ~(x & y) -> x ^ y */
> +(simplify
> + (bit_and:c (bit_ior @0 @1) (bit_not (bit_and @0 @1)))
> + (bit_xor @0 @1))
> +
> +/* (x | y) & (~x ^ y) -> x & y */
> +(simplify
> + (bit_and:c (bit_ior:c @0 @1) (bit_xor:c @1 (bit_not @0)))
> + (bit_and @0 @1))
> +
> (simplify
> (abs (negate @0))
> (abs @0))
> diff --git gcc/testsuite/gcc.dg/fold-and-1.c gcc/testsuite/gcc.dg/fold-and-1.c
> index e69de29..d555bb4 100644
> --- gcc/testsuite/gcc.dg/fold-and-1.c
> +++ gcc/testsuite/gcc.dg/fold-and-1.c
> @@ -0,0 +1,70 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-cddce1" } */
> +
> +int
> +fn1 (int x, int y)
> +{
> + int tem1 = x | y;
> + int tem2 = ~(x & y);
> + return tem1 & tem2;
> +}
> +
> +int
> +fn2 (int x, int y)
> +{
> + int tem1 = y | x;
> + int tem2 = ~(x & y);
> + return tem1 & tem2;
> +}
> +
> +int
> +fn3 (int x, int y)
> +{
> + int tem1 = x | y;
> + int tem2 = ~(y & x);
> + return tem1 & tem2;
> +}
> +
> +int
> +fn4 (int x, int y)
> +{
> + int tem1 = y | x;
> + int tem2 = ~(y & x);
> + return tem1 & tem2;
> +}
> +
> +int
> +fn5 (int x, int y)
> +{
> + int tem1 = ~(x & y);
> + int tem2 = x | y;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn6 (int x, int y)
> +{
> + int tem1 = ~(x & y);
> + int tem2 = y | x;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn7 (int x, int y)
> +{
> + int tem1 = ~(y & x);
> + int tem2 = x | y;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn8 (int x, int y)
> +{
> + int tem1 = ~(y & x);
> + int tem2 = y | x;
> + return tem1 & tem2;
> +}
> +
> +/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */
> +/* { dg-final { scan-tree-dump-not " \\& " "cddce1" } } */
> +/* { dg-final { scan-tree-dump-not "~" "cddce1" } } */
> diff --git gcc/testsuite/gcc.dg/fold-and-2.c gcc/testsuite/gcc.dg/fold-and-2.c
> index e69de29..3df2a0b 100644
> --- gcc/testsuite/gcc.dg/fold-and-2.c
> +++ gcc/testsuite/gcc.dg/fold-and-2.c
> @@ -0,0 +1,70 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-cddce1" } */
> +
> +int
> +fn1 (int x, int y)
> +{
> + int tem1 = x | y;
> + int tem2 = ~x ^ y;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn2 (int x, int y)
> +{
> + int tem1 = y | x;
> + int tem2 = ~x ^ y;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn3 (int x, int y)
> +{
> + int tem1 = x | y;
> + int tem2 = y ^ ~x;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn4 (int x, int y)
> +{
> + int tem1 = y | x;
> + int tem2 = y ^ ~x;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn5 (int x, int y)
> +{
> + int tem1 = ~x ^ y;
> + int tem2 = x | y;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn6 (int x, int y)
> +{
> + int tem1 = ~x ^ y;
> + int tem2 = y | x;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn7 (int x, int y)
> +{
> + int tem1 = y ^ ~x;
> + int tem2 = x | y;
> + return tem1 & tem2;
> +}
> +
> +int
> +fn8 (int x, int y)
> +{
> + int tem1 = y ^ ~x;
> + int tem2 = y | x;
> + return tem1 & tem2;
> +}
> +
> +/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */
> +/* { dg-final { scan-tree-dump-not " \\^ " "cddce1" } } */
> +/* { dg-final { scan-tree-dump-not "~" "cddce1" } } */
>
> Marek
>
>
--
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Dilip Upmanyu, Graham Norton, HRB 21284 (AG Nuernberg)