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: Marc Glisse <marc dot glisse at inria dot fr>
- To: "Hurugalawadi, Naveen" <Naveen dot Hurugalawadi at caviumnetworks dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 7 Jul 2015 08:06:32 +0200 (CEST)
- 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>
- Reply-to: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
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