Fold and integer types with sub-ranges

Richard Kenner kenner@vlsi1.ultra.nyu.edu
Sun Feb 25 12:28:00 GMT 2007


> Note that having TREE_TYPE(type)!=NULL does not imply that the type and the
> base type are inequivalent.  For example, if you declare a type Int as
> follows:
> 	subtype Int is Integer;
> then TREE_TYPE(type_for_Int)=type_for_Integer, but the types are equivalent,
> in particular they have the same TYPE_MIN_VALUE and TYPE_MAX_VALUE.

True, but there's still no harm in using the base type in that case (and I
think the front end will).

I think there are two very different things that need to be tested:

(1) If fold wants to determine if it can safely remove a conversion, it needs
to explicitly test whether the constant can fit into the (sub)type; it
doesn't care whether it's a subtype of something or not.

(2) If we're *generating* arithmetic, we can check TREE_TYPE (type) and,
if nonzero, generate the conversions.  Then fold can get rid of them if they
turn out to be unnecessary.

I think the above is the simplest mechanism that also is precisely correct;
yes, we could do further checks in (2), but it seems unnecessary work: the
issue isn't if the bounds are the same, but if the constant fits in the bounds.



More information about the Gcc mailing list