public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Aldy Hernandez <aldyh@redhat.com>
To: Jeff Law <law@redhat.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>,
	Andrew MacLeod <amacleod@redhat.com>
Subject: Re: [patch] canonicalize unsigned [1,MAX] ranges into ~[0,0]
Date: Fri, 04 Oct 2019 15:49:00 -0000	[thread overview]
Message-ID: <74fb2cf8-6312-6ae2-b620-3d36deb61080@redhat.com> (raw)
In-Reply-To: <995b4560-6a76-6742-888f-eadbfb9ff9cc@redhat.com>



On 10/4/19 11:38 AM, Jeff Law wrote:
> On 10/4/19 6:59 AM, Aldy Hernandez wrote:
>> When I did the value_range canonicalization work, I noticed that an
>> unsigned [1,MAX] and an ~[0,0] could be two different representations
>> for the same thing.  I didn't address the problem then because callers
>> to ranges_from_anti_range() would go into an infinite loop trying to
>> extract ~[0,0] into [1,MAX] and [].  We had a lot of callers to
>> ranges_from_anti_range, and it smelled like a rat's nest, so I bailed.
>>
>> Now that we have one main caller (from the symbolic PLUS/MINUS
>> handling), it's a lot easier to contain.  Well, singleton_p also calls
>> it, but it's already handling nonzero specially, so it wouldn't be affected.
>>
>>
>> With some upcoming cleanups I'm about to post, the fact that [1,MAX] and
>> ~[0,0] are equal_p(), but not nonzero_p(), matters.  Plus, it's just
>> good form to have one representation, giving us the ability to pick at
>> nonzero_p ranges with ease.
>>
>> The code in extract_range_from_plus_minus_expr() continues to be a mess
>> (as it has always been), but at least it's contained, and with this
>> patch, it's slightly smaller.
>>
>> Note, I'm avoiding adding a comment header for functions with highly
>> descriptive obvious names.
>>
>> OK?
>>
>> Aldy
>>
>> canonicalize-nonzero-ranges.patch
>>
>> commit 1c333730deeb4ddadc46ad6d12d5344f92c0352c
>> Author: Aldy Hernandez <aldyh@redhat.com>
>> Date:   Fri Oct 4 08:51:25 2019 +0200
>>
>>      Canonicalize UNSIGNED [1,MAX] into ~[0,0].
>>      
>>      Adapt PLUS/MINUS symbolic handling, so it doesn't call
>>      ranges_from_anti_range with a VR_ANTI_RANGE containing one sub-range.
>>
>> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>> index 6e4f145af46..3934b41fdf9 100644
>> --- a/gcc/ChangeLog
>> +++ b/gcc/ChangeLog
>> @@ -1,3 +1,18 @@
>> +2019-10-04  Aldy Hernandez  <aldyh@redhat.com>
>> +
>> +	* tree-vrp.c (value_range_base::singleton_p): Use num_pairs
>> +	instead of calling vrp_val_is_*.
>> +	(value_range_base::set): Canonicalize unsigned [1,MAX] into
>> +	non-zero.
>> +	(range_has_numeric_bounds_p): New.
>> +	(range_int_cst_p): Use range_has_numeric_bounds_p.
>> +	(ranges_from_anti_range): Assert that we won't recurse
>> +	indefinitely.
>> +	(extract_extremes_from_range): New.
>> +	(extract_range_from_plus_minus_expr): Adapt so we don't call
>> +	ranges_from_anti_range with an anti-range containing only one
>> +	sub-range.
> So no problem with the implementation, but I do have a higher level
> question.
> 
> One of the goals of the representation side of the Ranger project is to
> drop anti-ranges.  Canonicalizing [1, MAX] to ~[0,0] seems to be going
> in the opposite direction.   So do we really want to canonicalize to ~[0,0]?

Hmmm, Andrew had the same question.

It really doesn't matter what we canonicalize too, as long as we're 
consistent, but there are a bunch of non-zero tests throughout that were 
checking for the ~[0,0] construct, and I didn't want to rock the boat 
too much.  Although in all honesty, most of those should already be 
converted to the ::nonzero_p() API.

However, if we canonicalize into [1,MAX] for unsigned, we have the 
problem that a signed non-zero will still be ~[0,0], so our ::nonzero_p 
code will have to check two different representations, not to mention it 
will now have to check TYPE_UNSIGNED(type).

Aldy

  reply	other threads:[~2019-10-04 15:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-04 12:59 Aldy Hernandez
2019-10-04 15:38 ` Jeff Law
2019-10-04 15:49   ` Aldy Hernandez [this message]
2019-10-04 16:02     ` Jeff Law
2019-10-04 16:14       ` Aldy Hernandez
2019-10-04 17:17         ` Jeff Law
2019-10-07 12:28           ` Aldy Hernandez
2019-10-13 16:32             ` Jeff Law
2019-10-15 11:59             ` Rainer Orth
2019-10-15 12:37               ` Aldy Hernandez
2019-10-15 12:45                 ` Rainer Orth
2019-10-15 13:07                   ` Iain Sandoe
2019-10-15 18:21                 ` Jakub Jelinek
2019-10-16  7:46                   ` Aldy Hernandez
2019-10-16  8:14                     ` Jakub Jelinek
2019-10-17  7:17                       ` Aldy Hernandez
2019-10-17  7:38                         ` Jakub Jelinek
2019-10-04 16:29   ` 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=74fb2cf8-6312-6ae2-b620-3d36deb61080@redhat.com \
    --to=aldyh@redhat.com \
    --cc=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.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).