public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
@ 2015-07-07  4:52 Hurugalawadi, Naveen
  2015-07-07  6:06 ` Marc Glisse
  0 siblings, 1 reply; 13+ messages in thread
From: Hurugalawadi, Naveen @ 2015-07-07  4:52 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 576 bytes --]

Hi,

Please find attached the patch "PR25529.patch" that converts the pattern:-
(unsigned * 2)/2 is into unsigned &0x7FFFFFFF

Please review and let me know if its okay.

Regression tested on AARH64 and x86_64.

Thanks,
Naveen

gcc/testsuite/ChangeLog:

2015-07-07  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

	PR middle-end/25529
	* gcc.dg/pr25529.c: New test.

gcc/ChangeLog:

2015-07-07  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

	PR middle-end/25529
	* match.pd (div (mult @0 INTEGER_CST@1) INTEGER_CST@1) : 
	New simplifier.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: PR25529.patch --]
[-- Type: text/x-patch; name="PR25529.patch", Size: 1003 bytes --]

--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -529,6 +529,16 @@ along with GCC; see the file COPYING3.  If not see
   (bitop (bit_and:c @0 @1) (bit_and @2 @1))
   (bit_and (bitop @0 @2) @1)))
 
+/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
+(for div (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+  (div (mult @0 INTEGER_CST@1) INTEGER_CST@1)
+  (with { tree n2 = build_int_cst (TREE_TYPE (@0),
+				   wi::exact_log2 (@1)); }
+  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+   (bit_and @0 (rshift (lshift { build_minus_one_cst (TREE_TYPE (@0)); }
+			       { n2; }) { n2; }))))))
+
 /* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
 (simplify
   (bit_and (bit_ior @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)

--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr25529.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+f1 (unsigned t)
+{
+  return (t * 2) / 2;
+}
+
+/* { dg-final { scan-tree-dump "\& 2147483647" "optimized" } } */

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-07-07  4:52 [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF) Hurugalawadi, Naveen
@ 2015-07-07  6:06 ` Marc Glisse
  2015-07-07  9:12   ` Richard Biener
  0 siblings, 1 reply; 13+ messages in thread
From: Marc Glisse @ 2015-07-07  6:06 UTC (permalink / raw)
  To: Hurugalawadi, Naveen; +Cc: gcc-patches

On Tue, 7 Jul 2015, Hurugalawadi, Naveen wrote:

> Please find attached the patch "PR25529.patch" that converts the pattern:-
> (unsigned * 2)/2 is into unsigned &0x7FFFFFFF

+/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
+(for div (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+  (div (mult @0 INTEGER_CST@1) INTEGER_CST@1)

You don't need to repeat INTEGER_CST, the second time @1 is enough.

+  (with { tree n2 = build_int_cst (TREE_TYPE (@0),
+				   wi::exact_log2 (@1)); }
+  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+   (bit_and @0 (rshift (lshift { build_minus_one_cst (TREE_TYPE (@0)); }
+			       { n2; }) { n2; }))))))

What happens if you write t*3/3?

-- 
Marc Glisse

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-07-07  6:06 ` Marc Glisse
@ 2015-07-07  9:12   ` Richard Biener
  2015-07-07  9:24     ` Marc Glisse
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Biener @ 2015-07-07  9:12 UTC (permalink / raw)
  To: gcc-patches; +Cc: Hurugalawadi, Naveen

On Tue, Jul 7, 2015 at 8:06 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Tue, 7 Jul 2015, Hurugalawadi, Naveen wrote:
>
>> Please find attached the patch "PR25529.patch" that converts the pattern:-
>> (unsigned * 2)/2 is into unsigned &0x7FFFFFFF
>
>
> +/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
> +(for div (trunc_div ceil_div floor_div round_div exact_div)
> + (simplify
> +  (div (mult @0 INTEGER_CST@1) INTEGER_CST@1)
>
> You don't need to repeat INTEGER_CST, the second time @1 is enough.
>
> +  (with { tree n2 = build_int_cst (TREE_TYPE (@0),
> +                                  wi::exact_log2 (@1)); }
> +  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
> +   (bit_and @0 (rshift (lshift { build_minus_one_cst (TREE_TYPE (@0)); }
> +                              { n2; }) { n2; }))))))
>
> What happens if you write t*3/3?

Huh, and you posted this patch twice?  See my reply to the other copy
for the correctness issues and better handling of exact_div

Richard.

> --
> Marc Glisse

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-07-07  9:12   ` Richard Biener
@ 2015-07-07  9:24     ` Marc Glisse
  2015-07-07  9:35       ` Richard Biener
  0 siblings, 1 reply; 13+ messages in thread
From: Marc Glisse @ 2015-07-07  9:24 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, Hurugalawadi, Naveen

On Tue, 7 Jul 2015, Richard Biener wrote:

> On Tue, Jul 7, 2015 at 8:06 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
>> On Tue, 7 Jul 2015, Hurugalawadi, Naveen wrote:
>>
>>> Please find attached the patch "PR25529.patch" that converts the pattern:-
>>> (unsigned * 2)/2 is into unsigned &0x7FFFFFFF
>>
>>
>> +/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
>> +(for div (trunc_div ceil_div floor_div round_div exact_div)
>> + (simplify
>> +  (div (mult @0 INTEGER_CST@1) INTEGER_CST@1)
>>
>> You don't need to repeat INTEGER_CST, the second time @1 is enough.
>>
>> +  (with { tree n2 = build_int_cst (TREE_TYPE (@0),
>> +                                  wi::exact_log2 (@1)); }
>> +  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
>> +   (bit_and @0 (rshift (lshift { build_minus_one_cst (TREE_TYPE (@0)); }
>> +                              { n2; }) { n2; }))))))
>>
>> What happens if you write t*3/3?
>
> Huh, and you posted this patch twice?  See my reply to the other copy
> for the correctness issues and better handling of exact_div

They are not the same, one is for left shifts and the other one for right 
shifts. And that makes a big difference: in t*c/c, the division is always 
exact, so all divisions are equivalent. This is not the case for t/c*c.

-- 
Marc Glisse

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-07-07  9:24     ` Marc Glisse
@ 2015-07-07  9:35       ` Richard Biener
  2015-07-21  9:16         ` Hurugalawadi, Naveen
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Biener @ 2015-07-07  9:35 UTC (permalink / raw)
  To: GCC Patches; +Cc: Hurugalawadi, Naveen

On Tue, Jul 7, 2015 at 11:24 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Tue, 7 Jul 2015, Richard Biener wrote:
>
>> On Tue, Jul 7, 2015 at 8:06 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
>>>
>>> On Tue, 7 Jul 2015, Hurugalawadi, Naveen wrote:
>>>
>>>> Please find attached the patch "PR25529.patch" that converts the
>>>> pattern:-
>>>> (unsigned * 2)/2 is into unsigned &0x7FFFFFFF
>>>
>>>
>>>
>>> +/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
>>> +(for div (trunc_div ceil_div floor_div round_div exact_div)
>>> + (simplify
>>> +  (div (mult @0 INTEGER_CST@1) INTEGER_CST@1)
>>>
>>> You don't need to repeat INTEGER_CST, the second time @1 is enough.
>>>
>>> +  (with { tree n2 = build_int_cst (TREE_TYPE (@0),
>>> +                                  wi::exact_log2 (@1)); }
>>> +  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
>>> +   (bit_and @0 (rshift (lshift { build_minus_one_cst (TREE_TYPE (@0)); }
>>> +                              { n2; }) { n2; }))))))
>>>
>>> What happens if you write t*3/3?
>>
>>
>> Huh, and you posted this patch twice?  See my reply to the other copy
>> for the correctness issues and better handling of exact_div
>
>
> They are not the same, one is for left shifts and the other one for right
> shifts. And that makes a big difference: in t*c/c, the division is always
> exact, so all divisions are equivalent. This is not the case for t/c*c.

