This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: patch to fix constant math -5th patch, rtl


On Wed, Apr 24, 2013 at 5:29 PM, Richard Sandiford
<rdsandiford@googlemail.com> wrote:
> Richard Biener <richard.guenther@gmail.com> writes:
>> On Wed, Apr 24, 2013 at 4:35 PM, Kenneth Zadeck
>> <zadeck@naturalbridge.com> wrote:
>>> On 04/24/2013 09:36 AM, Richard Biener wrote:
>>>>
>>>> On Wed, Apr 24, 2013 at 2:44 PM, Richard Sandiford
>>>> <rdsandiford@googlemail.com> wrote:
>>>>>
>>>>> Richard Biener <richard.guenther@gmail.com> writes:
>>>>>>
>>>>>> Can we in such cases please to a preparatory patch and change the
>>>>>> CONST_INT/CONST_DOUBLE paths to do an explicit [sz]ext to
>>>>>> mode precision first?
>>>>>
>>>>> I'm not sure what you mean here.  CONST_INT HWIs are already
>>>>> sign-extended
>>>>> from mode precision to HWI precision.  The 8-bit value 0xb10000000 must
>>>>> be
>>>>> represented as (const_int -128); nothing else is allowed.  E.g.
>>>>> (const_int 128)
>>>>> is not a valid QImode value on BITS_PER_UNIT==8 targets.
>>>>
>>>> Yes, that's what I understand.  But consider you get a CONST_INT that is
>>>> _not_ a valid QImode value.  Current code simply trusts that it is, given
>>>> the context from ...
>>>
>>> And the fact that it we have to trust but cannot verify is a severe problem
>>> at the rtl level that is not going to go away.    what i have been strongly
>>> objecting to is your idea that just because we cannot verify it, we can thus
>>> go change it in some completely different way (i.e. the infinite precision
>>> nonsense that you keep hitting us with) and it will all be ok.
>>
>> Appearantly it is all ok because that's exactly what we have today (and
>> had for the last 25 years).  CONST_INT encodes infinite precision signed
>> values (with the complication that a QImode 0x80 isn't valid, thus all
>> modes are signed as well it seems).
>
> I think this is the fundamental disagreement.  Your last step doesn't
> follow.  RTL integer modes are neither signed nor unsigned.  They are
> just a collection of N bits.  The fact that CONST_INTs represent
> smaller-than-HWI integers in sign-extended form is purely a represential
> detail.  There are no semantics attached to it.  We could just as easily
> have decided to extend with zeros or ones instead of sign bits.
>
> Although the decision was made before my time, I'm pretty sure the
> point of having a canonical representation (which happened to be sign
> extension) was to make sure that any given rtl constant has only a
> single representation.  It would be too confusing if a QImode 0x80 could
> be represented as either (const_int 128) or (const_int -128) (would
> (const_int 384) then also be OK?).

No, not as value for a QImode as it doesn't fit there.

> And that's the problem with using an infinite-precision wide_int.
> If you directly convert a CONST_INT representation of 0x80 into a
> wide_int, you will always get infinite-precision -128, thanks to the
> CONST_INT canonicalisation rule.  But if you arrive at 0x80 though
> arithmetic, you might get infinite-precision 128 instead.  These two
> values would not compare equal.

That's true.  Note that I am not objecting to the canonicalization choice
for the RTL object.  On trees we do have -128 and 128 QImode integers
as tree constants have a sign.

So we clearly cannot have wide_int make that choice, but those that
create either a tree object or a RTL object have to do additional
canonicalization (or truncation to not allow a QImode 384).

Yes, I'm again arguing that making choices for wide_int shouldn't be
done because it seems right for RTL or right for how a CPU operates.
But we are mixing two things in this series of patches - introduction
of an additional RTX object kind CONST_WIDE_INT together with
deciding on its encoding of constant values, and introduction of
a wide_int class as a vehicle to do arithmetic on the host for larger
than HOST_WIDE_INT values.

The latter could be separated by dropping CONST_DOUBLE in favor
of CONST_WIDE_INT everywhere and simply providing a
CONST_WIDE_INT <-> double-int interface (both ways, so you'd
actually never generate a CONST_WIDE_INT that doesn't fit a double-int).

>> CONST_DOUBLE encodes infinite precision signed values as well.  Just
>> the "infinite" is limited by the size of the encoding, one and two
>> HOST_WIDE_INTs.
>
> It encodes an N-bit integer.  It's just that (assuming non-power-of-2
> modes) several N-bit integers (with varying N) can be encoded using the
> same CONST_DOUBLE representation.  That might be what you meant, sorry,
> and so might seem pedantic, but I wasn't sure.

Yes, that's what I meant.  Being able to share the same RTX object for
constants with the same representation but a different mode is nice
and looks appealing (of course works only when the actual mode stored
in the RTX object is then sth like VOIDmode ...).  That we have gazillions
of NULL pointer constants on trees (for each pointer type) isn't.

Richard.

> Richard


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]