This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Optimize (CST1 << A) == CST2 (PR tree-optimization/66299)
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Marc Glisse <marc dot glisse at inria dot fr>
- Cc: Marek Polacek <polacek at redhat dot com>, Jakub Jelinek <jakub at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <rguenther at suse dot de>
- Date: Tue, 9 Jun 2015 09:53:21 +0200
- Subject: Re: [PATCH] Optimize (CST1 << A) == CST2 (PR tree-optimization/66299)
- Authentication-results: sourceware.org; auth=none
- References: <20150528121545 dot GE27320 at redhat dot com> <20150528123436 dot GM10247 at tucnak dot redhat dot com> <alpine dot DEB dot 2 dot 11 dot 1505282124310 dot 2177 at laptop-mg dot saclay dot inria dot fr> <20150608151055 dot GR2756 at redhat dot com> <alpine dot DEB dot 2 dot 20 dot 1506081901550 dot 28961 at stedding dot saclay dot inria dot fr>
On Mon, Jun 8, 2015 at 7:03 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Mon, 8 Jun 2015, Marek Polacek wrote:
>
>> PR tree-optimization/66299
>> * match.pd ((CST1 << A) == CST2 -> A == ctz (CST2) - ctz (CST1)
>> ((CST1 << A) != CST2 -> A != ctz (CST2) - ctz (CST1)): New
>
>
> You are braver than I am, I would have abbreviated ctz (CST2) - ctz (CST1)
> to CST3 in the ChangeLog ;-)
>
>> +/* (CST1 << A) == CST2 -> A == ctz (CST2) - ctz (CST1)
>> + (CST1 << A) != CST2 -> A != ctz (CST2) - ctz (CST1)
>> + if CST2 != 0. */
>> +(for cmp (ne eq)
>> + (simplify
>> + (cmp (lshift INTEGER_CST@0 @1) INTEGER_CST@2)
>> + (with {
>> + unsigned int cand = wi::ctz (@2) - wi::ctz (@0); }
>> + (if (!integer_zerop (@2)
>
>
> You can probably use directly wi::ne_p (@2, 0) here. Shouldn't this be
> indented one space more?
Yes, one space more. I suppose using integer_zerop might in theory
allow for handling vector shifts at some point ...?
>> + && wi::eq_p (wi::lshift (@0, cand), @2))
>> + (cmp @1 { build_int_cst (TREE_TYPE (@1), cand); })))))
>
>
> Making 'cand' signed, you could return 0 when cand<0, like (2<<x)==1. You
> could also return 0 when the candidate turns out not to work: (3<<x)==4.
Sounds like a good improvement.
> Tweaking it so that (6<<X)==0 becomes X>=31 for TYPE_OVERFLOW_WRAPS and
> false for TYPE_OVERFLOW_UNDEFINED is probably more controversial.
Hm, yes. I think signed overflow != shift amount overflow, so testing
the overflow
macros for this isn't valid.
Otherwise the patch looks ok to me as well - mind doing the improvement above?
Thanks,
Richard.
> FWIW, the patch looks good to me, thanks.
>
> --
> Marc Glisse