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]

[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


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