From: Eric Botcazou <ebotcazou@adacore.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [RFC] optimize x - y cmp 0 with undefined overflow
Date: Fri, 20 Jun 2014 09:40:00 -0000 [thread overview]
Message-ID: <3415746.rtOLWSx8DO@polaris> (raw)
In-Reply-To: <CAFiYyc09D-ikg0j9aOqkP3kvrjwFMaob-2q_XnbjAzixrggwuQ@mail.gmail.com>
[I'm at last back to this...]
> > With [1, -x + INF] as the resulting range? But it can be bogus if x is
> > itself equal to +INF (unlike the input range [x + 1, +INF] which is
> > always correct)
>
> Hmm, indeed.
>
> > so this doesn't look valid to me. I don't see how we can get away
> > without a +INF(OVF) here, but I can compute it in
> > extract_range_from_binary_expr_1 if you prefer and try only [op0,op0]
> > and [op1,op1].
>
> Yeah, I'd prefer that.
To recap, the range of y is [x + 1, +INF] and we're trying to evaluate the
range of y - x, in particular we want to prove that y - x > 0.
We compute the range of y - x as [1, -x + INF] by combining [x + 1, +INF] with
[x, x] and we want to massage it because compare_values will rightly choke.
If overflow is undefined, we can simply change it to [1, +INF (OVF)] and be
done with that. But if overflow is defined, we need to prove that -x + INF
cannot wrap around (which is true if the type is unsigned) and the simplest
way to do that in the general case is to recursively invoke the machinery
of extract_range_from_binary_expr_1 on range_of(-x) + INF and analyze the
result. This looks much more complicated implementation-wise (and would very
likely buy us nothing in practice) than my scheme, where we just approximate
range_of(-x) by [-INF,+INF] and don't need to implement the recursion at all.
However I can change extract_range_from_binary_expr so that only one range
among [-INF,x], [x,+INF] and [x,x] is tried instead of the 3 ranges in a row.
I initially didn't want to do that because this breaks the separation between
extract_range_from_binary_expr_1 and extract_range_from_binary_expr but, given
their names, this is very likely acceptable. What do you think?
--
Eric Botcazou
next prev parent reply other threads:[~2014-06-20 9:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-26 10:24 Eric Botcazou
2014-05-26 12:55 ` Richard Biener
2014-05-27 9:26 ` Eric Botcazou
2014-05-27 9:42 ` Richard Biener
2014-05-27 10:00 ` Eric Botcazou
2014-05-27 10:12 ` Richard Biener
2014-05-30 8:49 ` Eric Botcazou
2014-06-02 10:36 ` Richard Biener
2014-06-02 10:37 ` Richard Biener
2014-06-03 8:13 ` Eric Botcazou
2014-06-03 11:00 ` Richard Biener
2014-06-06 10:54 ` Eric Botcazou
2014-06-06 15:45 ` Richard Biener
2014-06-20 9:40 ` Eric Botcazou [this message]
2014-06-24 10:34 ` Richard Biener
2014-09-29 23:01 ` Eric Botcazou
2014-05-27 16:14 ` Eric Botcazou
2014-05-27 16:19 ` 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=3415746.rtOLWSx8DO@polaris \
--to=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.guenther@gmail.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).