[patches] messing up loop notes again

Jan Hubicka jh@suse.cz
Thu Jul 26 12:29:00 GMT 2001


> Hi,
> After some investigation I've found that vast majority of situations
> we mess up the loop notes is that we want to redirect the fallthru
> edge entering loop (eighter for edge splitting or jump optimization).
> 
> To redirect properly, we must move loop_beg note before the newly created
> unconditional branch, as loop optimizer expects it to be there.
> 
> This replaces my "avoid messing up loop notes 2" patches.  The #3 patch
> is still relevant.
> 
> With combination of these two patches I get no loop optimizer failures
> on combine.c
> 
> Bootstrapped/regtested i686; requires the barriers patch to survive.
> 
> Honza
Oops, I am getting crazy - I've sent wrong file

Thu Jul 26 21:27:39 CEST 2001  Jan Hubicka  <jh@suse.cz>
	* flow.c (last_loop_beg_note): New function.
	(redirect_edge_and_branch): Use it.
	(split_edge): Likewise.

Index: flow.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flow.c,v
retrieving revision 1.442
diff -c -3 -p -r1.442 flow.c
*** flow.c	2001/07/25 20:51:24	1.442
--- flow.c	2001/07/26 19:18:21
*************** try_redirect_by_replacing_jump (e, targe
*** 1747,1752 ****
--- 1747,1776 ----
    return true;
  }
  
+ /* Return last loop_beg note appearing after INSN, before start of next
+    basic block.  Return INSN if there are no such notes.
+ 
+    When emmiting jump to redirect an fallthru edge, it should always
+    appear after the LOOP_BEG notes, as loop optimizer expect loop to
+    eighter start by fallthru edge or jump following the LOOP_BEG note
+    jumping to the loop exit test.
+  */
+ rtx
+ last_loop_beg_note (insn)
+      rtx insn;
+ {
+   rtx last = insn;
+   insn = NEXT_INSN (insn);
+   while (GET_CODE (insn) == NOTE
+ 	 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK)
+     {
+       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
+ 	last = insn;
+       insn = NEXT_INSN (insn);
+     }
+   return last;
+ }
+ 
  /* Attempt to change code to redirect edge E to TARGET.
     Don't do that on expense of adding new instructions or reordering
     basic blocks.
*************** redirect_edge_and_branch_force (e, targe
*** 1876,1882 ****
    /* Case of the fallthru block.  */
    if (!e->src->succ->succ_next)
      {
!       e->src->end = emit_jump_insn_after (gen_jump (label), e->src->end);
        JUMP_LABEL (e->src->end) = label;
        LABEL_NUSES (label)++;
        if (basic_block_for_insn)
--- 1901,1908 ----
    /* Case of the fallthru block.  */
    if (!e->src->succ->succ_next)
      {
!       e->src->end = emit_jump_insn_after (gen_jump (label),
! 					  last_loop_beg_note (e->src->end));
        JUMP_LABEL (e->src->end) = label;
        LABEL_NUSES (label)++;
        if (basic_block_for_insn)
*************** redirect_edge_and_branch_force (e, targe
*** 1905,1911 ****
  
    memset (new_bb, 0, sizeof (*new_bb));
  
!   new_bb->end = new_bb->head = e->src->end;
    new_bb->succ = NULL;
    new_bb->pred = new_edge;
    new_bb->count = e->count;
--- 1931,1937 ----
  
    memset (new_bb, 0, sizeof (*new_bb));
  
!   new_bb->end = new_bb->head = last_loop_beg_note (e->src->end);
    new_bb->succ = NULL;
    new_bb->pred = new_edge;
    new_bb->count = e->count;
*************** split_edge (edge_in)
*** 2063,2069 ****
  
  	  /* Now add the jump insn ...  */
  	  pos = emit_jump_insn_after (gen_jump (old_succ->head),
! 				      jump_block->end);
  	  jump_block->end = pos;
  	  if (basic_block_for_insn)
  	    set_block_for_new_insns (pos, jump_block);
--- 2089,2095 ----
  
  	  /* Now add the jump insn ...  */
  	  pos = emit_jump_insn_after (gen_jump (old_succ->head),
! 				      last_loop_beg_note (jump_block->end));
  	  jump_block->end = pos;
  	  if (basic_block_for_insn)
  	    set_block_for_new_insns (pos, jump_block);



More information about the Gcc-patches mailing list