This is the mail archive of the 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: Ada subtypes and base types

Jeffrey A Law wrote:
> On Mon, 2006-02-27 at 20:08 +0100, Waldek Hebisch wrote:
> > What do you mean by "abuse"?  TYPE_MAX_VALUE means maximal value
> > allowed by given type.
> As long as you're *absolutely* clear that  a variable with a
> restricted range can never hold a value outside that the
> restricted range in a conforming program, then I'll back off
> the "abuse" label and merely call it pointless :-)
> The scheme you're using "promoting" to a base type before all
> arithmetic creates lots of useless type conversions and means
> that the optimizers can't utilize TYPE_MIN_VALUE/TYPE_MAX_VALUE
> anyway.  ie, you don't gain anything over keeping that knowledge
> in the front-end.

Pascal arithmetic essentially is untyped: operators take integer
arguments and are supposed to give mathematically correct result
(provided all intermediate results are representable in machine
arithmetic, overflow is treated as user error). OTOH for proper
type checking front end have to track ranges associated to
variables. So "useless" type conversions are needed due to
Pascal standard and backend constraints.

I think that it is easy for back end to make good use of
TYPE_MIN_VALUE/TYPE_MAX_VALUE. Namely, consider the assignment

x := y + z * w;

where variables y, z and w have values in the interval [0,7] and
x have values in [0,1000]. Pascal converts the above to the
following C like code:

int tmp = (int) y + (int) z * (int) w;
x = (tmp < 0 || tmp > 1000)? (Range_Check_Error (), 0) : tmp;
I expect VRP to deduce that tmp will have values in [0..56] and
eliminate range check. Also, it should be clear that in the
assigment above artithmetic can be done using any convenient

In principle Pascal front end could deduce more precise types (ranges),
but that would create some extra type conversions and a lot
of extra types. Moreover, I assume that VRP can do better job
at tracking ranges then Pascal front end.

                              Waldek Hebisch 

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