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: Richard Biener <richard dot guenther at gmail dot com>
- To: "Hurugalawadi, Naveen" <Naveen dot Hurugalawadi at caviumnetworks dot com>
- Cc: Marc Glisse <marc dot glisse at inria dot fr>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 20 Oct 2015 14:06:40 +0200
- 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> <CAFiYyc1yG0xPACvMMHn1oar+MgOE_qER3aFgZNr9KuDeaavoLQ at mail dot gmail dot com> <SN2PR0701MB10249F42F47E03257133DAF78E3F0 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <alpine dot DEB dot 2 dot 20 dot 1510140733470 dot 1981 at laptop-mg dot saclay dot inria dot fr> <CAFiYyc0GqkXkbqAEAh5_ivgGHQb2YNzRukmGduio-dHp7RbQjQ at mail dot gmail dot com> <alpine dot DEB dot 2 dot 20 dot 1510141240330 dot 2509 at laptop-mg dot saclay dot inria dot fr> <CAFiYyc3sS46khXFpZLetingTYuN5=2fu3N76+oErNShsRH3dvA at mail dot gmail dot com> <alpine dot DEB dot 2 dot 20 dot 1510141334440 dot 2509 at laptop-mg dot saclay dot inria dot fr> <SN2PR0701MB1024DCB71D27D1879DE3A7C48E3E0 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <CAFiYyc17b4BO5GDVxodzNfoztV0Gvdy6pdpJfW2dR+8xh0aK1Q at mail dot gmail dot com> <SN2PR0701MB10241785BE597A8D3D648B8C8E3D0 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <alpine dot DEB dot 2 dot 20 dot 1510161238370 dot 7951 at laptop-mg dot saclay dot inria dot fr> <SN2PR0701MB1024F6EA47AF604FFDAF58258E3A0 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com> <alpine dot DEB dot 2 dot 20 dot 1510191323001 dot 11872 at laptop-mg dot saclay dot inria dot fr> <SN2PR0701MB1024B0A9DCDCA6C3F71885518E390 at SN2PR0701MB1024 dot namprd07 dot prod dot outlook dot com>
On Tue, Oct 20, 2015 at 8:46 AM, Hurugalawadi, Naveen
<Naveen.Hurugalawadi@caviumnetworks.com> wrote:
> Hi,
>
>>> +/* Fold X + (X / CST) * -CST to X % CST. */
>>> This one is still wrong
> Removed.
>
>>> I don't understand the point of the FLOAT_TYPE_P check.
> The check was there in fold-const. So, just had the same check.
>
>>> Will we also simplify (A & B) - (A & ~B) into B - (A ^ B) ?
> Done.
>
>>> or maybe integer_all_onesp (const_binop (BIT_XOR_EXPR, type, @2, @1))
> Done.
>
>>> :c on bit_ior? It should also allow you to merge the 2 CST versions into one.
> Had it. But due to the error on "logical_inverted_value"; confused it with
> this pattern and had duplicated it.
>
>>> I am not really in favor of the indentation change (or the comment).
> Done.
>
>>> This patch is ok when bootstrapped / tested and with a proper changelog entry.
> Regression tested on X86_64 with no extra failures.
+(simplify
+ (minus (bit_and:s @0 INTEGER_CST@2) (bit_and:s @0 INTEGER_CST@1))
+ (if (integer_all_onesp (const_binop (BIT_XOR_EXPR, type, @2, @1)))
+ (minus (bit_xor @0 @1) @1)))
use if (wi::bit_and (@2, @1) == 0)
and instead of the 2nd group
+/* Fold (A & B) - (A & ~B) into B - (A ^ B). */
+(simplify
+ (minus (bit_and:s @0 @1) (bit_and:s @0 (bit_not @1)))
+ (minus @1 (bit_xor @0 @1)))
+(simplify
+ (minus (bit_and:s @0 INTEGER_CST@1) (bit_and:s @0 INTEGER_CST@2))
+ (if (integer_all_onesp (const_binop (BIT_XOR_EXPR, type, @2, @1)))
+ (minus @1 (bit_xor @0 @1))))
place a :c on the minus of the one not matching INTEGER_CSTs.
+(simplify
+ (bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1))
+ (if (integer_all_onesp (const_binop (BIT_XOR_EXPR, type, @2, @1)))
+ (bit_xor @0 @1)))
see above, use wi::bit_and instead
Otherwise looks ok to me.
RIchard.
> 2015-10-20 Richard Biener <rguenther@suse.de>
> Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
>
> * fold-const.c (fold_binary_loc) : Move (-A) * (-B) -> A * B
> to match.pd.
> Move (a * (1 << b)) is (a << b) to match.pd.
> Move convert (C1/X)*C2 into (C1*C2)/X to match.pd.
> Move ~X & X, (X == 0) & X, and !X & X are zero to match.pd.
> Move X & ~X , X & (X == 0), and X & !X are zero to match.pd.
>
> * match.pd (mult:c @0 (convert? (lshift integer_onep@1 @2))):
> New simplifier.
> (mult (rdiv:s REAL_CST@0 @1) REAL_CST@2): New simplifier.
> (bit_and:c (convert? @0) (convert? (bit_not @0))): New simplifier.
> (bit_ior (bit_and:s @0 (bit_not:s @1)) (bit_and:s (bit_not:s @0) @1))
> : New simplifier.
> (mult:c (convert1? (negate @0)) (convert2? negate_expr_p@1)):
> New simplifier.
> (match (logical_inverted_value @0) (truth_not @0)) : New Predicate.
>
>
>
> 2015-10-20 Richard Biener <rguenther@suse.de>
> Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
>
> * fold-const.c (fold_binary_loc) : Move Fold (A & ~B) - (A & B)
> into (A ^ B) - B to match.pd
> Move (X & ~Y) | (~X & Y) is X ^ Y to match.pd.
>
> * match.pd (minus (bit_and:s @0 (bit_not @1)) (bit_and:s @0 @1)):
> New simplifier.
> (minus (bit_and:s @0 INTEGER_CST@2) (bit_and:s @0 INTEGER_CST@1)):
> New simplifier.
> (minus (bit_and:s @0 @1) (bit_and:s @0 (bit_not @1))): New simplifier.
> (minus (bit_and:s @0 INTEGER_CST@1) (bit_and:s @0 INTEGER_CST@2)):
> New simplifier.
> (bit_ior:c (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1)):
> New simplifier.
> (bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1)):
> New simplifier.