This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Simplify RTL for loop exits without nesting (take 2)
- From: Roger Sayle <roger at eyesopen dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 24 Sep 2002 20:46:06 -0600 (MDT)
- Subject: [PATCH] Simplify RTL for loop exits without nesting (take 2)
This patch is an update to my earlier patch of the same title:
http://gcc.gnu.org/ml/gcc-patches/2002-09/msg01196.html
Since that patch was posted, I've commited two other related
patches to expand_exit_loop_if_false on the basic improvements
branch, so that the original patch no longer applies cleanly.
To recap, expand_exit_loop_if_false typically generates four or
five RTL insns for a loop exit, when in almost all cases only one
or two are actually required. Rather than let cfg_cleanup
delete the three redundant insns for each exit, we can avoid
allocating them in the first place.
This revision (i) updates the patch to apply cleanly against the
gcc-3_4-basic-improvements-branch and (ii) confirms that it still
works as expected following the recent changes in this area.
This version has been bootstrapped on i686-pc-linux-gnu, all languages
except Ada and treelang, and survives a full "make -k check" with
no new regressions. Ok for gcc-3_4-basic-improvements-branch?
2002-09-24 Roger Sayle <roger@eyesopen.com>
* stmt.c (expand_exit_loop_if_false): Expand a simple conditional
jump, if the loop to exit is the top of the current nesting stack.
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.269.4.4
diff -c -3 -p -r1.269.4.4 stmt.c
*** stmt.c 20 Sep 2002 05:29:37 -0000 1.269.4.4
--- stmt.c 24 Sep 2002 16:18:21 -0000
*************** expand_exit_loop_if_false (whichloop, co
*** 2702,2713 ****
if (integer_zerop (cond))
return expand_exit_loop (whichloop);
/* In order to handle fixups, we actually create a conditional jump
around an unconditional branch to exit the loop. If fixups are
necessary, they go before the unconditional branch. */
label = gen_label_rtx ();
! do_jump (cond, NULL_RTX, label);
expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label,
NULL_RTX);
emit_label (label);
--- 2702,2720 ----
if (integer_zerop (cond))
return expand_exit_loop (whichloop);
+ /* Check if we definitely won't need a fixup. */
+ if (whichloop == nesting_stack)
+ {
+ jumpifnot (cond, whichloop->data.loop.end_label);
+ return 1;
+ }
+
/* In order to handle fixups, we actually create a conditional jump
around an unconditional branch to exit the loop. If fixups are
necessary, they go before the unconditional branch. */
label = gen_label_rtx ();
! jumpif (cond, label);
expand_goto_internal (NULL_TREE, whichloop->data.loop.end_label,
NULL_RTX);
emit_label (label);
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833