This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] tree-ssa-ccp propagate constants into PHIs
- From: law at redhat dot com
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 05 Aug 2003 07:15:47 -0600
- Subject: [tree-ssa] tree-ssa-ccp propagate constants into PHIs
- Reply-to: law at redhat dot com
CCP goes through all the trouble to propagate constant values on a global
basis and substitutes them into statements throughout the function. However
it fails to substitute constants into PHI nodes. Seems kind-of silly to
me :-)
This enables CCP to propagate constants into PHI nodes.
Bootstrapped and regression tested.
* tree-ssa-ccp.c (substitute_and_fold): Substitute known
constants into PHI nodes.
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.81
diff -c -3 -p -r1.1.2.81 tree-ssa-ccp.c
*** tree-ssa-ccp.c 31 Jul 2003 16:33:26 -0000 1.1.2.81
--- tree-ssa-ccp.c 5 Aug 2003 13:12:07 -0000
*************** substitute_and_fold (void)
*** 311,316 ****
--- 311,337 ----
FOR_EACH_BB (bb)
{
block_stmt_iterator i;
+ tree phi;
+
+ /* Propagate our known constants into PHI nodes. */
+ for (phi = phi_nodes (bb); phi; phi = TREE_CHAIN (phi))
+ {
+ int i;
+
+ for (i = 0; i < PHI_NUM_ARGS (phi); i++)
+ {
+ value *new_val;
+ tree *orig_p = &PHI_ARG_DEF (phi, i);
+
+ if (! SSA_VAR_P (*orig_p))
+ break;
+
+ new_val = get_value (*orig_p);
+ if (new_val->lattice_val == CONSTANT
+ && may_propagate_copy (*orig_p, new_val->const_val))
+ *orig_p = new_val->const_val;
+ }
+ }
for (i = bsi_start (bb); !bsi_end_p (i); bsi_next (&i))
{