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] Clean-up orphaned NOTE_INSN_LOOP_CONT notes


In two recent examples, I've come across orphaned NOTE_INSN_LOOP_CONT
notes whilst examining the output.  These are generated by infinite
loop constructs like "for(;;) {...}" or "while(1) {...}" which may
be generated as

;; NOTE_INSN_LOOP_BEG
L1:	...
	Jmp L2

;; NOTE_INSN_LOOP_CONT
L2:	Jmp L1
;; NOTE_INSN_LOOP_END

Control flow optimization then starts recognizing the unconditional
branches to an unconditional branch, and jump threading redirects
all references to L2 to L1.  Finally dead code elimination spots
that L2's basic block in unreachable and deletes the basic block.
With this current mainline produces:

;; NOTE_INSN_LOOP_BEG
L1:	...
	Jmp L1

;; NOTE_INSN_LOOP_CONT
;; NOTE_INSN_LOOP_END

The NOTE_INSN_LOOP_CONT has become orphaned as it isn't deleted
when the label it annotates is destroyed.  This note is no longer
useful to the loop optimization pass, for example it isn't even
inside the loop!  This was a contributing factor in PR opt/6405.
I suspect its also the cause of problems for another patch I'm
working on.

The patch below cleans up the NOTE_INSN_LOOP_CONT notes when its
parent basic block is deleted and the label it annotates is destroyed.

This patch has survived a complete "make bootstrap" and "make -k
check" on i686-pc-linux-gnu, all languages except Ada and treelang,
with no new regressions.

Ok for mainline or the gcc-3_4-basic-improvements-branch?


2002-09-08  Roger Sayle  <roger@eyesopen.com>

	* cfgrtl.c (flow_delete_block_noexpunge): Delete orphaned
	NOTE_INSN_LOOP_CONT notes when deleting basic blocks.


Index: cfgrtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgrtl.c,v
retrieving revision 1.58
diff -c -3 -p -r1.58 cfgrtl.c
*** cfgrtl.c	21 Jun 2002 19:05:00 -0000	1.58
--- cfgrtl.c	8 Sep 2002 14:58:47 -0000
*************** flow_delete_block_noexpunge (b)
*** 360,372 ****
       and remove the associated NOTE_INSN_EH_REGION_BEG and
       NOTE_INSN_EH_REGION_END notes.  */

!   /* Get rid of all NOTE_INSN_PREDICTIONs hanging before the block.  */

    for (insn = PREV_INSN (b->head); insn; insn = PREV_INSN (insn))
      {
        if (GET_CODE (insn) != NOTE)
  	break;
!       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION)
  	NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
      }

--- 360,374 ----
       and remove the associated NOTE_INSN_EH_REGION_BEG and
       NOTE_INSN_EH_REGION_END notes.  */

!   /* Get rid of all NOTE_INSN_PREDICTIONs and NOTE_INSN_LOOP_CONTs
!      hanging before the block.  */

    for (insn = PREV_INSN (b->head); insn; insn = PREV_INSN (insn))
      {
        if (GET_CODE (insn) != NOTE)
  	break;
!       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PREDICTION
! 	  || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_CONT)
  	NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
      }


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]