This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[tree-ssa]: Use value propagation code in PRE


Since the last patch, I missed a small problem (we use the cached version for the inserts, since it needs to call propagate_value on it).

I'm just bootstrapping and make checking on x86 and darwin right now.

[dberlin@dberlin gcc]$ cvs diff -u3p tree-flow.h tree-ssa-pre.c tree-ssa-dom.c
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.191
diff -u -3 -p -r1.1.4.191 tree-flow.h
--- tree-flow.h 20 Feb 2004 12:46:00 -0000 1.1.4.191
+++ tree-flow.h 21 Feb 2004 00:49:04 -0000
@@ -576,7 +576,7 @@ tree widen_bitfield (tree, tree, tree);
/* In tree-ssa-dom.c */
extern void dump_dominator_optimization_stats (FILE *);
extern void debug_dominator_optimization_stats (void);
-extern void propagate_copy (tree *, tree);
+extern void propagate_value (tree *, tree);


/* In tree-flow-inline.h */
static inline int phi_arg_from_edge (tree, edge);
Index: tree-ssa-pre.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-pre.c,v
retrieving revision 1.1.4.129
diff -u -3 -p -r1.1.4.129 tree-ssa-pre.c
--- tree-ssa-pre.c 30 Jan 2004 13:14:18 -0000 1.1.4.129
+++ tree-ssa-pre.c 21 Feb 2004 00:49:05 -0000
@@ -141,9 +141,10 @@ static inline tree find_rhs_use_for_var
static tree create_ephi_node (basic_block, unsigned int);
static inline int opnum_of_phi (tree, int);
static inline int opnum_of_ephi (const tree, const edge);
-static tree subst_phis (struct expr_info *, tree, basic_block, basic_block);
-static void generate_expr_as_of_bb (tree, basic_block, basic_block);
-static void generate_vops_as_of_bb (tree, basic_block, basic_block);
+static tree subst_phis (struct expr_info *, tree, basic_block, basic_block,
+ bool);
+static void generate_expr_as_of_bb (tree, basic_block, basic_block, bool);
+static void generate_vops_as_of_bb (tree, basic_block, basic_block, bool);
static void rename_1 (struct expr_info *);
static void process_delayed_rename (struct expr_info *, tree, tree);
static void assign_new_class (tree, varray_type *, varray_type *);
@@ -1205,7 +1206,8 @@ opnum_of_phi (tree phi, int j)
block BB. */


 static void
-generate_expr_as_of_bb (tree expr, basic_block pred, basic_block bb)
+generate_expr_as_of_bb (tree expr, basic_block pred, basic_block bb,
+                       bool for_insert)
 {
   use_optype uses = STMT_USE_OPS (expr);
   bool replaced_constants = false;
@@ -1223,10 +1225,16 @@ generate_expr_as_of_bb (tree expr, basic
            {
              int opnum = opnum_of_phi (phi, pred->index);
              tree p = PHI_ARG_DEF (phi, opnum);
-             *vp = p;
-             if (!phi_ssa_name_p (p))
-               replaced_constants = true;
-             break;
+             if (may_propagate_copy (*vp, p))
+               {
+                 if (for_insert)
+                   propagate_value (vp, p);
+                 else
+                   *vp = p;
+                 if (!phi_ssa_name_p (p))
+                   replaced_constants = true;
+                 break;
+               }
            }
        }
     }
