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] Removing redundant loads


I mentioned at the GCC summit, I had a nice one line patch which allowed
tree-ssa to remove redundant loads at basically no cost.

Testing of that patch uncovered a latent but in the tree-ssa code which
is why the patch hadn't been checked in.  That bug has been identified
and fixed.

Some notes on the effects of this change:

  First remember that the GCC optimizers have some capability to remove
  redundant loads.  CSE, GCSE and identifying dead code can all make
  stores go away.  So one shouldn't expect a huge improvement in the
  generated code from this patch.

  But even with that in mind, this patch results in about .4% reduction
  in instructions for my components of cc1 & libstdc++ test.  Some of
  the instructions removed were loads, some were address computations,
  some where secondary effects due to changing register pressure, etc.

  .4% static instruction improvement may not be huge, but it's not
  insignificant, especially when a goodly amount of those are memory
  operands.  The improvements tended to be small ones spread across
  many files.

  Second, this resulted in a compiler which consistently runs faster.  
  The improvement is small, again roughly a .4% improvement.  This
  improvement was pretty consistent regardless of whether or not the
  final assembly code showed any improvement.

  Third, I was testing another hunk of code (out of the libstdc++-v3
  testsuite) where load elimination done by tree-ssa exposed a lot of
  redundant stores.  This resulted in a roughly 3% decrease in static
  code size -- with nearly every one of the remove instructions being
  a store.  Good stuff.

	* tree-ssa.c (rewrite_stmt): Detect and remove redundant
	memory loads.
	(avail_expr_hash): Use iterative_hash_expr, not iterative_hash_object
	as needed.


Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.81
diff -c -3 -p -r1.1.4.81 tree-ssa.c
*** tree-ssa.c	24 May 2003 13:08:51 -0000	1.1.4.81
--- tree-ssa.c	29 May 2003 19:16:09 -0000
*************** rewrite_stmt (si, block_defs_p, block_av
*** 2107,2116 ****
      fold_stmt (stmt);
  
    /* Step 2.  Check for redundant computations.  Do this optimization only
!      for assignments that make no calls and have no aliased nor volatile
!      references and no side effects (i.e., no VDEFs).  */
!   may_optimize_p = !ann->makes_aliased_loads
! 		   && !ann->makes_aliased_stores
  		   && !ann->has_volatile_ops
  		   && vdefs == NULL;
  
--- 2107,2115 ----
      fold_stmt (stmt);
  
    /* Step 2.  Check for redundant computations.  Do this optimization only
!      for assignments that make no calls and have no aliased stores
!      nor volatile references and no side effects (i.e., no VDEFs).  */
!   may_optimize_p = !ann->makes_aliased_stores
  		   && !ann->has_volatile_ops
  		   && vdefs == NULL;
  
*************** avail_expr_hash (p)
*** 2604,2610 ****
        if (TREE_CODE (op) == SSA_NAME)
  	val = iterative_hash_object (SSA_NAME_VERSION (op), val);
        else
! 	val = iterative_hash_object (op, val);
      }
  
    /* Add the SSA version numbers of every vuse operand.  This is important
--- 2603,2609 ----
        if (TREE_CODE (op) == SSA_NAME)
  	val = iterative_hash_object (SSA_NAME_VERSION (op), val);
        else
! 	val = iterative_hash_expr (op, val);
      }
  
    /* Add the SSA version numbers of every vuse operand.  This is important




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