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] Remove loop notes (3/8) -- cfg manipulation


Hello,

there is some code in cfgrtl.c that ensures that loop notes are
preserved.  With the loop notes going to disappear, this code
is not useful any more, and this patch removes it.

Bootstrapped & regtested on i686.

Zdenek

	* cfgrtl.c (last_loop_beg_note, back_edge_of_syntactic_loop_p):
	Removed.
	(force_nonfallthru_and_redirect): Do not use last_loop_beg_note.
	(rtl_split_edge): Do not use back_edge_of_syntactic_loop_p.
	(commit_one_edge_insertion): Do not look for loop notes.

Index: cfgrtl.c
===================================================================
*** cfgrtl.c	(revision 111675)
--- cfgrtl.c	(working copy)
*************** Software Foundation, 51 Franklin Street,
*** 64,71 ****
  static int can_delete_note_p (rtx);
  static int can_delete_label_p (rtx);
  static void commit_one_edge_insertion (edge, int);
- static rtx last_loop_beg_note (rtx);
- static bool back_edge_of_syntactic_loop_p (basic_block, basic_block);
  static basic_block rtl_split_edge (edge);
  static bool rtl_move_block_after (basic_block, basic_block);
  static int rtl_verify_flow_info (void);
--- 64,69 ----
*************** try_redirect_by_replacing_jump (edge e, 
*** 861,888 ****
    return e;
  }
  
- /* Return last loop_beg note appearing after INSN, before start of next
-    basic block.  Return INSN if there are no such notes.
- 
-    When emitting jump to redirect a fallthru edge, it should always appear
-    after the LOOP_BEG notes, as loop optimizer expect loop to either start by
-    fallthru edge or jump following the LOOP_BEG note jumping to the loop exit
-    test.  */
- 
- static rtx
- last_loop_beg_note (rtx insn)
- {
-   rtx last = insn;
- 
-   for (insn = NEXT_INSN (insn); insn && NOTE_P (insn)
-        && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK;
-        insn = NEXT_INSN (insn))
-     if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
-       last = insn;
- 
-   return last;
- }
- 
  /* Redirect edge representing branch of (un)conditional jump or tablejump,
     NULL on failure  */
  static edge
--- 859,864 ----
*************** force_nonfallthru_and_redirect (edge e, 
*** 1100,1108 ****
  	 forward from the last instruction of the old block.  */
        if (!tablejump_p (BB_END (e->src), NULL, &note))
  	note = BB_END (e->src);
- 
-       /* Position the new block correctly relative to loop notes.  */
-       note = last_loop_beg_note (note);
        note = NEXT_INSN (note);
  
        jump_block = create_basic_block (note, NULL, e->src);
--- 1076,1081 ----
*************** rtl_tidy_fallthru_edge (edge e)
*** 1254,1293 ****
    e->flags |= EDGE_FALLTHRU;
  }
  
- /* Helper function for split_edge.  Return true in case edge BB2 to BB1
-    is back edge of syntactic loop.  */
- 
- static bool
- back_edge_of_syntactic_loop_p (basic_block bb1, basic_block bb2)
- {
-   rtx insn;
-   int count = 0;
-   basic_block bb;
- 
-   if (bb1 == bb2)
-     return true;
- 
-   /* ??? Could we guarantee that bb indices are monotone, so that we could
-      just compare them?  */
-   for (bb = bb1; bb && bb != bb2; bb = bb->next_bb)
-     continue;
- 
-   if (!bb)
-     return false;
- 
-   for (insn = BB_END (bb1); insn != BB_HEAD (bb2) && count >= 0;
-        insn = NEXT_INSN (insn))
-     if (NOTE_P (insn))
-       {
- 	if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
- 	  count++;
- 	else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
- 	  count--;
-       }
- 
-   return count >= 0;
- }
- 
  /* Should move basic block BB after basic block AFTER.  NIY.  */
  
  static bool
--- 1227,1232 ----
*************** rtl_split_edge (edge edge_in)
*** 1328,1359 ****
  	force_nonfallthru (e);
      }
  
!   /* Create the basic block note.
! 
!      Where we place the note can have a noticeable impact on the generated
!      code.  Consider this cfg:
! 
! 		        E
! 			|
! 			0
! 		       / \
! 		   +->1-->2--->E
!                    |  |
! 		   +--+
! 
!       If we need to insert an insn on the edge from block 0 to block 1,
!       we want to ensure the instructions we insert are outside of any
!       loop notes that physically sit between block 0 and block 1.  Otherwise
!       we confuse the loop optimizer into thinking the loop is a phony.  */
! 
!   if (edge_in->dest != EXIT_BLOCK_PTR
!       && PREV_INSN (BB_HEAD (edge_in->dest))
!       && NOTE_P (PREV_INSN (BB_HEAD (edge_in->dest)))
!       && (NOTE_LINE_NUMBER (PREV_INSN (BB_HEAD (edge_in->dest)))
! 	  == NOTE_INSN_LOOP_BEG)
!       && !back_edge_of_syntactic_loop_p (edge_in->dest, edge_in->src))
!     before = PREV_INSN (BB_HEAD (edge_in->dest));
!   else if (edge_in->dest != EXIT_BLOCK_PTR)
      before = BB_HEAD (edge_in->dest);
    else
      before = NULL_RTX;
--- 1267,1274 ----
  	force_nonfallthru (e);
      }
  
!   /* Create the basic block note.  */
!   if (edge_in->dest != EXIT_BLOCK_PTR)
      before = BB_HEAD (edge_in->dest);
    else
      before = NULL_RTX;
*************** rtl_split_edge (edge edge_in)
*** 1363,1372 ****
    if (edge_in->flags & EDGE_FALLTHRU && edge_in->dest == EXIT_BLOCK_PTR)
      {
        before = NEXT_INSN (BB_END (edge_in->src));
-       if (before
- 	  && NOTE_P (before)
- 	  && NOTE_LINE_NUMBER (before) == NOTE_INSN_LOOP_END)
- 	before = NEXT_INSN (before);
        bb = create_basic_block (before, NULL, edge_in->src);
        BB_COPY_PARTITION (bb, edge_in->src);
      }
--- 1278,1283 ----
*************** commit_one_edge_insertion (edge e, int w
*** 1596,1606 ****
  	     We know this block has a single successor, so we can just emit
  	     the queued insns before the jump.  */
  	  if (JUMP_P (BB_END (bb)))
! 	    for (before = BB_END (bb);
! 		 NOTE_P (PREV_INSN (before))
! 		 && NOTE_LINE_NUMBER (PREV_INSN (before)) ==
! 		 NOTE_INSN_LOOP_BEG; before = PREV_INSN (before))
! 	      ;
  	  else
  	    {
  	      /* We'd better be fallthru, or we've lost track of
--- 1507,1513 ----
  	     We know this block has a single successor, so we can just emit
  	     the queued insns before the jump.  */
  	  if (JUMP_P (BB_END (bb)))
! 	    before = BB_END (bb);
  	  else
  	    {
  	      /* We'd better be fallthru, or we've lost track of


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