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: [tree-ssa/mainline PATCH] fold "test"==0 into constant

> 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 think it is usefull.

The advantage with lower and upper bounds is that you only need to do
a single recursion.  The second advantage is that the bounds functions
can contain recursion limiters (a depth or time-to-live counter) such
that we only recurse atmost four or five levels before returning a
safe default, TYPE_MIN_VALUE (TREE_TYPE (t)) or TYPE_MAX_VALUE (...).

> We will likely get this with VRP soonish.

This is not quite the same as classical VRP which maintains bounds on
variables.  Instead this a local VRP within a single expression, for
the time being DECLs are assumed to hold the full range of their type.
Instead its the context the expression they are in that provides the
resticted bounds.  "if ((x ? 2 : 3) == (y ? 6 : 7))" is always false
without any dataflow analysis or propagation of bounds.  Similarly,
"(x | 6) != 0" and "(x & 5) < 12".

Clearly this ties in which the more usual notion of VRP, where the
bounds on variables may be propagated through the CFG, using min and
max at phi nodes.  But even before that is in-place, local VRP is
useful.  Indeed many of the (unsigned char)x <= 0xff optimizations
during constant folding are just special cases of the more generic

> However nonzero test is not exacly an interval (at least in common
> implementations you don't allow negative interval mening everything
> except for zero).

This is very true, we know that for signed x, "x | 5" is never zero,
but may still be positive or negative.  However, building the nonzero
predicate on top of the proposed range bounds, limits the numbers of
cases like this that have to be considered specially.


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