re PR middle-end/26134 (fold *(float*)(&complex_float_var) into REALPART_EXPR<complex...
authorRichard Guenther <rguenther@suse.de>
Wed, 16 Mar 2011 13:53:09 +0000 (13:53 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 16 Mar 2011 13:53:09 +0000 (13:53 +0000)
2011-03-16  Richard Guenther  <rguenther@suse.de>

PR tree-optimization/26134
* tree-ssa.c (maybe_rewrite_mem_ref_base): Handle rewriting
complex part accesses to REALPART_EXPR and IMAGPART_EXPR.
(non_rewritable_mem_ref_base): Handle complex type component
accesses, constrain offsets for vector and complex extracts
more properly.

* gcc.dg/tree-ssa/complex-6.c: New testcase.

From-SVN: r171046

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/complex-6.c [new file with mode: 0644]
gcc/tree-ssa.c

index 7e81a550dfbffbd59961a1c21a5f33155656f5d8..a535ac1e10e381c7893eca31ce8af0d3b45fd89f 100644 (file)
@@ -1,3 +1,12 @@
+2011-03-16  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/26134
+       * tree-ssa.c (maybe_rewrite_mem_ref_base): Handle rewriting
+       complex part accesses to REALPART_EXPR and IMAGPART_EXPR.
+       (non_rewritable_mem_ref_base): Handle complex type component
+       accesses, constrain offsets for vector and complex extracts
+       more properly.
+
 2011-03-16  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/48146
index 2e6963b0460e791996ec2109f8307c84f1e7f0e1..7b68766d717e6ebcc336b22e2ddb6c16b535bab1 100644 (file)
@@ -1,3 +1,8 @@
+2011-03-16  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/26134
+       * gcc.dg/tree-ssa/complex-6.c: New testcase.
+
 2011-03-16  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/48146
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/complex-6.c b/gcc/testsuite/gcc.dg/tree-ssa/complex-6.c
new file mode 100644 (file)
index 0000000..01d1fd1
--- /dev/null
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+float
+quantum_real(float _Complex a)
+{
+  float *p = (float *) &a;
+  return p[0];
+}
+float
+quantum_imag(float _Complex a)
+{
+  float *p = (float *) &a;
+  return p[1];
+}
+float
+quantum_foo(float _Complex a)
+{
+  float *p = (float *) &a;
+  return p[2];
+}
+
+/* { dg-final { scan-tree-dump-times "REALPART_EXPR" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "IMAGPART_EXPR" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
index f28e5d15c72d2f5ebc810a822b57ba6342a29a97..e7e3edcf6f1f9db85b751671427b5898c7cb84a3 100644 (file)
@@ -1855,6 +1855,14 @@ maybe_rewrite_mem_ref_base (tree *tp)
                                         bitsize_int (BITS_PER_UNIT),
                                         TREE_OPERAND (*tp, 1), 0));
        }
+      else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
+              && useless_type_conversion_p (TREE_TYPE (*tp),
+                                            TREE_TYPE (TREE_TYPE (sym))))
+       {
+         *tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
+                       ? REALPART_EXPR : IMAGPART_EXPR,
+                       TREE_TYPE (*tp), sym);
+       }
       else if (integer_zerop (TREE_OPERAND (*tp, 1)))
        {
          if (!useless_type_conversion_p (TREE_TYPE (*tp),
@@ -1888,10 +1896,14 @@ non_rewritable_mem_ref_base (tree ref)
       && TREE_CODE (TREE_OPERAND (base, 0)) == ADDR_EXPR)
     {
       tree decl = TREE_OPERAND (TREE_OPERAND (base, 0), 0);
-      if (TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
+      if ((TREE_CODE (TREE_TYPE (decl)) == VECTOR_TYPE
+          || TREE_CODE (TREE_TYPE (decl)) == COMPLEX_TYPE)
          && useless_type_conversion_p (TREE_TYPE (base),
                                        TREE_TYPE (TREE_TYPE (decl)))
          && double_int_fits_in_uhwi_p (mem_ref_offset (base))
+         && double_int_ucmp
+              (tree_to_double_int (TYPE_SIZE_UNIT (TREE_TYPE (decl))),
+               mem_ref_offset (base)) == 1
          && multiple_of_p (sizetype, TREE_OPERAND (base, 1),
                            TYPE_SIZE_UNIT (TREE_TYPE (base))))
        return NULL_TREE;