OSDN Git Service

2011-02-08 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Feb 2011 10:44:06 +0000 (10:44 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 8 Feb 2011 10:44:06 +0000 (10:44 +0000)
PR tree-optimization/47632
* tree-ssa-forwprop.c (remove_prop_source_from_use): Remove
unused up_to_stmt parameter, return whether cfg-cleanup is
necessary, remove EH info properly.
(forward_propagate_into_gimple_cond): Adjust caller.
(forward_propagate_into_cond): Likewise.
(forward_propagate_comparison): Likewise.
(tree_ssa_forward_propagate_single_use_vars): Make
forward_propagate_comparison case similar to the two others.

* g++.dg/opt/pr47632.C: New testcase.

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr47632.C [new file with mode: 0644]
gcc/tree-ssa-forwprop.c

index 3fd6d02..c485326 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-08  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/47632
+       * tree-ssa-forwprop.c (remove_prop_source_from_use): Remove
+       unused up_to_stmt parameter, return whether cfg-cleanup is
+       necessary, remove EH info properly.
+       (forward_propagate_into_gimple_cond): Adjust caller.
+       (forward_propagate_into_cond): Likewise.
+       (forward_propagate_comparison): Likewise.
+       (tree_ssa_forward_propagate_single_use_vars): Make
+       forward_propagate_comparison case similar to the two others.
+
 2011-02-08  Nick Clifton  <nickc@redhat.com>
 
        * config/mn10300/mn10300.opt (mliw): New command line option.
index fef7869..51b225f 100644 (file)
@@ -1,3 +1,8 @@
+2011-02-08  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/47632
+       * g++.dg/opt/pr47632.C: New testcase.
+
 2011-02-07  Ulrich Weigand  <Ulrich.Weigand@de.ibm.com>
 
        * g++.dg/abi/packed1.C: Expect warning on spu-*-* as well.
diff --git a/gcc/testsuite/g++.dg/opt/pr47632.C b/gcc/testsuite/g++.dg/opt/pr47632.C
new file mode 100644 (file)
index 0000000..4b0572a
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile }
+// { dg-options "-O -fnon-call-exceptions -ftrapv" }
+
+template < typename > struct S
+{
+  int n;
+  void bar ()
+    {
+      int *i = new int[n];
+    }
+};
+
+void
+foo (S < char >*s)
+{
+  s->bar ();
+}
+
index ee12e40..f183159 100644 (file)
@@ -299,34 +299,34 @@ can_propagate_from (gimple def_stmt)
   return true;
 }
 
-/* Remove a copy chain ending in NAME along the defs but not
-   further or including UP_TO_STMT.  If NAME was replaced in
-   its only use then this function can be used to clean up
-   dead stmts.  Returns true if UP_TO_STMT can be removed
-   as well, otherwise false.  */
+/* Remove a copy chain ending in NAME along the defs.
+   If NAME was replaced in its only use then this function can be used
+   to clean up dead stmts.  Returns true if cleanup-cfg has to run.  */
 
 static bool
-remove_prop_source_from_use (tree name, gimple up_to_stmt)
+remove_prop_source_from_use (tree name)
 {
   gimple_stmt_iterator gsi;
   gimple stmt;
+  bool cfg_changed = false;
 
   do {
+    basic_block bb;
+
     if (!has_zero_uses (name))
-      return false;
+      return cfg_changed;
 
     stmt = SSA_NAME_DEF_STMT (name);
-    if (stmt == up_to_stmt)
-      return true;
-
     gsi = gsi_for_stmt (stmt);
+    bb = gimple_bb (stmt);
     release_defs (stmt);
     gsi_remove (&gsi, true);
+    cfg_changed |= gimple_purge_dead_eh_edges (bb);
 
     name = (gimple_assign_copy_p (stmt)) ? gimple_assign_rhs1 (stmt) : NULL;
   } while (name && TREE_CODE (name) == SSA_NAME);
 
-  return false;
+  return cfg_changed;
 }
 
 /* Return the rhs of a gimple_assign STMT in a form of a single tree,
@@ -468,9 +468,8 @@ forward_propagate_into_gimple_cond (gimple stmt)
        update_stmt (stmt);
 
        /* Remove defining statements.  */
-       remove_prop_source_from_use (name, NULL);
-
-       if (is_gimple_min_invariant (tmp))
+       if (remove_prop_source_from_use (name)
+           || is_gimple_min_invariant (tmp))
          did_something = 2;
        else if (did_something == 0)
          did_something = 1;
@@ -579,9 +578,8 @@ forward_propagate_into_cond (gimple_stmt_iterator *gsi_p)
        update_stmt (stmt);
 
        /* Remove defining statements.  */
-       remove_prop_source_from_use (name, NULL);
-
-       if (is_gimple_min_invariant (tmp))
+       if (remove_prop_source_from_use (name)
+           || is_gimple_min_invariant (tmp))
          did_something = 2;
        else if (did_something == 0)
          did_something = 1;
@@ -1207,9 +1205,6 @@ forward_propagate_comparison (gimple stmt)
        update_stmt (use_stmt);
       }
 
-      /* Remove defining statements.  */
-      remove_prop_source_from_use (name, stmt);
-
       if (dump_file && (dump_flags & TDF_DETAILS))
        {
          tree old_rhs = rhs_to_tree (TREE_TYPE (gimple_assign_lhs (stmt)),
@@ -1221,7 +1216,8 @@ forward_propagate_comparison (gimple stmt)
          fprintf (dump_file, "'\n");
        }
 
-      return true;
+      /* Remove defining statements.  */
+      return remove_prop_source_from_use (name);
     }
 
   return false;
@@ -2051,13 +2047,8 @@ tree_ssa_forward_propagate_single_use_vars (void)
                                        == tcc_comparison)
                {
                  if (forward_propagate_comparison (stmt))
-                   {
-                     release_defs (stmt);
-                     todoflags |= TODO_remove_unused_locals;
-                     gsi_remove (&gsi, true);
-                   }
-                 else
-                   gsi_next (&gsi);
+                   cfg_changed = true;
+                 gsi_next (&gsi);
                }
              else if (gimple_assign_rhs_code (stmt) == BIT_AND_EXPR)
                {