On Tue, 2006-03-14 at 03:16 +0100, Waldek Hebisch wrote:

> 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
> precision.
VRP can certainly do this -- I added the ability to see through
more typecasts a while back.  In general, I've tried to improve
the ability of our optimizers to eliminate or at least "see through"
some typecasts.  However, that capability is often very limited
and the ability to see through type casts is not pervasive in
the optimization pipeline.

What I seriously doubt is that you have enough cases of the nature
you posted to matter in practice.

I would expect that for the vast majority of cases that the
source and destination operands are going to have the same ranges.
And in that case exposing the tighter min/max data on your ranges
does you no good.  It just creates a lot of silly nop-casts which
waste memory and will tend to inhibit optimizations.


> 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.
I'm not suggesting the FEs deduce more types and track ranges;
that would be rather absurd.  What I'm saying is that exposing
these types outside the FE is most likely costing you both on
the compile-time side and on the run-time side.

You'd present far cleaner code to the optimizers if you just
did *everything* in the object's base type.  You'd generate
far fewer nodes, saving compile-time and memory and the
optimizers will have a much better opportunity to optimize
the code.

But that's your decision to make -- I think we've all agreed
that as long as you don't allow values outside the min/max
range to be stored into variables with these types, then it
should be safe to continue to do things the way you're doing
them.

jeff

Reply via email to