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]

Re: [PATCH, for 4.2] improve remove useless statements (before CFG)


On Mon, Aug 22, 2005 at 10:21:36AM -0400, Andrew Pinski wrote:
> +  data->will_branch = false;

Notice how many times you set this.  Doesn't this strike you as
a maintainence problem?  Can you think of a better place to clear
this such that it's not so much of a problem?

It's also misnamed:

> +      if (call_expr_flags (t) & ECF_NORETURN)
> +	data->will_branch = true;
> +      else
> +	data->will_branch = false;

Such calls don't branch.  They do, however, !may_fallthru.

> +	    /* Remove stuff after a branch.  */
> +	    if (data->will_branch)
> +	      {
> +		while (!tsi_end_p (i))
> +		  {
> +		    t = tsi_stmt (i);
> +		    if (IS_EMPTY_STMT (t))
> +		      {
> +			tsi_delink (&i);
> +			continue;
> +		      }
> +		    /* Go until a statement is a LABEL_EXPR or
> +		       can contain a LABEL_EXPR. */
> +		    if (TREE_CODE (t) == LABEL_EXPR
> +		        || TREE_CODE (t) == BIND_EXPR
> +			|| TREE_CODE (t) == COND_EXPR
> +			|| TREE_CODE (t) == TRY_FINALLY_EXPR
> +			|| TREE_CODE (t) == TRY_CATCH_EXPR)
> +		      break;
> +		    if (warn_notreached)
> +		      remove_useless_stmts_warn_notreached (t);
> +		    tsi_delink (&i);

This can be merged with the outer loop.

Fixing all of the above might look like:

	bool unreachable = false;

	while (!tsi_end_p (i))
	  {
	    t = tsi_stmt (i);
	    if (IS_EMPTY_STMT (t))
	      {
		tsi_delink (&i);
		continue;
	      }
	    if (unreachable)
	      {
		if (may_contain_label)
		  unreachable = false;
		else
		  {
		    tsi_delink (&i);
		    continue;
		  }
	      }

	    data->may_fallthru = true;

	    remove_useless_stmts_1 (tsi_stmt_ptr (i), data);

	    if (!data->may_fallthru)
	      unreachable = true;

	    t = tsi_stmt (i);
	    if (TREE_CODE (t) == STATEMENT_LIST)
	      {
		tsi_link_before (&i, t, TSI_SAME_STMT);
		tsi_delink (&i);
	      }
	    else
	      tsi_next (&i);
	  }

And, finally, no I won't approve this for 4.1.


r~


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