re PR tree-optimization/23911 (Failure to propagate constants from a const initialize...
authorSteven Bosscher <stevenb@suse.de>
Thu, 29 Sep 2005 12:25:10 +0000 (12:25 +0000)
committerSteven Bosscher <steven@gcc.gnu.org>
Thu, 29 Sep 2005 12:25:10 +0000 (12:25 +0000)
gcc/
PR tree-optimization/23911
* tree-ssa-ccp.c (fold_const_aggregate_ref): Handle REALPART_EXPR
and IMAGPART_EXPR too.

testsuite/
* gcc.dg/pr23911.c: New test.

From-SVN: r104771

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

index 7b1ffbbeaa4f0d515e839f2c33780ecc937a3e14..fb6640308a1fdfb407240d02d4239348389970a8 100644 (file)
@@ -1,3 +1,9 @@
+2005-09-29  Steven Bosscher  <stevenb@suse.de>
+
+       PR tree-optimization/23911
+       * tree-ssa-ccp.c (fold_const_aggregate_ref): Handle REALPART_EXPR
+       and IMAGPART_EXPR too.
+
 2005-09-28  Mark Mitchell  <mark@codesourcery.com>
 
        PR 17886
index 1c426b48f90bb98bbca3c2c60589d8c6c51ae4ea..6146c2387f668a682bf621c3516ff7d9fc9478b0 100644 (file)
@@ -1,3 +1,7 @@
+2005-09-29  Steven Bosscher  <stevenb@suse.de>
+
+       * gcc.dg/pr23911.c: New test.
+
 2005-09-28  Mark Mitchell  <mark@codesourcery.com>
 
        * g++.dg/opt/pr19650.C: Use -w -fpermissive.
diff --git a/gcc/testsuite/gcc.dg/pr23911.c b/gcc/testsuite/gcc.dg/pr23911.c
new file mode 100644 (file)
index 0000000..1003075
--- /dev/null
@@ -0,0 +1,22 @@
+/* This was a missed optimization in tree constant propagation
+   that CSE would catch later on.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-store_ccp" } */
+
+double _Complex *a; 
+const double _Complex b[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 
+void 
+test (void) 
+{ 
+  a[0] = b[0] + b[1]; 
+  a[1] = b[0] + b[1]; 
+  return; 
+} 
+
+/* After store_ccp, there should not be any assignments from real or
+   imaginary parts anymore.  The constants should be loaded from b and
+   propagated into the elements of a.  */
+/* { dg-final { scan-tree-dump-times "= CR" 0 "store_ccp" } } */
+/* { dg-final { scan-tree-dump-times "= CI" 0 "store_ccp" } } */
+/* { dg-final { cleanup-tree-dump "store_ccp" } } */
index 1ff15287345f370e960611989ffed523f0180007..43b8129109b08ed0fc3dda67ba3230aade6da2ce 100644 (file)
@@ -1045,6 +1045,15 @@ fold_const_aggregate_ref (tree t)
          return cval;
       break;
 
+    case REALPART_EXPR:
+    case IMAGPART_EXPR:
+      {
+       tree c = fold_const_aggregate_ref (TREE_OPERAND (t, 0));
+       if (c && TREE_CODE (c) == COMPLEX_CST)
+         return fold_build1 (TREE_CODE (t), TREE_TYPE (t), c);
+       break;
+      }
+    
     default:
       break;
     }