diff mbox

[GSoC,match-and-simplify] mark some more operators as commutative

Message ID CAJXstsBYTSyE9gQQv0bMQPFJz=MjJUWhRG4U4JnOfv_0__uORA@mail.gmail.com
State New
Headers show

Commit Message

Prathamesh Kulkarni June 23, 2014, 1:32 p.m. UTC
* match.pd: Mark operators in some bitwise and plus-minus
patterns to be commutative.

Thanks and Regards,
Prathamesh

Comments

Richard Biener June 23, 2014, 2:10 p.m. UTC | #1
On Mon, Jun 23, 2014 at 3:32 PM, Prathamesh Kulkarni
<bilbotheelffriend@gmail.com> wrote:
> * match.pd: Mark operators in some bitwise and plus-minus
> patterns to be commutative.

 /* A - (A +- B) -> -+ B */
 (match_and_simplify
-  (minus @0 (plus @0 @1))
+  (minus @0 (plus:c @0 @1))
   (negate @0))

seems pointless

 /* ~x & ~y -> ~(x | y) */
 (match_and_simplify
-  (bit_and (bit_not @0) (bit_not @1))
+  (bit_and:c (bit_not @0) (bit_not @1))
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   (bit_not (bit_ior @0 @1)))

likewise.

I have removed the pointless ones and committed the patch.

Richard.

> Thanks and Regards,
> Prathamesh
Marc Glisse June 23, 2014, 2:23 p.m. UTC | #2
On Mon, 23 Jun 2014, Richard Biener wrote:

> On Mon, Jun 23, 2014 at 3:32 PM, Prathamesh Kulkarni
> <bilbotheelffriend@gmail.com> wrote:
>> * match.pd: Mark operators in some bitwise and plus-minus
>> patterns to be commutative.
>
> /* A - (A +- B) -> -+ B */
> (match_and_simplify
> -  (minus @0 (plus @0 @1))
> +  (minus @0 (plus:c @0 @1))
>   (negate @0))
>
> seems pointless

Why? a-(a+b) and a-(b+a) are both wanted and don't appear elsewhere in the 
file, no? Should simplify to (negate @1) though.
Richard Biener June 23, 2014, 2:38 p.m. UTC | #3
On Mon, Jun 23, 2014 at 4:23 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Mon, 23 Jun 2014, Richard Biener wrote:
>
>> On Mon, Jun 23, 2014 at 3:32 PM, Prathamesh Kulkarni
>> <bilbotheelffriend@gmail.com> wrote:
>>>
>>> * match.pd: Mark operators in some bitwise and plus-minus
>>> patterns to be commutative.
>>
>>
>> /* A - (A +- B) -> -+ B */
>> (match_and_simplify
>> -  (minus @0 (plus @0 @1))
>> +  (minus @0 (plus:c @0 @1))
>>   (negate @0))
>>
>> seems pointless
>
>
> Why? a-(a+b) and a-(b+a) are both wanted and don't appear elsewhere in the
> file, no? Should simplify to (negate @1) though.

Ah, indeed.  So here commutation doesn't work because of correctness.

Richard.

> --
> Marc Glisse
Richard Biener June 23, 2014, 4:41 p.m. UTC | #4
On Mon, Jun 23, 2014 at 4:38 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Mon, Jun 23, 2014 at 4:23 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
>> On Mon, 23 Jun 2014, Richard Biener wrote:
>>
>>> On Mon, Jun 23, 2014 at 3:32 PM, Prathamesh Kulkarni
>>> <bilbotheelffriend@gmail.com> wrote:
>>>>
>>>> * match.pd: Mark operators in some bitwise and plus-minus
>>>> patterns to be commutative.
>>>
>>>
>>> /* A - (A +- B) -> -+ B */
>>> (match_and_simplify
>>> -  (minus @0 (plus @0 @1))
>>> +  (minus @0 (plus:c @0 @1))
>>>   (negate @0))
>>>
>>> seems pointless
>>
>>
>> Why? a-(a+b) and a-(b+a) are both wanted and don't appear elsewhere in the
>> file, no? Should simplify to (negate @1) though.
>
> Ah, indeed.  So here commutation doesn't work because of correctness.

Or rather the pattern is broken from the start ... fixed.

Richard.

> Richard.
>
>> --
>> Marc Glisse
diff mbox

Patch

Index: gcc/match.pd
===================================================================
--- gcc/match.pd	(revision 211893)
+++ gcc/match.pd	(working copy)
@@ -138,7 +138,7 @@  along with GCC; see the file COPYING3.
   (minus (plus @0 @1) @1)
   @0)
 (match_and_simplify
-  (plus (minus @0 @1) @1)
+  (plus:c (minus @0 @1) @1)
   @0)
 /* (CST +- A) +- CST -> CST' +- A.  */
 /* match_and_simplify handles constant folding for us so we can
@@ -176,7 +176,7 @@  along with GCC; see the file COPYING3.
 
 /* A - (A +- B) -> -+ B */
 (match_and_simplify
-  (minus @0 (plus @0 @1))
+  (minus @0 (plus:c @0 @1))
   (negate @0))
 
 (match_and_simplify
@@ -285,25 +285,25 @@  along with GCC; see the file COPYING3.
 
 /* x & ~x -> 0 */
 (match_and_simplify
-  (bit_and @0 (bit_not @0))
+  (bit_and:c @0 (bit_not @0))
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   { build_int_cst (type, 0); })
 
 /* ~x & ~y -> ~(x | y) */
 (match_and_simplify
-  (bit_and (bit_not @0) (bit_not @1))
+  (bit_and:c (bit_not @0) (bit_not @1))
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   (bit_not (bit_ior @0 @1)))
 
 /* ~x | ~y -> ~(x & y) */
 (match_and_simplify
-  (bit_ior (bit_not @0) (bit_not @1))
+  (bit_ior:c (bit_not @0) (bit_not @1))
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   (bit_not (bit_and @0 @1)))
 
 /* x & (~x | y) -> y & x */
 (match_and_simplify
-  (bit_and @0 (bit_ior (bit_not @0) @1))
+  (bit_and:c @0 (bit_ior:c (bit_not @0) @1))
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   (bit_and @1 @0))
 
@@ -320,25 +320,25 @@  along with GCC; see the file COPYING3.
 
 /* (x | y) & x -> x */
 (match_and_simplify
-  (bit_and (bit_ior @0 @1) @0)
+  (bit_and:c (bit_ior:c @0 @1) @0)
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   @0)
 
 /* (x & y) | x -> x */
 (match_and_simplify
-  (bit_ior (bit_and @0 @1) @0)
+  (bit_ior:c (bit_and:c @0 @1) @0)
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   @0)
 
 /* (~x | y) & x -> x & y */
 (match_and_simplify
-  (bit_and (bit_ior (bit_not @0) @1) @0)
+  (bit_and:c (bit_ior:c (bit_not @0) @1) @0)
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   (bit_and @0 @1))
 
 /* (~x & y) | x -> x | y */
 (match_and_simplify
-  (bit_ior (bit_and (bit_not @0) @1) @0)
+  (bit_ior:c (bit_and:c (bit_not @0) @1) @0)
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   (bit_ior @0 @1))
 
@@ -350,7 +350,7 @@  along with GCC; see the file COPYING3.
 
 /* ((a & b) & ~a) -> 0 */
 (match_and_simplify
-  (bit_and (bit_and @0 @1) (bit_not @0))
+  (bit_and:c (bit_and:c @0 @1) (bit_not @0))
   if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
   { build_int_cst (type, 0); })