[tree-ssa] Removal of more useless statements

law@redhat.com law@redhat.com
Mon Jun 23 22:35:00 GMT 2003


While working on eliminating more edges from the CFG, I noticed that
we were not being as aggressive as we could/should be when removing
useless TRY_FINALLY_EXPRs and TRY_CATCH_EXPRs.  This patch allows us
to remove TRY_FINALLY_EXPRs and TRY_CATCH_EXPRs in a few more situations.

It's been through all the usual testing.

	* tree-cfg.c (remove_useless_stmts_and_vars): More aggressively
	remove TRY_CATCH_EXPRs and TRY_FINALLY_EXPRs.

Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.115
diff -c -3 -p -r1.1.4.115 tree-cfg.c
*** tree-cfg.c	23 Jun 2003 20:06:04 -0000	1.1.4.115
--- tree-cfg.c	23 Jun 2003 21:35:41 -0000
*************** remove_useless_stmts_and_vars (tree *fir
*** 1533,1555 ****
  	  repeat |= remove_useless_stmts_and_vars (&TREE_OPERAND (*stmt_p, 0));
  	  repeat |= remove_useless_stmts_and_vars (&TREE_OPERAND (*stmt_p, 1));
  
! 	  /* If the body of a TRY_FINALLY is empty, then we can just
! 	     emit the handler without the enclosing TRY_FINALLY.
!                                                                              

! 	     If the body of a TRY_CATCH is empty and the handler is
! 	     empty (it had no reachable code either), then we can
! 	     emit an empty statement without the enclosing TRY_CATCH.
! 
! 	     In both cases we want to apply this optimization pass
! 	     again.  */
! 	  if (IS_EMPTY_STMT (TREE_OPERAND (*stmt_p, 0)))
  	    {
! 	      if (code == TRY_FINALLY_EXPR
! 		  || IS_EMPTY_STMT (TREE_OPERAND (*stmt_p, 1)))
! 		{
! 		  *stmt_p = TREE_OPERAND (*stmt_p, 1);
! 		  repeat = 1;
! 		}
  	    }
  	}
        else if (code == BIND_EXPR)
--- 1533,1558 ----
  	  repeat |= remove_useless_stmts_and_vars (&TREE_OPERAND (*stmt_p, 0));
  	  repeat |= remove_useless_stmts_and_vars (&TREE_OPERAND (*stmt_p, 1));
  
! 	  /* If the handler of a TRY_CATCH or TRY_FINALLY is empty, then
! 	     we can emit the TRY block without the enclosing TRY_CATCH_EXPR
! 	     or TRY_FINALLY_EXPR.  */
! 	  if (IS_EMPTY_STMT (TREE_OPERAND (*stmt_p, 1)))
  	    {
! 	      *stmt_p = TREE_OPERAND (*stmt_p, 0);
! 	      repeat = 1;
! 	    }
! 
! 	  /* If the body of a TRY_FINALLY is empty, then we can emit
! 	     the FINALLY block without the enclosing TRY_FINALLY_EXPR.
! 
! 	     I don't think this is safe with TRY_CATCH_EXPR.  Consider
! 	     if the CATCH block of a TRY_CATCH_EXPR is reached from
! 	     outside the TRY_CATCH_EXPR via a GOTO.  */
! 	  else if (code == TRY_FINALLY_EXPR
! 		   && IS_EMPTY_STMT (TREE_OPERAND (*stmt_p, 0)))
! 	    {
! 	      *stmt_p = TREE_OPERAND (*stmt_p, 1);
! 	      repeat = 1;
  	    }
  	}
        else if (code == BIND_EXPR)





More information about the Gcc-patches mailing list