OSDN Git Service

PR middle-end/17278
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-dom.c
index 68bf4f9..648ee56 100644 (file)
@@ -246,7 +246,7 @@ struct vrp_hash_elt
    in this basic block.  We use this during finalization to know
    which variables need their VRP data updated.  */
 
-/* Stack of SSA_NAMEs which had their values constrainted by operations
+/* Stack of SSA_NAMEs which had their values constrained by operations
    in this basic block.  During finalization of this block we use this
    list to determine which variables need their VRP data updated.
 
@@ -457,8 +457,29 @@ tree_ssa_dominator_optimize (void)
 
       for (i = 0; i < num_referenced_vars; i++)
        var_ann (referenced_var (i))->current_def = NULL;
+
+      /* Finally, remove everything except invariants in SSA_NAME_VALUE.
+
+        This must be done before we iterate as we might have a
+        reference to an SSA_NAME which was removed by the call to
+        rewrite_ssa_into_ssa.
+
+        Long term we will be able to let everything in SSA_NAME_VALUE
+        persist.  However, for now, we know this is the safe thing to do.  */
+      for (i = 0; i < num_ssa_names; i++)
+       {
+         tree name = ssa_name (i);
+         tree value;
+
+         if (!name)
+           continue;
+
+         value = SSA_NAME_VALUE (name);
+         if (value && !is_gimple_min_invariant (value))
+           SSA_NAME_VALUE (name) = NULL;
+       }
     }
-  while (cfg_altered);
+  while (optimize > 1 && cfg_altered);
 
   /* Debugging dumps.  */
   if (dump_file && (dump_flags & TDF_STATS))
@@ -478,24 +499,6 @@ tree_ssa_dominator_optimize (void)
   /* Free nonzero_vars.  */
   BITMAP_XFREE (nonzero_vars);
   BITMAP_XFREE (need_eh_cleanup);
-
-  /* Finally, remove everything except invariants in SSA_NAME_VALUE.
-
-     Long term we will be able to let everything in SSA_NAME_VALUE
-     persist.  However, for now, we know this is the safe thing to
-     do.  */
-  for (i = 0; i < num_ssa_names; i++)
-    {
-      tree name = ssa_name (i);
-      tree value;
-
-      if (!name)
-       continue;
-
-      value = SSA_NAME_VALUE (name);
-      if (value && !is_gimple_min_invariant (value))
-       SSA_NAME_VALUE (name) = NULL;
-    }
   
   VEC_free (tree_on_heap, block_defs_stack);
   VEC_free (tree_on_heap, avail_exprs_stack);
@@ -1252,7 +1255,7 @@ record_equivalences_from_incoming_edge (basic_block bb)
   basic_block parent;
   struct edge_info *edge_info;
 
-  /* If our parent block ended with a control statment, then we may be
+  /* If our parent block ended with a control statement, then we may be
      able to record some equivalences based on which outgoing edge from
      the parent was followed.  */
   parent = get_immediate_dominator (CDI_DOMINATORS, bb);
@@ -2816,6 +2819,14 @@ cprop_operand (tree stmt, use_operand_p op_p)
         extensions.  */
       else if (!may_propagate_copy (op, val))
        return false;
+      
+      /* Do not propagate copies if the propagated value is at a deeper loop
+        depth than the propagatee.  Otherwise, this may move loop variant
+        variables outside of their loops and prevent coalescing
+        opportunities.  If the value was loop invariant, it will be hoisted
+        by LICM and exposed for copy propagation.  */
+      if (loop_depth_of_name (val) > loop_depth_of_name (op))
+       return false;
 
       /* Dump details.  */
       if (dump_file && (dump_flags & TDF_DETAILS))