public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marc Glisse <marc.glisse@inria.fr>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, richard.sandiford@arm.com
Subject: Re: Fold pointer range checks with equal spans
Date: Tue, 31 Jul 2018 20:53:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.21.1807312141380.12599@stedding.saclay.inria.fr> (raw)
In-Reply-To: <CAFiYyc3ev_7WgA-sYukkH18rNoW5V=Vekt0tOifRrGkm169TWw@mail.gmail.com>

On Tue, 31 Jul 2018, Richard Biener wrote:

>>> Also, when @2 == @0 + (@1+1) then the original condition is true but
>>> ((sizetype) @0 - (sizetype) @2 + @1) > (@1 * 2) is not?
>>>    (sizetype) @0 - (sizetype) (@0 + @1 + 1) + @1 > @1 * 2
>>> -> -1 > @1 * 2
>>>
>>> which is false.  So I can't really see how you can apply this transform in
>>> general (it would be fine for generating alias checks but a bit more
>>> pessimistic).
>>>
>>> But maybe I am missing something?
>>
>> It relies on sizetype being unsigned: (sizetype)-1 > @1 * 2 is true.
>
> Hmm, so mathematically this is
>
>  (@0 - @2) % modreduce + @1 > @1 * 2
>
> then, but I don't want to think too much about this since Marc didn't
> object here ;)

We already transform abs(x)<=3 into (unsigned)x+3u<=6u, that's the usual
way we do range checking so I didn't pay much attention to that part.
(tempted to say: "I didn't want to think too much about this since
Richard was going to do it anyway" ;-)

Turning multiple comparisons of the form P + cst CMP Q + cst into a
range check on P - Q sounds good (we don't really have to restrict to
the case where the range is symmetric). Actually, just turning P + cst
CMP Q + cst into P - Q CMP cst should do it, we should already have code
to handle range checking on integers (modulo the issue of CSE P-Q and
Q-P). But I don't know if a couple :s is sufficient to make this
transformation a good canonicalization.

If we start from a comparison of pointer_plus, I think it would make
sense to use pointer_diff.

I believe currently we try to use pointer operations (pointer_plus,
pointer_diff, lt) only for related pointers and we cast to some integer
type for wilder cases (implementation of std::less in C++ for instance).
On the other hand, in an alias check, the 2 pointers are possibly
unrelated, so maybe the code emitted for an alias check should be
changed.

-- 
Marc Glisse

  reply	other threads:[~2018-07-31 20:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-20 10:27 Richard Sandiford
2018-07-20 12:11 ` Marc Glisse
2018-07-23 15:04   ` Richard Sandiford
2018-07-25  9:07     ` Richard Biener
2018-07-30 17:47       ` Richard Sandiford
2018-07-31 10:55         ` Richard Biener
2018-07-31 20:53           ` Marc Glisse [this message]
2018-08-01 10:59             ` Richard Sandiford
2018-08-01 12:18               ` Marc Glisse
2018-08-01 10:25           ` Richard Sandiford
2018-08-01 11:59             ` 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.21.1807312141380.12599@stedding.saclay.inria.fr \
    --to=marc.glisse@inria.fr \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    --cc=richard.sandiford@arm.com \
    /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).