public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* match.pd: (x | y) & ~x -> y & ~x
@ 2015-05-15 17:33 Marc Glisse
  2015-05-18 10:04 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Marc Glisse @ 2015-05-15 17:33 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 432 bytes --]

Hello,

we already have the more complicated: x & ~(x & y) -> x & ~y (which I am 
reindenting by the way) and the simpler: (~x | y) & x -> x & y, so I am 
proposing this one for completeness. Regtested on ppc64le-redhat-linux.

2015-05-15  Marc Glisse  <marc.glisse@inria.fr>

gcc/
 	* match.pd ((x | y) & ~x -> y & ~x, (x & y) | ~x -> y | ~x): New
 	simplifications.
gcc/testsuite/
 	* gcc.dg/nand.c: New testcase.

-- 
Marc Glisse

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1741 bytes --]

Index: match.pd
===================================================================
--- match.pd	(revision 223217)
+++ match.pd	(working copy)
@@ -257,24 +257,32 @@ along with GCC; see the file COPYING3.
 
 /* x + (x & 1) -> (x + 1) & ~1 */
 (simplify
  (plus:c @0 (bit_and@2 @0 integer_onep@1))
  (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
   (bit_and (plus @0 @1) (bit_not @1))))
 
 /* x & ~(x & y) -> x & ~y */
 /* x | ~(x | y) -> x | ~y  */
 (for bitop (bit_and bit_ior)
-  (simplify
-    (bitop:c @0 (bit_not (bitop:c@2 @0 @1)))
-      (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
-	(bitop @0 (bit_not @1)))))
+ (simplify
+  (bitop:c @0 (bit_not (bitop:c@2 @0 @1)))
+   (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
+    (bitop @0 (bit_not @1)))))
+
+/* (x | y) & ~x -> y & ~x */
+/* (x & y) | ~x -> y | ~x */
+(for bitop (bit_and bit_ior)
+     rbitop (bit_ior bit_and)
+ (simplify
+  (bitop:c (rbitop:c @0 @1) (bit_not@2 @0))
+  (bitop @1 @2)))
 
 (simplify
  (abs (negate @0))
  (abs @0))
 (simplify
  (abs tree_expr_nonnegative_p@0)
  @0)
 
 
 /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST))
Index: testsuite/gcc.dg/nand.c
===================================================================
--- testsuite/gcc.dg/nand.c	(revision 0)
+++ testsuite/gcc.dg/nand.c	(working copy)
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-original" } */
+
+unsigned f(unsigned x, unsigned y){
+  return (x | y) & ~x;
+}
+unsigned g(unsigned x, unsigned y){
+  return ~x & (y | x);
+}
+
+/* { dg-final { scan-tree-dump-times "return ~x & y;" 2 "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: match.pd: (x | y) & ~x -> y & ~x
  2015-05-15 17:33 match.pd: (x | y) & ~x -> y & ~x Marc Glisse
@ 2015-05-18 10:04 ` Richard Biener
  2015-05-22 21:24   ` Marc Glisse
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2015-05-18 10:04 UTC (permalink / raw)
  To: Marc Glisse; +Cc: GCC Patches

On Fri, May 15, 2015 at 7:22 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> Hello,
>
> we already have the more complicated: x & ~(x & y) -> x & ~y (which I am
> reindenting by the way) and the simpler: (~x | y) & x -> x & y, so I am
> proposing this one for completeness. Regtested on ppc64le-redhat-linux.

Ok (doesn't seem to be in fold-const.c).

Btw, there are quite some (simple) ones only in fold-const.c which are eligible
for moving to match.pd (thus remove them from fold-const.c and implement in
match.pd).  Mostly canonicalization ones though.

Richard.

> 2015-05-15  Marc Glisse  <marc.glisse@inria.fr>
>
> gcc/
>         * match.pd ((x | y) & ~x -> y & ~x, (x & y) | ~x -> y | ~x): New
>         simplifications.
> gcc/testsuite/
>         * gcc.dg/nand.c: New testcase.
>
> --
> Marc Glisse
> Index: match.pd
> ===================================================================
> --- match.pd    (revision 223217)
> +++ match.pd    (working copy)
> @@ -257,24 +257,32 @@ along with GCC; see the file COPYING3.
>
>  /* x + (x & 1) -> (x + 1) & ~1 */
>  (simplify
>   (plus:c @0 (bit_and@2 @0 integer_onep@1))
>   (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
>    (bit_and (plus @0 @1) (bit_not @1))))
>
>  /* x & ~(x & y) -> x & ~y */
>  /* x | ~(x | y) -> x | ~y  */
>  (for bitop (bit_and bit_ior)
> -  (simplify
> -    (bitop:c @0 (bit_not (bitop:c@2 @0 @1)))
> -      (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
> -       (bitop @0 (bit_not @1)))))
> + (simplify
> +  (bitop:c @0 (bit_not (bitop:c@2 @0 @1)))
> +   (if (TREE_CODE (@2) != SSA_NAME || has_single_use (@2))
> +    (bitop @0 (bit_not @1)))))
> +
> +/* (x | y) & ~x -> y & ~x */
> +/* (x & y) | ~x -> y | ~x */
> +(for bitop (bit_and bit_ior)
> +     rbitop (bit_ior bit_and)
> + (simplify
> +  (bitop:c (rbitop:c @0 @1) (bit_not@2 @0))
> +  (bitop @1 @2)))
>
>  (simplify
>   (abs (negate @0))
>   (abs @0))
>  (simplify
>   (abs tree_expr_nonnegative_p@0)
>   @0)
>
>
>  /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST))
> Index: testsuite/gcc.dg/nand.c
> ===================================================================
> --- testsuite/gcc.dg/nand.c     (revision 0)
> +++ testsuite/gcc.dg/nand.c     (working copy)
> @@ -0,0 +1,12 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-original" } */
> +
> +unsigned f(unsigned x, unsigned y){
> +  return (x | y) & ~x;
> +}
> +unsigned g(unsigned x, unsigned y){
> +  return ~x & (y | x);
> +}
> +
> +/* { dg-final { scan-tree-dump-times "return ~x & y;" 2 "original" } } */
> +/* { dg-final { cleanup-tree-dump "original" } } */
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: match.pd: (x | y) & ~x -> y & ~x
  2015-05-18 10:04 ` Richard Biener
@ 2015-05-22 21:24   ` Marc Glisse
  2015-05-23 10:47     ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Marc Glisse @ 2015-05-22 21:24 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches

