This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Division Optimization in match and simplify
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: "Hurugalawadi, Naveen" <Naveen dot Hurugalawadi at caviumnetworks dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 6 Nov 2015 08:37:40 +0100 (CET)
- Subject: Re: Division Optimization in match and simplify
- Authentication-results: sourceware.org; auth=none
- References: <BLUPR0701MB10112FDAF6046909BE252FFB8E2A0 at BLUPR0701MB1011 dot namprd07 dot prod dot outlook dot com> <alpine dot DEB dot 2 dot 20 dot 1511040920400 dot 2317 at laptop-mg dot saclay dot inria dot fr> <BLUPR0701MB10110152D9B362818EB337668E2A0 at BLUPR0701MB1011 dot namprd07 dot prod dot outlook dot com> <alpine dot DEB dot 2 dot 20 dot 1511041155570 dot 2317 at laptop-mg dot saclay dot inria dot fr>,<CAFiYyc172oRzH6H8dNP0E5mbEcN5GVGF1ujoWtUvDUV0TBQkcw at mail dot gmail dot com> <SN2PR0701MB102426084E1A305896CB1D6A8E290 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com>,<alpine dot DEB dot 2 dot 20 dot 1511050652430 dot 2037 at laptop-mg dot saclay dot inria dot fr> <SN2PR0701MB10249706A57ED2C5EFA7EA7C8E280 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com>
- Reply-to: gcc-patches at gcc dot gnu dot org
+/* Optimize (X & (-A)) / A where A is a power of 2, to X >> log2(A) */
+(for div (trunc_div ceil_div floor_div round_div exact_div)
+ (simplify
+ (div (convert? (bit_and @0 INTEGER_CST@1)) INTEGER_CST@2)
+ (if (!TYPE_UNSIGNED (type) && integer_pow2p (@2)
+ && tree_int_cst_sgn (@2) > 0
+ && wi::add (@2, @1) == 0
+ && tree_nop_conversion_p (type, TREE_TYPE (@0)))
+ (rshift (convert @0) { build_int_cst (integer_type_node,
+ wi::exact_log2 (@2)); }))))
Sorry, I must be very unclear when I write :-(
I indeed like tree_int_cst_sgn (@2) > 0 better than looking at the sign
bit, but I don't know why you re-introduced !TYPE_UNSIGNED (type) at the
same time. The whole reason I prefer tree_int_cst_sgn is that it also
applies when type is unsigned and @2 is 2^31.
--
Marc Glisse