From: Richard Biener <richard.guenther@gmail.com>
To: Marc Glisse <marc.glisse@inria.fr>
Cc: Marek Polacek <polacek@redhat.com>,
Jakub Jelinek <jakub@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>,
Richard Biener <rguenther@suse.de>
Subject: Re: [PATCH] Optimize (CST1 << A) == CST2 (PR tree-optimization/66299)
Date: Tue, 09 Jun 2015 07:56:00 -0000 [thread overview]
Message-ID: <CAFiYyc2vfBzHGHQEkvRujiE2z-brW4J3P0R+TyjQuy44PZj0-A@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1506081901550.28961@stedding.saclay.inria.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
next prev parent reply other threads:[~2015-06-09 7:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-28 12:33 Marek Polacek
2015-05-28 13:10 ` Jakub Jelinek
2015-05-28 20:33 ` Marc Glisse
2015-06-08 15:12 ` Marek Polacek
2015-06-08 17:14 ` Marc Glisse
2015-06-09 7:56 ` Richard Biener [this message]
2015-06-09 11:46 ` Marc Glisse
2015-06-09 11:49 ` Richard Biener
2015-06-09 11:57 ` Richard Biener
2015-06-09 12:13 ` Marc Glisse
2015-06-09 12:22 ` Richard Biener
2015-06-09 13:46 ` Marek Polacek
2015-06-09 14:11 ` Richard Biener
2015-05-28 13:16 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFiYyc2vfBzHGHQEkvRujiE2z-brW4J3P0R+TyjQuy44PZj0-A@mail.gmail.com \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=marc.glisse@inria.fr \
--cc=polacek@redhat.com \
--cc=rguenther@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).