This is the mail archive of the
mailing list for the GCC project.
Re: [Committed] PR middle-end/23470: pow(x,2.0) is non-negative
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Roger Sayle" <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 1 Nov 2006 11:45:20 +0100
- Subject: Re: [Committed] PR middle-end/23470: pow(x,2.0) is non-negative
- References: <Pine.LNX.firstname.lastname@example.org>
On 11/1/06, Roger Sayle <email@example.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
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.