Minor CCP improvement and add comments to tree.h

Jeffrey A Law law@redhat.com
Wed Sep 22 05:58:00 GMT 2004


As noted in a message yesterday, it's not possible for the different
passes to use and update equivalency information via SSA_NAME_EQUIV.

This patch updates CCP to use any recorded equivalency information
in SSA_NAME_EQUIV to seed the CCP values array and at the end of CCP,
we transfer any equivalences discovered by CCP into the SSA_NAME_EQUIV
field as well.

This ever so slightly reduces the number of state transitions
performed by CCP.  I was hoping for better results, but such is
life.

This change also adds some comments to tree.h that were requested
by Daniel.  I'm not sure how I managed to lose them since I know
I wrote them twice...   Oh well.

Bootstrapped and regression tested on i686-pc-linux-gnu.


-------------- next part --------------
	* tree-ssa-ccp.c (get_default_value): If we have a constant
	value recorded for an SSA_NAME, then use that constant as
	the initial lattice value.
	(substitute_and_fold): Transfer equivalences discovered into
	SSA_NAME_EQUIV.

	* tree.h (SSA_NAME_EQUIV): Add comments.
	(SET_SSA_NAME_EQUIV): Similarly.

Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.626
diff -c -p -r1.626 tree.h
*** tree.h	21 Sep 2004 03:18:59 -0000	1.626
--- tree.h	22 Sep 2004 03:49:47 -0000
*************** struct tree_exp GTY(())
*** 1304,1316 ****
  #define SSA_NAME_OCCURS_IN_ABNORMAL_PHI(NODE) \
      SSA_NAME_CHECK (NODE)->common.asm_written_flag
  
- 
  /* Nonzero if this SSA_NAME expression is currently on the free list of
     SSA_NAMES.  Using NOTHROW_FLAG seems reasonably safe since throwing
     has no meaning for an SSA_NAME.  */
  #define SSA_NAME_IN_FREE_LIST(NODE) \
      SSA_NAME_CHECK (NODE)->common.nothrow_flag
  
  #define SSA_NAME_EQUIV(NAME) __extension__ \
    ({  tree equiv = SSA_NAME_CHECK (NAME)->ssa_name.equiv; \
        if (equiv && TREE_CODE (equiv) == SSA_NAME) \
--- 1304,1317 ----
  #define SSA_NAME_OCCURS_IN_ABNORMAL_PHI(NODE) \
      SSA_NAME_CHECK (NODE)->common.asm_written_flag
  
  /* Nonzero if this SSA_NAME expression is currently on the free list of
     SSA_NAMES.  Using NOTHROW_FLAG seems reasonably safe since throwing
     has no meaning for an SSA_NAME.  */
  #define SSA_NAME_IN_FREE_LIST(NODE) \
      SSA_NAME_CHECK (NODE)->common.nothrow_flag
  
+ /* If NAME is equivalent to some other SSA_NAME or an invariant, then
+    return the equivalent SSA_NAME or invariant, else return NULL.  */
  #define SSA_NAME_EQUIV(NAME) __extension__ \
    ({  tree equiv = SSA_NAME_CHECK (NAME)->ssa_name.equiv; \
        if (equiv && TREE_CODE (equiv) == SSA_NAME) \
*************** struct tree_exp GTY(())
*** 1318,1323 ****
--- 1319,1326 ----
        equiv; \
     })
  
+ /* Record that NAME (an SSA_NAME) is equivalent to EQUIV.  */
+ 
  #define SET_SSA_NAME_EQUIV(NAME, EQUIV)\
     SSA_NAME_CHECK (NAME)->ssa_name.equiv = (EQUIV);
  
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-ccp.c,v
retrieving revision 2.41
diff -c -p -r2.41 tree-ssa-ccp.c
*** tree-ssa-ccp.c	17 Sep 2004 21:54:41 -0000	2.41
--- tree-ssa-ccp.c	22 Sep 2004 04:04:52 -0000
*************** get_default_value (tree var)
*** 135,141 ****
    val.lattice_val = UNDEFINED;
    val.const_val = NULL_TREE;
  
!   if (TREE_CODE (sym) == PARM_DECL || TREE_THIS_VOLATILE (sym))
      {
        /* Function arguments and volatile variables are considered VARYING.  */
        val.lattice_val = VARYING;
--- 135,148 ----
    val.lattice_val = UNDEFINED;
    val.const_val = NULL_TREE;
  
!   if (TREE_CODE (var) == SSA_NAME
!       && SSA_NAME_EQUIV (var)
!       && is_gimple_min_invariant (SSA_NAME_EQUIV (var)))
!     {
!       val.lattice_val = CONSTANT;
!       val.const_val = SSA_NAME_EQUIV (var);
!     }
!   else if (TREE_CODE (sym) == PARM_DECL || TREE_THIS_VOLATILE (sym))
      {
        /* Function arguments and volatile variables are considered VARYING.  */
        val.lattice_val = VARYING;
*************** static void
*** 512,517 ****
--- 519,525 ----
  substitute_and_fold (void)
  {
    basic_block bb;
+   unsigned int i;
  
    if (dump_file && (dump_flags & TDF_DETAILS))
      fprintf (dump_file,
*************** substitute_and_fold (void)
*** 586,591 ****
--- 594,618 ----
  	    }
  	}
      }
+ 
+   /* And transfer what we learned from VALUE_VECTOR into the
+      SSA_NAMEs themselves.  This probably isn't terribly important
+      since we probably constant propagated the values to their
+      use sites above.  */
+   for (i = 0; i < num_ssa_names; i++)
+     {
+       tree name = ssa_name (i);
+       value *value;
+ 
+       if (!name)
+ 	continue;
+ 
+       value = get_value (name);
+       if (value->lattice_val == CONSTANT
+           && is_gimple_reg (name)
+ 	  && is_gimple_min_invariant (value->const_val))
+ 	SET_SSA_NAME_EQUIV (name, value->const_val)
+     }
  }
  
  


More information about the Gcc-patches mailing list