OSDN Git Service

2010-01-21 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 21 Jan 2010 12:15:40 +0000 (12:15 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 21 Jan 2010 12:15:40 +0000 (12:15 +0000)
PR middle-end/19988
* fold-const.c (negate_expr_p): Pretend only negative
real constants are easily negatable.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156152 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr19988.c [new file with mode: 0644]

index 90061ec..207d680 100644 (file)
@@ -1,3 +1,9 @@
+2010-01-21  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/19988
+       * fold-const.c (negate_expr_p): Pretend only negative
+       real constants are easily negatable.
+
 2010-01-20  Janis Johnson  <janis187@us.ibm.com>
            Jason Merrill  <jason@redhat.com>
 
index 9d249cc..e7a4b8c 100644 (file)
@@ -1129,10 +1129,14 @@ negate_expr_p (tree t)
              && TYPE_OVERFLOW_WRAPS (type));
 
     case FIXED_CST:
-    case REAL_CST:
     case NEGATE_EXPR:
       return true;
 
+    case REAL_CST:
+      /* We want to canonicalize to positive real constants.  Pretend
+         that only negative ones can be easily negated.  */
+      return REAL_VALUE_NEGATIVE (TREE_REAL_CST (t));
+
     case COMPLEX_CST:
       return negate_expr_p (TREE_REALPART (t))
             && negate_expr_p (TREE_IMAGPART (t));
index 9c89203..2bfa419 100644 (file)
@@ -1,3 +1,8 @@
+2010-01-21  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/19988
+       * gcc.dg/pr19988.c: New testcase.
+
 2010-01-20  Janis Johnson  <janis187@us.ibm.com>
 
        * g++.dg/compat/decimal/compat-common.h: New file.
diff --git a/gcc/testsuite/gcc.dg/pr19988.c b/gcc/testsuite/gcc.dg/pr19988.c
new file mode 100644 (file)
index 0000000..aa2fed1
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized -fdump-tree-original" } */
+
+double foo(double x, double y)
+{
+  return ((x + 0.1234 * y) * (x - 0.1234 * y));
+}
+
+/* Keep positive constants during folding.  */
+/* { dg-final { scan-tree-dump-times " 1.23" 2 "original" } } */
+/* CSE one multiplication.  */
+/* { dg-final { scan-tree-dump-times " \\\* " 2 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */