This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, for 4.2] improve remove useless statements (before CFG)
- From: Richard Henderson <rth at redhat dot com>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: patch Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 22 Aug 2005 12:11:33 -0700
- Subject: Re: [PATCH, for 4.2] improve remove useless statements (before CFG)
- References: <635b9f5da81c9029c4f16a21fe3320bb@physics.uc.edu>
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~