OSDN Git Service

PR middlend/38385
[pf3gnuchains/gcc-fork.git] / gcc / tree-loop-distribution.c
index 062ab48..745957f 100644 (file)
@@ -331,6 +331,38 @@ generate_memset_zero (gimple stmt, tree op0, tree nb_iter,
   return res;
 }
 
+/* Propagate phis in BB b to their uses and remove them.  */
+
+static void
+prop_phis (basic_block b)
+{
+  gimple_stmt_iterator psi;
+  gimple_seq phis = phi_nodes (b);
+
+  for (psi = gsi_start (phis); !gsi_end_p (psi); )
+    {
+      gimple phi = gsi_stmt (psi);
+      tree def = gimple_phi_result (phi), use = gimple_phi_arg_def (phi, 0);
+
+      gcc_assert (gimple_phi_num_args (phi) == 1);
+
+      if (!is_gimple_reg (def))
+       {
+         imm_use_iterator iter;
+         use_operand_p use_p;
+         gimple stmt;
+
+         FOR_EACH_IMM_USE_STMT (stmt, iter, def)
+           FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
+             SET_USE (use_p, use);
+       }
+      else
+       replace_uses_by (def, use);
+
+      remove_phi_node (&psi, true);
+    }
+}
+
 /* Tries to generate a builtin function for the instructions of LOOP
    pointed to by the bits set in PARTITION.  Returns true when the
    operation succeeded.  */
@@ -400,6 +432,7 @@ generate_builtin (struct loop *loop, bitmap partition, bool copy_p)
       unsigned nbbs = loop->num_nodes;
       basic_block src = loop_preheader_edge (loop)->src;
       basic_block dest = single_exit (loop)->dest;
+      prop_phis (dest);
       make_edge (src, dest, EDGE_FALLTHRU);
       set_immediate_dominator (CDI_DOMINATORS, dest, src);
       cancel_loop_tree (loop);