From: Richard Biener <richard.guenther@gmail.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: "Hurugalawadi, Naveen" <Naveen.Hurugalawadi@caviumnetworks.com>
Subject: Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
Date: Tue, 07 Jul 2015 09:35:00 -0000 [thread overview]
Message-ID: <CAFiYyc07MCwT9NF_OQTE92KG0Rf+3Oex_muSRTx7Ji9TF99Jag@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1507071121510.1875@laptop-mg.saclay.inria.fr>
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
next prev parent reply other threads:[~2015-07-07 9:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-07 4:52 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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFiYyc07MCwT9NF_OQTE92KG0Rf+3Oex_muSRTx7Ji9TF99Jag@mail.gmail.com \
--to=richard.guenther@gmail.com \
--cc=Naveen.Hurugalawadi@caviumnetworks.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).