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] Avoiding useless stmt copies in CCP


OK, this definitely classifies as low hanging fruit.  It takes my timing
test from 714 to 701 seconds of user time by avoiding creating a copy
if there are no operands to replace.

Next step, either a non-destructive folder or undo buffers for trees.

Whee.

	* tree-ssa-ccp.c (may_fold_p): New function.  Returns nonzero if
	the given statement may fold after replacement of operands with
	constants.
	(evaluate_stmt): Only create a copy of the statement if there is
	a reasonable chance the statement will fold.

Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.45
diff -c -3 -p -r1.1.2.45 tree-ssa-ccp.c
*** tree-ssa-ccp.c	6 Feb 2003 04:41:05 -0000	1.1.2.45
--- tree-ssa-ccp.c	14 Feb 2003 04:20:10 -0000
*************** static value evaluate_stmt		PARAMS ((tre
*** 115,120 ****
--- 115,121 ----
  static void dump_lattice_value		PARAMS ((FILE *, const char *, value));
  static tree widen_bitfield		PARAMS ((tree, tree, tree));
  static bool replace_uses_in		PARAMS ((tree));
+ static bool may_fold_p			PARAMS ((tree));
  static void fold_stmt			PARAMS ((tree));
  static tree get_rhs			PARAMS ((tree));
  static void set_rhs			PARAMS ((tree, tree));
*************** evaluate_stmt (stmt)
*** 618,627 ****
    val.lattice_val = VARYING;
    val.const_val = NULL_TREE;
  
!   /* Evaluate a copy of the original statement.  */
!   copy = copy_stmt (stmt);
!   if (replace_uses_in (copy))
!     fold_stmt (copy);
  
    /* Extract the folded value from the statement.  */
    simplified = get_rhs (copy);
--- 619,634 ----
    val.lattice_val = VARYING;
    val.const_val = NULL_TREE;
  
!   if (may_fold_p (stmt))
!     {
!       /* Evaluate a copy of the original statement with operands
!          replaced with their current constant value.  */
!       copy = copy_stmt (stmt);
!       replace_uses_in (copy);
!       fold_stmt (copy);
!     }
!   else
!     copy = stmt;
  
    /* Extract the folded value from the statement.  */
    simplified = get_rhs (copy);
*************** replace_uses_in (stmt)
*** 885,890 ****
--- 892,926 ----
      }
  
    return replaced;
+ }
+ 
+ 
+ /* Return nonzero if STMT has a reasonable chance of folding into
+    something simpler.
+ 
+    We consider STMT likely to fold if at least one of its operands
+    is a constant.  */
+ 
+ static bool
+ may_fold_p (stmt)
+      tree stmt;
+ {
+   varray_type uses;
+   size_t i;
+ 
+   get_stmt_operands (stmt);
+ 
+   uses = use_ops (stmt);
+   for (i = 0; uses && i < VARRAY_ACTIVE_SIZE (uses); i++)
+     {
+       tree *use = VARRAY_GENERIC_PTR (uses, i);
+       value *val = get_value (*use);
+ 
+       if (val->lattice_val == CONSTANT)
+ 	return true;
+     }
+ 
+   return false;
  }
  
  







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