From: Marc Glisse <marc.glisse@inria.fr>
To: Marek Polacek <polacek@redhat.com>
Cc: 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: Mon, 08 Jun 2015 17:14:00 -0000 [thread overview]
Message-ID: <alpine.DEB.2.20.1506081901550.28961@stedding.saclay.inria.fr> (raw)
In-Reply-To: <20150608151055.GR2756@redhat.com>
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?
> + && 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.
Tweaking it so that (6<<X)==0 becomes X>=31 for TYPE_OVERFLOW_WRAPS and
false for TYPE_OVERFLOW_UNDEFINED is probably more controversial.
FWIW, the patch looks good to me, thanks.
--
Marc Glisse
next prev parent reply other threads:[~2015-06-08 17:03 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 [this message]
2015-06-09 7:56 ` Richard Biener
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=alpine.DEB.2.20.1506081901550.28961@stedding.saclay.inria.fr \
--to=marc.glisse@inria.fr \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--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).