Message ID | CAJXstsBYTSyE9gQQv0bMQPFJz=MjJUWhRG4U4JnOfv_0__uORA@mail.gmail.com |
---|---|
State | New |
Headers | show |
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
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.
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
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
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); })