Ah, sorry.  Still the same comment for computing the constant and
placing of the 'with' applies.  For signed types with TYPE_OVERFLOW_UNDEFINED
you can simply cancel the operation (even for non-power-of-two multipliers).
In fold-const.c extract_muldiv contains magic to handle this kind of cases.
Otherwise for signed division (only the sign of the division matters, so you
can probably ignore sign-changing conversions of the multiplication result)
you can simplify it to a sign-extension from bit precision - log2 with
the proposed introduction of a SEXT_EXPR (see other thread about
type promotion).

Richard.

> --
> Marc Glisse

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-07-07  9:35       ` Richard Biener
@ 2015-07-21  9:16         ` Hurugalawadi, Naveen
  2015-07-22 12:10           ` Richard Biener
  0 siblings, 1 reply; 13+ messages in thread
From: Hurugalawadi, Naveen @ 2015-07-21  9:16 UTC (permalink / raw)
  To: Richard Biener; +Cc: marc.glisse, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 772 bytes --]

Hi,

>> For signed types with TYPE_OVERFLOW_UNDEFINED
>> you can simply cancel the operation (even for non-power-of-two multipliers).

Thanks for the review and comments.

Please find attached the modified patch as per your comments.

Please review the same and let me know if any further modifications are required.

Regression Tested on X86_64.

Thanks,
Naveen

gcc/testsuite/ChangeLog:

2015-07-21  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

	PR middle-end/25529
	* gcc.dg/pr25529.c: New test.

gcc/ChangeLog:

2015-07-21  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

	PR middle-end/25529
	* match.pd (exact_div (mult @0 INTEGER_CST@1) @1) : 	New simplifier.
	(trunc_div (mult @0 integer_pow2p@1) @1) : New simplifier.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr25529.patch --]
[-- Type: text/x-patch; name="pr25529.patch", Size: 1047 bytes --]

--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -280,6 +280,20 @@ along with GCC; see the file COPYING3.  If not see
 	&& integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0)
    (bit_and @0 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))))
 
+/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
+(simplify
+ (exact_div (mult @0 INTEGER_CST@1) @1)
+ (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
+  @0))
+
+(simplify
+ (trunc_div (mult @0 integer_pow2p@1) @1)
+ (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (with { tree n2 = build_int_cst (TREE_TYPE (@0),
+				  wi::exact_log2 (@1)); }
+  (bit_and @0 (rshift (lshift { build_minus_one_cst (TREE_TYPE (@0)); }
+				{ n2; }) { n2; })))))
+
 /* X % Y is smaller than Y.  */
 (for cmp (lt ge)
  (simplify
new file mode 100644
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr25529.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+f1 (unsigned t)
+{
+  return (t * 2) / 2;
+}
+
+/* { dg-final { scan-tree-dump "\& 2147483647" "optimized" } } */

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-07-21  9:16         ` Hurugalawadi, Naveen
@ 2015-07-22 12:10           ` Richard Biener
  2015-07-23  3:59             ` Hurugalawadi, Naveen
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Biener @ 2015-07-22 12:10 UTC (permalink / raw)
  To: Hurugalawadi, Naveen; +Cc: marc.glisse, GCC Patches

On Tue, Jul 21, 2015 at 11:16 AM, Hurugalawadi, Naveen
<Naveen.Hurugalawadi@caviumnetworks.com> wrote:
> Hi,
>
>>> For signed types with TYPE_OVERFLOW_UNDEFINED
>>> you can simply cancel the operation (even for non-power-of-two multipliers).
>
> Thanks for the review and comments.
>
> Please find attached the modified patch as per your comments.
>
> Please review the same and let me know if any further modifications are required.
>
> Regression Tested on X86_64.

@@ -280,6 +280,20 @@ along with GCC; see the file COPYING3.  If not see
        && integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0)
    (bit_and @0 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))))

+/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
+(simplify
+ (exact_div (mult @0 INTEGER_CST@1) @1)
+ (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
+  @0))

The comment applies to the pattern below and the pattern above lacks a comment

