diff mbox

[PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)

Message ID SN2PR0701MB1024C09A0E0C1C2885ABBEE68E730@SN2PR0701MB1024.namprd07.prod.outlook.com
State New
Headers show

Commit Message

Hurugalawadi, Naveen Aug. 7, 2015, 8:43 a.m. UTC
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.

Comments

Richard Biener Aug. 11, 2015, 12:50 p.m. UTC | #1
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.
>
Richard Biener Aug. 11, 2015, 12:51 p.m. UTC | #2
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.
>>
H.J. Lu Aug. 20, 2015, 7:26 p.m. UTC | #3
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
diff mbox

Patch

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