This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: "Hurugalawadi, Naveen" <Naveen dot Hurugalawadi at caviumnetworks dot com>
- Cc: "marc dot glisse at inria dot fr" <marc dot glisse at inria dot fr>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 22 Jul 2015 13:54:52 +0200
- Subject: Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF)
- Authentication-results: sourceware.org; auth=none
- References: <SN2PR0701MB1024267AF107C82E4F2F8A6C8E920 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <alpine dot DEB dot 2 dot 20 dot 1507070800550 dot 1693 at laptop-mg dot saclay dot inria dot fr> <CAFiYyc1c_NVr1eKVg3v5xv4829aMDbp0QnrmeB-BEYCmg6uQ+A at mail dot gmail dot com> <alpine dot DEB dot 2 dot 20 dot 1507071121510 dot 1875 at laptop-mg dot saclay dot inria dot fr> <CAFiYyc07MCwT9NF_OQTE92KG0Rf+3Oex_muSRTx7Ji9TF99Jag at mail dot gmail dot com> <DM2PR0701MB1018959170F8B70E4C982C628E840 at DM2PR0701MB1018 dot namprd07 dot prod dot outlook dot com>
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.