@@ -1242,7 +1250,8 @@ generate_expr_as_of_bb (tree expr, basic
    ops for the bb.  */

 static void
-generate_vops_as_of_bb (tree expr, basic_block pred, basic_block bb)
+generate_vops_as_of_bb (tree expr, basic_block pred, basic_block bb,
+                       bool for_insert)
 {
   vuse_optype vuses = STMT_VUSE_OPS (expr);
   size_t i;
@@ -1258,8 +1267,14 @@ generate_vops_as_of_bb (tree expr, basic
            {
              int opnum = opnum_of_phi (phi, pred->index);
              tree p = PHI_ARG_DEF (phi, opnum);
-             *VUSE_OP_PTR (vuses, i) = p;
-             break;
+             if (may_propagate_copy (*VUSE_OP_PTR (vuses, i), p))
+               {
+                 if (for_insert)
+                   propagate_value (VUSE_OP_PTR (vuses, i), p);
+                 else
+                   *VUSE_OP_PTR (vuses, i) = p;
+                 break;
+               }
            }
        }
     }
@@ -1269,14 +1284,16 @@ generate_vops_as_of_bb (tree expr, basic
    in BB. */

static tree
-subst_phis (struct expr_info *ei, tree Z, basic_block pred, basic_block bb)
+subst_phis (struct expr_info *ei, tree Z, basic_block pred, basic_block bb,
+ bool for_insert)
{
tree stmt_copy;
size_t i;


   /* Return the cached version, if we have one. */
   if (pred->index < n_phi_preds
-      && phi_pred_cache[pred->index] != NULL_TREE)
+      && phi_pred_cache[pred->index] != NULL_TREE
+      && !for_insert)
     return phi_pred_cache[pred->index];

   /* Otherwise, generate a new expression.  */
@@ -1285,7 +1302,7 @@ subst_phis (struct expr_info *ei, tree Z
   create_stmt_ann (stmt_copy);
   modify_stmt (stmt_copy);
   get_stmt_operands (stmt_copy);
-  generate_expr_as_of_bb (stmt_copy, pred, bb);
+  generate_expr_as_of_bb (stmt_copy, pred, bb, for_insert);
   set_bb_for_stmt (stmt_copy, bb);
   modify_stmt (stmt_copy);
   get_stmt_operands (stmt_copy);
@@ -1305,7 +1322,7 @@ subst_phis (struct expr_info *ei, tree Z
         add_vuse (VUSE_OP (vuses, i), stmt_copy);
       finalize_ssa_stmt_operands (stmt_copy);

-      generate_vops_as_of_bb (stmt_copy, pred, bb);
+      generate_vops_as_of_bb (stmt_copy, pred, bb, for_insert);
     }
   else
     {
@@ -1517,8 +1534,8 @@ process_delayed_rename (struct expr_info
          EPHI_ARG_DELAYED_RENAME (exp_phi, opnd_num) = false;
          def = opnd;
          newexp = subst_phis (ei, real_occ,
-                             EPHI_ARG_EDGE (exp_phi, opnd_num)->src,
-                             bb_for_stmt (exp_phi));
+                              EPHI_ARG_EDGE (exp_phi, opnd_num)->src,
+                              bb_for_stmt (exp_phi), false);

          /* For operands defined by EPHIs, we need to compare the
             generated expression and the phi result.
@@ -2095,7 +2112,7 @@ insert_one_operand (struct expr_info *ei
   copy = unshare_expr (copy);
   expr = build (MODIFY_EXPR, TREE_TYPE (ei->expr),
                temp, copy);
-  expr = subst_phis (ei, expr, bb, bb_for_stmt (ephi));
+  expr = subst_phis (ei, expr, bb, bb_for_stmt (ephi), true);
   newtemp = make_ssa_name (temp, expr);
   TREE_OPERAND (expr, 0) = newtemp;
   copy = TREE_OPERAND (expr, 1);
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.136
diff -u -3 -p -r1.1.2.136 tree-ssa-dom.c
--- tree-ssa-dom.c      16 Feb 2004 12:36:01 -0000      1.1.2.136
+++ tree-ssa-dom.c      21 Feb 2004 00:49:06 -0000
@@ -259,6 +259,7 @@ static void restore_vars_to_original_val
                                            varray_type table);
 static void register_definitions_for_stmt (tree, varray_type *);
 static void redirect_edges_and_update_ssa_graph (varray_type);
+static void propagate_copy (tree *, tree);

/* Local version of fold that doesn't introduce cruft. */

@@ -279,7 +280,7 @@ local_fold (tree t)
/* Propagate the value VAL (assumed to be a constant or another SSA_NAME)
into the operand pointed by OP_P. */


-static void
+void
propagate_value (tree *op_p, tree val)
{
if (TREE_CODE (val) == SSA_NAME)
@@ -3314,7 +3315,7 @@ avail_expr_eq (const void *p1, const voi
pointer, copy the memory tag used originally by *OP_P into VAR. This is
needed in cases where VAR had never been dereferenced in the program. */


-void
+static void
 propagate_copy (tree *op_p, tree var)
 {
 #if defined ENABLE_CHECKING


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]