[Committed] PR middle-end/23470: pow(x,2.0) is non-negative

Richard Guenther richard.guenther@gmail.com
Wed Nov 1 10:45:00 GMT 2006


On 11/1/06, Roger Sayle <roger@eyesopen.com> wrote:
>
> The following patch resolves PR middle-end/23470 by teaching
> fold-const.c's tree_expr_nonnegative_p that pow(x,y) and powi(x,y)
> are nonnegative if either x is non-negative or y is an even number.
> Reading though my documentation this appears correct for C99 even
> in the presence of infinities and signed zeros.
>
> The issue in the PR is with -ffast-math, the middle-end internally
> handles x*x as __builtin_pow(x,2.0) when x has a floating point type,
> and although fold-const.c can determine that x*x is non-negative for
> floating point values, it wasn't as clever about __builtin_pow.  With
> this change, we can now even optimize "if (x*x*x*x*x*x < 0.0)" when
> using -ffast-math.

What do you think of a POW_EXPR tree code?  We could allow base
and exponent to differ in types and impose fortran semantics on it
with respect to expression contracting and rounding.  Folding and
expanding would simplify.

Richard.



More information about the Gcc-patches mailing list