public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Eric Botcazou <ebotcazou@adacore.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [RFC] optimize x - y cmp 0 with undefined overflow
Date: Fri, 06 Jun 2014 15:45:00 -0000	[thread overview]
Message-ID: <CAFiYyc09D-ikg0j9aOqkP3kvrjwFMaob-2q_XnbjAzixrggwuQ@mail.gmail.com> (raw)
In-Reply-To: <2380818.KtDek0hH5m@polaris>

On Fri, Jun 6, 2014 at 12:52 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> So when computing a range for z in
>>
>>  z = y - x;
>>
>> with x = [-INF, y - 1] and y = [x + 1, +INF] (deduced from !(x >= y)) we
>> fail to do sth sensible with [y, y] - [-INF, y - 1] or [x + 1, +INF] - [x,
>> x] but we do sth with [x + 1, +INF] - [-INF, x]?  That seems odd to me.
>>
>> With the patch we compute z to [1, +INF(OVF)]
>
> Right, and note the overflow.
>
>> Going the [x + 1, +INF] - [x,x] path first we obtain
>>
>>   [1, -x + INF]
>>
>> which fails the sanity checking
>>
>>   cmp = compare_values (min, max);
>>   if (cmp == -2 || cmp == 1)
>>     {
>>       /* If the new range has its limits swapped around (MIN > MAX),
>>          then the operation caused one of them to wrap around, mark
>>          the new range VARYING.  */
>>       set_value_range_to_varying (vr);
>>     }
>>   else
>>     set_value_range (vr, type, min, max, NULL);
>>
>> but clearly the same reasoning you can apply that makes trying
>> with [-INF, x] valid (it's just enlarging the range) can be applied
>> here, too, when computing +INF - x for the upper bound.  We can
>> safely increase that to +INF making the range valid for the above
>> test.
>
> I don't think we can enlarge to +INF because -x + INF can overflow, we can
> only enlarge to +INF(OVF).
>
>> But I wonder what code path in the routine still relies on that sanity
>> checking to produce a valid result (so I'd rather try removing it, or
>> taking uncomparable bounds as a valid range).
>>
>> Simplest would be to simply do
>>
>>           set_value_range (vr, type, min, max, NULL);
>>           return;
>>
>> and be done with that in the plus/minus handling.  With that the
>> testcase optimizes ok for me.
>
> 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.

Thanks,
Richard.

> --
> Eric Botcazou

  reply	other threads:[~2014-06-06 15:45 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 [this message]
2014-06-20  9:40                       ` Eric Botcazou
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=CAFiYyc09D-ikg0j9aOqkP3kvrjwFMaob-2q_XnbjAzixrggwuQ@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).