re PR tree-optimization/48149 (Piecewise complex pass-through not optimized)
authorRichard Guenther <rguenther@suse.de>
Wed, 16 Mar 2011 15:55:48 +0000 (15:55 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 16 Mar 2011 15:55:48 +0000 (15:55 +0000)
2011-03-16  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/48149
* fold-const.c (fold_binary_loc): Fold
COMPLEX_EXPR <REALPART_EXPR <x>, IMAGPART_EXPR <x>>.

* gcc.dg/fold-complex-1.c: New testcase.

From-SVN: r171048

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

index a535ac1e10e381c7893eca31ce8af0d3b45fd89f..c19efcb5d9fdffff924a4d0d54aa052b98c003cf 100644 (file)
@@ -1,3 +1,9 @@
+2011-03-16  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/48149
+       * fold-const.c (fold_binary_loc): Fold
+       COMPLEX_EXPR <REALPART_EXPR <x>, IMAGPART_EXPR <x>>.
+
 2011-03-16  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/26134
index f8630a2baa3d421ef7f999096c97164bd5082194..9baa9eb24bc5eccd966f308cb8109620e75572bf 100644 (file)
@@ -13176,6 +13176,14 @@ fold_binary_loc (location_t loc,
          || (TREE_CODE (arg0) == INTEGER_CST
              && TREE_CODE (arg1) == INTEGER_CST))
        return build_complex (type, arg0, arg1);
+      if (TREE_CODE (arg0) == REALPART_EXPR
+         && TREE_CODE (arg1) == IMAGPART_EXPR
+         && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg0, 0)))
+             == TYPE_MAIN_VARIANT (type))
+         && operand_equal_p (TREE_OPERAND (arg0, 0),
+                             TREE_OPERAND (arg1, 0), 0))
+       return omit_one_operand_loc (loc, type, TREE_OPERAND (arg0, 0),
+                                    TREE_OPERAND (arg1, 0));
       return NULL_TREE;
 
     case ASSERT_EXPR:
index efb61404df9ca51218b01e1c2b1d675c69180f42..a9db0b7eb9d01ec409c0db7e92ba4be1c3881cea 100644 (file)
@@ -1,3 +1,8 @@
+2011-03-16  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/48149
+       * gcc.dg/fold-complex-1.c: New testcase.
+
 2011-03-16  Richard Guenther  <rguenther@suse.de>
 
        PR testsuite/48147
diff --git a/gcc/testsuite/gcc.dg/fold-complex-1.c b/gcc/testsuite/gcc.dg/fold-complex-1.c
new file mode 100644 (file)
index 0000000..a9ba0fd
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -ffast-math -fdump-tree-original" } */
+
+_Complex float
+foo (_Complex float x)
+{
+  return  __real x + 1.0iF * __imag x;
+}
+
+/* { dg-final { scan-tree-dump-times "COMPLEX_EXPR" 0 "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */