This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Multiply Optimization in match and Simplify
- From: Richard Biener <richard dot guenther at gmail dot com>
- 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>, "marc dot glisse at inria dot fr" <marc dot glisse at inria dot fr>
- Date: Tue, 3 Nov 2015 16:42:25 +0100
- Subject: Re: Multiply Optimization in match and Simplify
- Authentication-results: sourceware.org; auth=none
- References: <SN2PR0701MB102448CA48B5A9C045EDBBAE8E200 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <CAFiYyc1ZsiVhgeEOSCdkbXr+HuXLNbL6MkfJxe=ZRFhyk9eQdA at mail dot gmail dot com> <SN2PR0701MB1024ECA99F5DB02BD227CBE08E2B0 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com>
On Tue, Nov 3, 2015 at 6:12 AM, Hurugalawadi, Naveen
<Naveen.Hurugalawadi@caviumnetworks.com> wrote:
> Hi,
>
> Thanks for the review and suggestions.
>
>>> Please do not drop A - B -> A + (-B) from fold-const as match.pd
>>> doesn't implement all of fold-const.c negate_expr_p support.
>
> Done.
>
>>> which is more expensive. This means that we miss a
>>> (bit_and (bit_not @0) INTEGER_CST@1)
>
> Should we have this pattern implemented in match.pd?
I think so. Please combine with
+/* Fold X & (X ^ Y) as X & ~Y. */
+(simplify
+ (bit_and:c (convert? @0) (convert? (bit_xor:c @0 @1)))
+ (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
+ (convert (bit_and @0 (bit_not @1)))))
>>> negate_expr_p doesn't capture everything
>>> fold-const.c does so moving the above isn't a good idea.
>
> Dropped the pattern. Was working on some more patterns
> that had negate_expr_p. Will drop all of them.
>
>>> fold-const.c only handles constant C, so we only need to 2nd pattern.
>
> Yeah. Thought that even having variable would be optimized in a similar
> manner and hence had that pattern.
+/* Convert (A + A) * C -> A * 2 * C. */
+(simplify
+ (mult (convert? (plus @0 @0)) INTEGER_CST@1)
+ (mult (convert @0) (mult { build_int_cst (TREE_TYPE (@1), 2); } @1)))
so you dropped the nop-conversion check but not the converts ... This should
now simply match
(mult (plus @0 @0) INTEGER_CST@1)
but I'd rather (as Marc pointed out) enable the
/* Convert x+x into x*2.0. */
(simplify
(plus @0 @0)
(if (SCALAR_FLOAT_TYPE_P (type))
(mult @0 { build_real (type, dconst2); })))
pattern also for integral types. That should make the pattern redundant
(and the fold code can be removed anyway). Like with
@@ -1606,7 +1619,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(simplify
(plus @0 @0)
(if (SCALAR_FLOAT_TYPE_P (type))
- (mult @0 { build_real (type, dconst2); })))
+ (mult @0 { build_real (type, dconst2); })
+ (if (INTEGRAL_TYPE_P (type))
+ (mult @0 { build_int_cst (type, 2); }))))
(simplify
(minus integer_zerop @1)
Richard.
> Please find attached the modified pattern as per suggestions.
> Please review the patch and let me know if there should be any further
> modifications in it.
>
> Thanks,
> Naveen