This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Move some bit and binary optimizations in simplify and match
- 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: Mon, 12 Oct 2015 14:49:52 +0200 (CEST)
- Subject: Re: Move some bit and binary optimizations in simplify and match
- Authentication-results: sourceware.org; auth=none
- References: <SN2PR0701MB10242B9E56933B072C29DE698E360 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com>,<CAFiYyc0hiJX=Q6q9b4cNBnNXaKWKPkk3tb4gaBZr_m-gU9OjCA at mail dot gmail dot com> <SN2PR0701MB10245F3B91BE5291AD40C1848E310 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com>
- Reply-to: gcc-patches at gcc dot gnu dot org
On Mon, 12 Oct 2015, Hurugalawadi, Naveen wrote:
+/* Fold X + (X / CST) * -CST to X % CST. */
+(simplify
+ (plus (convert1? @0) (convert2? (mult (trunc_div @0 INTEGER_CST@1) INTEGER_CST@2)))
+ (if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
+ && wi::add (@1, @2) == 0)
+ (trunc_mod (convert @0) (convert @1))))
With INTEGER_CST above, the test INTEGRAL_TYPE_P might be redundant, and
VECTOR_INTEGER_TYPE_P can never match.
+/* Fold (A & ~B) - (A & B) into (A ^ B) - B. */
+(simplify
+ (minus (bit_and:s @0 (bit_not @1)) (bit_and:s @0 @2))
+ (if (! FLOAT_TYPE_P (type)
+ && wi::eq_p (@1, @2))
+ (minus (bit_xor @0 @1) @1)))
I don't think FLOAT_TYPE_P can ever be true for the result of bit_and.
+/* Fold (a * (1 << b)) into (a << b) */
+(simplify
+ (mult:c (convert1? @0) (convert2? (lshift integer_onep@1 @2)))
+ (if (! FLOAT_TYPE_P (type))
+ (lshift (convert @0) (convert @2))))
If a and 1 are vectors and b is a scalar...
+/* Simplify (X & ~Y) | (~X & Y) is X ^ Y. */
+(simplify
+ (bit_ior (bit_and:s @0 (bit_not @1)) (bit_and:s (bit_not @2) @3))
+ (if (wi::eq_p (@0, @2)
+ && wi::eq_p (@1, @3))
+ (bit_xor @0 @3)))
I don't think we need the :s when the result of the transformation is so
simple.
+/* Simplify ~X & X as zero. */
+(simplify
+ (bit_and:c (convert? @0) (convert? (bit_not @0)))
+ (convert { build_zero_cst (TREE_TYPE (@0)); }))
Can't you build 0 directly in the right type?
--
Marc Glisse