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] Remove useless var->var copies


The out-of-ssa translation can create useless var1 = var2 statements much like
it can create a useless var1 = <const> statements.

For a hunk of testcodes the code currently in cfg_remove_useless_stmts kills
about 400 var = <const> statements.  This patch allows us to kill an additional
40 or so var1 = var2 statements when we know that var1 already has the same
value as var2.

This patch also originally had an initialization of "stmt" to fix a bootstrap
problem for x86-64, but Richard already checked in that fix.

In an earlier message regarding this code I speculated that that the GOTO
elimination in this code may no longer be necessary.  After some investigation
I believe the GOTO elimination done in cfg_remove_useless_stmts is still
useful.

First, it's still eliminating a ton of GOTO statements which simply 
transfer control to the next statement.  Odds are long term our cfg 
cleanup code should detect and handle this case.  Until then the
code in cfg_remove_useless_stmts needs to stay.

Second, elimination of GOTO_EXPRs in arms of COND_EXPRs is still quite
important.  It's quite common for one of the arms to goto the statement
immediately after the COND_EXPR (ie fall-thru).  In fact, for a set of
testcases I've got here nearly 40% of the COND_EXPRs have one arm which
jumps to the next statement.  Eliminating the GOTO_EXPR in that arm
cuts the number of jumps we create during tree->rtl translation by, well,
nearly 40%.

Anyway, this patch has been bootstrapped and regression tested on
i686-pc-linux-gnu.

	* tree-cfg.c (cfg_remove_useless_stmts_bb): Also detect useless
	var->var copies created by the out-of-ssa translation.

Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.212
diff -c -3 -p -r1.1.4.212 tree-cfg.c
*** tree-cfg.c	13 Nov 2003 18:46:22 -0000	1.1.4.212
--- tree-cfg.c	13 Nov 2003 20:36:26 -0000
*************** cfg_remove_useless_stmts_bb (basic_block
*** 1307,1313 ****
        else if ((TREE_CODE (cond) == EQ_EXPR)
  	       && (TREE_CODE (TREE_OPERAND (cond, 0)) == VAR_DECL
  		   || TREE_CODE (TREE_OPERAND (cond, 0)) == PARM_DECL)
! 	       && TREE_CONSTANT (TREE_OPERAND (cond, 1)))
  	{
  	  var = TREE_OPERAND (cond, 0);
  	  val = TREE_OPERAND (cond, 1);
--- 1307,1315 ----
        else if ((TREE_CODE (cond) == EQ_EXPR)
  	       && (TREE_CODE (TREE_OPERAND (cond, 0)) == VAR_DECL
  		   || TREE_CODE (TREE_OPERAND (cond, 0)) == PARM_DECL)
! 	       && (TREE_CODE (TREE_OPERAND (cond, 1)) == VAR_DECL
! 		   || TREE_CODE (TREE_OPERAND (cond, 1)) == PARM_DECL
! 		   || TREE_CONSTANT (TREE_OPERAND (cond, 1))))
  	{
  	  var = TREE_OPERAND (cond, 0);
  	  val = TREE_OPERAND (cond, 1);
*************** cfg_remove_useless_stmts_bb (basic_block
*** 1321,1326 ****
--- 1323,1337 ----
  	      || ann->may_aliases
  	      || TREE_ADDRESSABLE (var))
  	    var = NULL_TREE;
+ 
+ 	  if (! TREE_CONSTANT (val))
+ 	    {
+ 	      ann = var_ann (val);
+ 	      if (!ann
+ 		  || ann->may_aliases
+ 		  || TREE_ADDRESSABLE (val))
+ 		val = NULL_TREE;
+ 	    }
  	}
  
        /* Ignore floating point variables, since comparison behaves weird for
*************** cfg_remove_useless_stmts_bb (basic_block
*** 1345,1351 ****
  	 THEN/ELSE clause.  */
        if (TREE_CODE (stmt) == MODIFY_EXPR
  	  && TREE_OPERAND (stmt, 0) == var
! 	  && operand_equal_p (val, TREE_OPERAND (stmt, 1), 1))
  	{
  	  bsi_remove (&bsi);
  	  continue;
--- 1356,1362 ----
  	 THEN/ELSE clause.  */
        if (TREE_CODE (stmt) == MODIFY_EXPR
  	  && TREE_OPERAND (stmt, 0) == var
! 	  && operand_equal_p (val, TREE_OPERAND (stmt, 1), 0))
  	{
  	  bsi_remove (&bsi);
  	  continue;
*************** cfg_remove_useless_stmts_bb (basic_block
*** 1356,1361 ****
--- 1367,1373 ----
  	  || TREE_CODE (stmt) == VA_ARG_EXPR
  	  || (TREE_CODE (stmt) == MODIFY_EXPR
  	      && (TREE_OPERAND (stmt, 0) == var
+ 		  || TREE_OPERAND (stmt, 0) == val
  		  || TREE_CODE (TREE_OPERAND (stmt, 1)) == VA_ARG_EXPR)))
  	var = NULL_TREE;
    




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