On Mon, 18 May 2015, Richard Biener wrote:

> On Fri, May 15, 2015 at 7:22 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
>
>> we already have the more complicated: x & ~(x & y) -> x & ~y (which I am
>> reindenting by the way) and the simpler: (~x | y) & x -> x & y, so I am
>> proposing this one for completeness. Regtested on ppc64le-redhat-linux.
>
> Ok (doesn't seem to be in fold-const.c).
>
> Btw, there are quite some (simple) ones only in fold-const.c which are 
> eligible for moving to match.pd (thus remove them from fold-const.c and 
> implement in match.pd).  Mostly canonicalization ones though.

Haven't you already done a lot of those in the branch though?

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: match.pd: (x | y) & ~x -> y & ~x
  2015-05-22 21:24   ` Marc Glisse
@ 2015-05-23 10:47     ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2015-05-23 10:47 UTC (permalink / raw)
  To: GCC Patches, Marc Glisse

On May 22, 2015 10:54:02 PM GMT+02:00, Marc Glisse <marc.glisse@inria.fr> wrote:
>On Mon, 18 May 2015, Richard Biener wrote:
>
>> On Fri, May 15, 2015 at 7:22 PM, Marc Glisse <marc.glisse@inria.fr>
>wrote:
>>
>>> we already have the more complicated: x & ~(x & y) -> x & ~y (which
>I am
>>> reindenting by the way) and the simpler: (~x | y) & x -> x & y, so I
>am
>>> proposing this one for completeness. Regtested on
>ppc64le-redhat-linux.
>>
>> Ok (doesn't seem to be in fold-const.c).
>>
>> Btw, there are quite some (simple) ones only in fold-const.c which
>are 
>> eligible for moving to match.pd (thus remove them from fold-const.c
>and 
>> implement in match.pd).  Mostly canonicalization ones though.
>
>Haven't you already done a lot of those in the branch though?

Yeah, maybe.  I'd have to check.

Reminds me to come back to all this. After sorting out all the vectorizer stuff I am working on at the moment.

Richard.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-05-23  7:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-15 17:33 match.pd: (x | y) & ~x -> y & ~x Marc Glisse
2015-05-18 10:04 ` Richard Biener
2015-05-22 21:24   ` Marc Glisse
2015-05-23 10:47     ` 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).