[tree-ssa/mainline PATCH] fold "test"==0 into constant

Jan Hubicka hubicka@ucw.cz
Thu Nov 6 14:07:00 GMT 2003


> 
> Hi Jan,
> > The patch bellow is based on merging tree_expr_nonnegative_p and RTL
> > nonzero_address implementation so it catch these and slightly more
> > sophisficated cases.
> 
> You need to guard some of these cases with checks for "! flag_wrapv".
> The code in rtlanal.c's nonzero_address_p is valid only because it is
> only used for addressing arithmetic which has undefined overflow.  In
> Java, for example, "max (x, 1) + max (y, 1)" can still be zero, even
> though each term must be greater than zero.  [p.s. it looks like

Isn't it what TREE_OVERFLOW flag is used for?

> you miss this case :>]  Similarly for multiplication where a zero result

I do, but that would require testing both nonzero and nonnegative in
PLUS case that may be quite expensive in recursion.  I can add it if you
thinnk it is usefull.
> 
> Longer-term, I think what constant folding really needs are two
> functions tree_expr_lower_bound and tree_expr_upper_bound, where we
> can implement some form of interval arithmetic.  Then the two current

We will likely get this with VRP soonish.  However nonzero test is not
exacly an interval (at least in common implementations you don't allow
negative interval mening everything except for zero).  

I think we will ikely end up with VRP code and in addtion these simple
checks.  The simple checks has the advantage of cheaply getting rid of
most cases without expensive analysis.

Honza



More information about the Gcc-patches mailing list