]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-ssa-pre.c (insert_into_preds_of_block): Before inserting a PHI ask VN if it...
authorRichard Guenther <rguenther@suse.de>
Thu, 21 Aug 2008 15:18:58 +0000 (15:18 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 21 Aug 2008 15:18:58 +0000 (15:18 +0000)
2008-08-21  Richard Guenther  <rguenther@suse.de>

* tree-ssa-pre.c (insert_into_preds_of_block): Before inserting
a PHI ask VN if it is already available.
* tree-ssa-sccvn.h (vn_phi_lookup): Declare.
* tree-ssa-sccvn.c (vn_phi_lookup): Export.

From-SVN: r139388

gcc/ChangeLog
gcc/tree-ssa-pre.c
gcc/tree-ssa-sccvn.c
gcc/tree-ssa-sccvn.h

index e897d5032f05394192d2780d9a68123522460816..741d19f33d46042ce8f4797e57678a28da4e7c79 100644 (file)
@@ -1,3 +1,10 @@
+2008-08-21  Richard Guenther  <rguenther@suse.de>
+
+       * tree-ssa-pre.c (insert_into_preds_of_block): Before inserting
+       a PHI ask VN if it is already available.
+       * tree-ssa-sccvn.h (vn_phi_lookup): Declare.
+       * tree-ssa-sccvn.c (vn_phi_lookup): Export.
+
 2008-08-21  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/36817
index d2a55ae7ddc6858446efef71d37617b0e1b6bc05..606cafa1792d726b2e7165136563197bd09a3636 100644 (file)
@@ -2896,7 +2896,7 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
   pre_expr eprime;
   edge_iterator ei;
   tree type = get_expr_type (expr);
-  tree temp;
+  tree temp, res;
   gimple phi;
 
   if (dump_file && (dump_flags & TDF_DETAILS))
@@ -3051,12 +3051,8 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
   if (TREE_CODE (type) == COMPLEX_TYPE
       || TREE_CODE (type) == VECTOR_TYPE)
     DECL_GIMPLE_REG_P (temp) = 1;
-  phi = create_phi_node (temp, block);
 
-  gimple_set_plf (phi, NECESSARY, false);
-  VN_INFO_GET (gimple_phi_result (phi))->valnum = gimple_phi_result (phi);
-  VN_INFO (gimple_phi_result (phi))->value_id = val;
-  VEC_safe_push (gimple, heap, inserted_exprs, phi);
+  phi = create_phi_node (temp, block);
   FOR_EACH_EDGE (pred, ei, block->preds)
     {
       pre_expr ae = avail[pred->src->index];
@@ -3067,6 +3063,20 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
       else
        add_phi_arg (phi, PRE_EXPR_NAME (avail[pred->src->index]), pred);
     }
+  /* If the PHI node is already available, use it.  */
+  if ((res = vn_phi_lookup (phi)) != NULL_TREE)
+    {
+      gimple_stmt_iterator gsi = gsi_for_stmt (phi);
+      remove_phi_node (&gsi, true);
+      release_defs (phi);
+      add_to_value (val, get_or_alloc_expr_for_name (res));
+      return false;
+    }
+
+  gimple_set_plf (phi, NECESSARY, false);
+  VN_INFO_GET (gimple_phi_result (phi))->valnum = gimple_phi_result (phi);
+  VN_INFO (gimple_phi_result (phi))->value_id = val;
+  VEC_safe_push (gimple, heap, inserted_exprs, phi);
 
   newphi = get_or_alloc_expr_for_name (gimple_phi_result (phi));
   add_to_value (val, newphi);
index 26a65f126e11ce113fb1ff100f62979190063b98..0b995d6837dfaeecba590c303a6330a4c63d118a 100644 (file)
@@ -1458,7 +1458,7 @@ static VEC(tree, heap) *shared_lookup_phiargs;
    value number if it exists in the hash table.  Return NULL_TREE if
    it does not exist in the hash table. */
 
-static tree
+tree
 vn_phi_lookup (gimple phi)
 {
   void **slot;
index 49baa761831d4847bbece91337f416ee196435db..84f096ef2245318b56ffef493918c92d6909bfaa 100644 (file)
@@ -184,6 +184,7 @@ vn_reference_t vn_reference_insert (tree, tree, VEC (tree, gc) *);
 vn_reference_t vn_reference_insert_pieces (VEC (tree, gc) *,
                                           VEC (vn_reference_op_s, heap) *,
                                           tree, unsigned int);
+tree vn_phi_lookup (gimple);
 
 hashval_t vn_nary_op_compute_hash (const vn_nary_op_t);
 int vn_nary_op_eq (const void *, const void *);