diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 94787b07012b..00803735c41b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2006-11-13 Richard Guenther + + Backport from mainline: + 2006-10-23 Richard Guenther + + PR middle-end/21032 + * convert.c (convert_to_real): Fold (float)-x to -(float)x + only if not flag_rounding_math. + 2006-11-12 Jason Merrill Andrew Pinski diff --git a/gcc/convert.c b/gcc/convert.c index 118889fad443..0a9743ac8f84 100644 --- a/gcc/convert.c +++ b/gcc/convert.c @@ -248,10 +248,12 @@ convert_to_real (tree type, tree expr) if (itype != type && FLOAT_TYPE_P (type)) switch (TREE_CODE (expr)) { - /* Convert (float)-x into -(float)x. This is always safe. */ + /* Convert (float)-x into -(float)x. This is safe for + round-to-nearest rounding mode. */ case ABS_EXPR: case NEGATE_EXPR: - if (TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (expr))) + if (!flag_rounding_math + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (expr))) return build1 (TREE_CODE (expr), type, fold (convert_to_real (type, TREE_OPERAND (expr, 0)))); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5dbb050612e5..989344ec69d5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2006-11-13 Richard Guenther + + Backport form mainline: + 2006-10-23 Richard Guenther + + PR middle-end/21032 + * gcc.dg/pr21032.c: New testcase. + 2006-11-12 Paul Thomas PR fortran/29699 diff --git a/gcc/testsuite/gcc.dg/pr21032.c b/gcc/testsuite/gcc.dg/pr21032.c new file mode 100644 index 000000000000..839a180cead2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr21032.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized -frounding-math" } */ + +void bar(float x); +void foo(double x) +{ + bar(-x); +} + +/* { dg-final { scan-tree-dump-not "-\\(float\\)" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */