This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Expand unreachable WHILE_STMTs like DO_STMTs (take 2)
- From: Roger Sayle <roger at eyesopen dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, Jason Merrill <jason at redhat dot com>
- Date: Tue, 3 Jun 2003 19:23:12 -0600 (MDT)
- Subject: Re: [PATCH] Expand unreachable WHILE_STMTs like DO_STMTs (take 2)
On Tue, 3 Jun 2003, Richard Henderson wrote:
> On Thu, May 29, 2003 at 07:56:21AM -0600, Roger Sayle wrote:
> > + case WHILE_STMT:
> > + /* If the start of a while statement is unreachable, there is
> > + no need to rotate the loop, instead the WHILE_STMT can be
> > + expanded like a DO_STMT. */
> > + genrtl_do_stmt_1 (WHILE_COND (t), WHILE_BODY (t));
>
> Didn't you lose the check for reachable label in the WHILE_COND?
> You had it in your original patch...
Ah, you noticed. I apologise for not explaining the rationale
for this tweak explicitly when I reposted the revised patch.
I believe the original test for user labels in the while
condition was unnecessary. The while condition will always be
expanded, and the "expected" behaviour is that any user label
targets in the expression appear before the controlling branch
of the loop.
Hence, the original layout (without while loop rotation) would be:
barrier // the start of the while is unreachable.
loop_top:
early_user_label:
cond = expand_expr(cond);
late_user_label:
if (!cond)
goto loop_exit:
loop_body
goto loop_top
loop_exit:
With while-loop rotation, we previously introduced dead-code:
barrier
goto loop_test // unreachable!
loop_top:
loop_body
loop_test:
early_user_label:
cond = expand_expr(cond)
late_user_label:
if (cond)
goto loop_top
However, its safe to convert this into a do-while loop even in the
presence of user labels in the while condition.
barrier
loop_top:
loop_body
loop_test:
early_user_label:
cond = expand_expr(cond)
late_user_label:
if (cond)
goto loop_top
I apologise if my explanation isn't particularly clear. The short
response is that I believe its safe to convert unreachable while
statements into do-while statements even in the presence of user
labels in the while condition. Removing this check should be safe
and also avoids GCC generating unreachable code warnings when
there are user labels in the unreachable while's condition.
Is this explanation satisfactory? The only thing that could be
affected is if the user's code assumes a particular ordering of
user labels in the object file. However I believe this isn't
guaranteed by GCC, with passes like reorder basic-blocks, loop
unrolling, CFG cleanup etc... moving labels relative to each
other whilst preserving the program's original behaviour.
Roger
--