re PR middle-end/21032 (With -frounding-math, incorrectly reorders unary minus)
authorRichard Guenther <rguenther@suse.de>
Mon, 23 Oct 2006 07:15:45 +0000 (07:15 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 23 Oct 2006 07:15:45 +0000 (07:15 +0000)
2006-10-23  Richard Guenther  <rguenther@suse.de>

PR middle-end/21032
* convert.c (convert_to_real): Fold (float)-x to -(float)x
only if not flag_rounding_math.

* gcc.dg/pr21032.c: New testcase.

From-SVN: r117968

gcc/ChangeLog
gcc/convert.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr21032.c [new file with mode: 0644]

index 328875538079d05fa747228e8909baf1ea0854ff..655596dcc55c69e291f2b55a8baeaf7cbceb6f91 100644 (file)
@@ -1,3 +1,9 @@
+2006-10-23  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/21032
+       * convert.c (convert_to_real): Fold (float)-x to -(float)x
+       only if not flag_rounding_math.
+
 2006-10-22  Richard Sandiford  <richard@codesourcery.com>
            Kaz Kojima  <kkojima@gcc.gnu.org>
 
index 118889fad443cd2be396b32baf72103e7a340ff1..0a9743ac8f84bf3e924cdc9f2b6345e7e0cdf8c0 100644 (file)
@@ -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))));
index 860107e23388e58741469e4190f9ff32babf696b..06d1abca1ab42996fc29a61ee0718736b4d0e280 100644 (file)
@@ -1,3 +1,8 @@
+2006-10-23  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/21032
+       * gcc.dg/pr21032.c: New testcase.
+
 2006-10-22  Jeff Law  <law@redhat.com>
        Richard Guenther  <rguenther@suse.de>
 
diff --git a/gcc/testsuite/gcc.dg/pr21032.c b/gcc/testsuite/gcc.dg/pr21032.c
new file mode 100644 (file)
index 0000000..839a180
--- /dev/null
@@ -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" } } */