+(simplify
+ (trunc_div (mult @0 integer_pow2p@1) @1)
+ (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+ (with { tree n2 = build_int_cst (TREE_TYPE (@0),
+                                 wi::exact_log2 (@1)); }
+  (bit_and @0 (rshift (lshift { build_minus_one_cst (TREE_TYPE (@0)); }
+                               { n2; }) { n2; })))))

please use

  (with
    {
      int n2 = wi::exact_log2 (@1);
      tree mask = wide_int_to_tree (type, wi::rshift (wi::lshift (-1, n2), n2));
    }
   (bit_and @0 { mask; }))))

in fact, the -1 << log2 >> log2 looks like it does wi::mask
(TYPE_PRECISION (type) - wi::exact_log2 (@1), false, TYPE_PRECISION
(type));
so using wi::mask is prefered here.

Thanks,
Richard.


> Thanks,
> Naveen
>
> gcc/testsuite/ChangeLog:
>
> 2015-07-21  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>
>
>         PR middle-end/25529
>         * gcc.dg/pr25529.c: New test.
>
> gcc/ChangeLog:
>
> 2015-07-21  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>
>
>         PR middle-end/25529
>         * match.pd (exact_div (mult @0 INTEGER_CST@1) @1) :     New simplifier.
>         (trunc_div (mult @0 integer_pow2p@1) @1) : New simplifier.

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-07-22 12:10           ` Richard Biener
@ 2015-07-23  3:59             ` Hurugalawadi, Naveen
  2015-07-23 13:36               ` Richard Biener
  0 siblings, 1 reply; 13+ messages in thread
From: Hurugalawadi, Naveen @ 2015-07-23  3:59 UTC (permalink / raw)
  To: Richard Biener; +Cc: marc.glisse, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 576 bytes --]

>> so using wi::mask is prefered here.

Thanks for your review and comments.

Please find attached the modified patch as per your comments.

Please let me know if this version is okay?

Thanks,
Naveen

2015-07-22  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

gcc/testsuite/ChangeLog:
         PR middle-end/25529
         * gcc.dg/pr25529.c: New test.

gcc/ChangeLog:
         PR middle-end/25529
         * match.pd (exact_div (mult @0 INTEGER_CST@1) @1) :     New simplifier.
         (trunc_div (mult @0 integer_pow2p@1) @1) : New simplifier.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr25529.patch --]
[-- Type: text/x-patch; name="pr25529.patch", Size: 1518 bytes --]

diff --git a/gcc/match.pd b/gcc/match.pd
index 9a66f52..9c8080f 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -29,7 +29,8 @@ along with GCC; see the file COPYING3.  If not see
    integer_each_onep integer_truep
    real_zerop real_onep real_minus_onep
    CONSTANT_CLASS_P
-   tree_expr_nonnegative_p)
+   tree_expr_nonnegative_p
+   integer_pow2p)
 
 /* Operator lists.  */
 (define_operator_list tcc_comparison
@@ -280,6 +281,20 @@ along with GCC; see the file COPYING3.  If not see
 	&& integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0)
    (bit_and @0 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))))
 
+/* Simplify (t * 2)/2 ->  t.  */
+(simplify
+ (exact_div (mult @0 INTEGER_CST@1) @1)
+ (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
+  @0))
+
+/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF.  */
+(simplify
+ (trunc_div (mult @0 integer_pow2p@1) @1)
+ (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
+  (bit_and @0 { wide_int_to_tree
+		(type, wi::mask (TYPE_PRECISION (type) - wi::exact_log2 (@1),
+				 false, TYPE_PRECISION (type))); })))
+
 /* X % Y is smaller than Y.  */
 (for cmp (lt ge)
  (simplify
diff --git a/gcc/testsuite/gcc.dg/pr25529.c b/gcc/testsuite/gcc.dg/pr25529.c
new file mode 100644
index 0000000..4d9fe9e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr25529.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int
+f (unsigned t)
+{
+  return (t * 2) / 2;
+}
+
+/* { dg-final { scan-tree-dump "\& 2147483647" "optimized" } } */

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-07-23  3:59             ` Hurugalawadi, Naveen
@ 2015-07-23 13:36               ` Richard Biener
  2015-08-07  8:44                 ` Hurugalawadi, Naveen
  0 siblings, 1 reply; 13+ messages in thread
From: Richard Biener @ 2015-07-23 13:36 UTC (permalink / raw)
  To: Hurugalawadi, Naveen; +Cc: marc.glisse, GCC Patches

On Thu, Jul 23, 2015 at 5:47 AM, Hurugalawadi, Naveen
<Naveen.Hurugalawadi@caviumnetworks.com> wrote:
>>> so using wi::mask is prefered here.
>
> Thanks for your review and comments.
>
> Please find attached the modified patch as per your comments.
>
> Please let me know if this version is okay?

Ok with adding

/* { dg-require-effective-target int32 } */

to the testcase.

Please omit the

+/* Simplify (t * 2)/2 ->  t.  */
+(simplify
+ (exact_div (mult @0 INTEGER_CST@1) @1)
+ (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
+  @0))

pattern.  As a followup extend it - it shoudl also work for non-INTEGER_CST
divisors and it should work for any kind of division, not just exact_div.  The
key here is TYPE_OVERFLOW_UNDEFINED.  I believe you should
find the equivalent operation in extract_trunc_div_1.

Richard.

> Thanks,
> Naveen
>
> 2015-07-22  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>
>
> gcc/testsuite/ChangeLog:
>          PR middle-end/25529
>          * gcc.dg/pr25529.c: New test.
>
> gcc/ChangeLog:
>          PR middle-end/25529
>          * match.pd (exact_div (mult @0 INTEGER_CST@1) @1) :     New simplifier.
>          (trunc_div (mult @0 integer_pow2p@1) @1) : New simplifier.

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-07-23 13:36               ` Richard Biener
@ 2015-08-07  8:44                 ` Hurugalawadi, Naveen
  2015-08-11 12:50                   ` Richard Biener
  2015-08-20 20:10                   ` H.J. Lu
  0 siblings, 2 replies; 13+ messages in thread
From: Hurugalawadi, Naveen @ 2015-08-07  8:44 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

Hi,  

>> extend it - it should also work for non-INTEGER_CST
>> divisors and it should work for any kind of division, not just exact_div.  

Please find attached the patch "pr25529.patch" that implements the pattern
for all divisors

Please review and let me know if its okay.  

Regression tested on AARH64 and x86_64.

Thanks,
Naveen  

2015-08-07  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

PR middle-end/25529 

	gcc/ChangeLog:  
	* match.pd (div (mult @0 @1) @1) : New simplifier.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr25529.patch --]
[-- Type: text/x-patch; name="pr25529.patch", Size: 511 bytes --]

diff --git a/gcc/match.pd b/gcc/match.pd
index 4230f9a..18045b8 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -296,6 +296,13 @@ along with GCC; see the file COPYING3.  If not see
  (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
   (bit_and @0 (negate @1))))
 
+/* Simplify (t * 2) / 2) -> t.  */
+(for div (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+  (div (mult @0 @1) @1)
+  (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
+   @0)))
+
 /* X % Y is smaller than Y.  */
 (for cmp (lt ge)
  (simplify

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-08-07  8:44                 ` Hurugalawadi, Naveen
@ 2015-08-11 12:50                   ` Richard Biener
  2015-08-11 12:51                     ` Richard Biener
  2015-08-20 20:10                   ` H.J. Lu
  1 sibling, 1 reply; 13+ messages in thread
From: Richard Biener @ 2015-08-11 12:50 UTC (permalink / raw)
  To: Hurugalawadi, Naveen; +Cc: gcc-patches

On Fri, Aug 7, 2015 at 10:43 AM, Hurugalawadi, Naveen
<Naveen.Hurugalawadi@caviumnetworks.com> wrote:
> Hi,
>
>>> extend it - it should also work for non-INTEGER_CST
>>> divisors and it should work for any kind of division, not just exact_div.
>
> Please find attached the patch "pr25529.patch" that implements the pattern
> for all divisors
>
> Please review and let me know if its okay.

Ok.

Thanks,
Richard.

> Regression tested on AARH64 and x86_64.
>
> Thanks,
> Naveen
>
> 2015-08-07  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>
>
> PR middle-end/25529
>
>         gcc/ChangeLog:
>         * match.pd (div (mult @0 @1) @1) : New simplifier.
>

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-08-11 12:50                   ` Richard Biener
@ 2015-08-11 12:51                     ` Richard Biener
  0 siblings, 0 replies; 13+ messages in thread
From: Richard Biener @ 2015-08-11 12:51 UTC (permalink / raw)
  To: Hurugalawadi, Naveen; +Cc: gcc-patches

On Tue, Aug 11, 2015 at 2:50 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Fri, Aug 7, 2015 at 10:43 AM, Hurugalawadi, Naveen
> <Naveen.Hurugalawadi@caviumnetworks.com> wrote:
>> Hi,
>>
>>>> extend it - it should also work for non-INTEGER_CST
>>>> divisors and it should work for any kind of division, not just exact_div.
>>
>> Please find attached the patch "pr25529.patch" that implements the pattern
>> for all divisors
>>
>> Please review and let me know if its okay.
>
> Ok.

Err, sorry.  You are missing a

 ANY_INTEGRAL_TYPE_P (type)

before the TYPE_OVERFLOW_UNDEFINED check which should simply
operate on 'type' rather than TREE_TYPE (@0).

Ok with that changes.

Richard.

> Thanks,
> Richard.
>
>> Regression tested on AARH64 and x86_64.
>>
>> Thanks,
>> Naveen
>>
>> 2015-08-07  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>
>>
>> PR middle-end/25529
>>
>>         gcc/ChangeLog:
>>         * match.pd (div (mult @0 @1) @1) : New simplifier.
>>

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

* Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
  2015-08-07  8:44                 ` Hurugalawadi, Naveen
  2015-08-11 12:50                   ` Richard Biener
@ 2015-08-20 20:10                   ` H.J. Lu
  1 sibling, 0 replies; 13+ messages in thread
From: H.J. Lu @ 2015-08-20 20:10 UTC (permalink / raw)
  To: Hurugalawadi, Naveen; +Cc: Richard Biener, gcc-patches

On Fri, Aug 7, 2015 at 1:43 AM, Hurugalawadi, Naveen
<Naveen.Hurugalawadi@caviumnetworks.com> wrote:
> Hi,
>
>>> extend it - it should also work for non-INTEGER_CST
>>> divisors and it should work for any kind of division, not just exact_div.
>
> Please find attached the patch "pr25529.patch" that implements the pattern
> for all divisors
>
> Please review and let me know if its okay.
>
> Regression tested on AARH64 and x86_64.
>
> Thanks,
> Naveen
>
> 2015-08-07  Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>
>
> PR middle-end/25529
>
>         gcc/ChangeLog:
>         * match.pd (div (mult @0 @1) @1) : New simplifier.
>

This caused:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67298

-- 
H.J.

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

end of thread, other threads:[~2015-08-20 19:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-07  4:52 [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF) Hurugalawadi, Naveen
2015-07-07  6:06 ` Marc Glisse
2015-07-07  9:12   ` Richard Biener
2015-07-07  9:24     ` Marc Glisse
2015-07-07  9:35       ` Richard Biener
2015-07-21  9:16         ` Hurugalawadi, Naveen
2015-07-22 12:10           ` Richard Biener
2015-07-23  3:59             ` Hurugalawadi, Naveen
2015-07-23 13:36               ` Richard Biener
2015-08-07  8:44                 ` Hurugalawadi, Naveen
2015-08-11 12:50                   ` Richard Biener
2015-08-11 12:51                     ` Richard Biener
2015-08-20 20:10                   ` H.J. Lu

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).