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]

Fix loop header duplicating code


Hi,
it is amazing, that any loop with copied header gets ignored by loop optimizer
unless the header is eliminated by cse.  The jump.c keeps jumps directly
to loop's label making loop.c to identify it as multiple entry one.

This patch should fix that.  Hope that loop.c will get converted to cfg
in 3.1, but in case...

No more multiple entry loops in my testcases.  Good.

Honza

Fri Jul 27 18:46:04 CEST 2001  Jan Hubicka  <jh@suse.cz>

	* jump.c (duplicate_loop_exit_test): Better test for jumps
	entering the loop; create loop pre_header.

Index: jump.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/jump.c,v
retrieving revision 1.187
diff -c -3 -p -r1.187 jump.c
*** jump.c	2001/07/26 20:35:58	1.187
--- jump.c	2001/07/27 16:41:45
*************** duplicate_loop_exit_test (loop_start)
*** 304,309 ****
--- 304,310 ----
    rtx lastexit;
    int max_reg = max_reg_num ();
    rtx *reg_map = 0;
+   rtx loop_pre_header_label;
  
    /* Scan the exit code.  We do not perform this optimization if any insn:
  
*************** duplicate_loop_exit_test (loop_start)
*** 404,409 ****
--- 405,411 ----
  	    reg_map[REGNO (reg)] = gen_reg_rtx (GET_MODE (reg));
  	  }
        }
+   loop_pre_header_label = gen_label_rtx ();
  
    /* Now copy each insn.  */
    for (insn = exitcode; insn != lastexit; insn = NEXT_INSN (insn))
*************** duplicate_loop_exit_test (loop_start)
*** 474,482 ****
  		  /* The jump_insn after loop_start should be followed
  		     by barrier and loopback label.  */
  		  if (prev_nonnote_insn (label)
! 		      && (PREV_INSN (prev_nonnote_insn (label))
! 			  == NEXT_INSN (loop_start)))
! 		    predict_insn_def (copy, PRED_LOOP_HEADER, TAKEN);
  		  else
  		    predict_insn_def (copy, PRED_LOOP_HEADER, NOT_TAKEN);
  		}
--- 476,489 ----
  		  /* The jump_insn after loop_start should be followed
  		     by barrier and loopback label.  */
  		  if (prev_nonnote_insn (label)
! 		      && (prev_nonnote_insn (prev_nonnote_insn (label))
! 			  == next_nonnote_insn (loop_start)))
! 		    {
! 		      predict_insn_def (copy, PRED_LOOP_HEADER, TAKEN);
! 		      /* To keep pre-header, we need to redirect all loop
! 		         entrances before the LOOP_BEG note.  */
! 		      redirect_jump (copy, loop_pre_header_label, 0);
! 		    }
  		  else
  		    predict_insn_def (copy, PRED_LOOP_HEADER, NOT_TAKEN);
  		}
*************** duplicate_loop_exit_test (loop_start)
*** 510,515 ****
--- 517,524 ----
        mark_jump_label (PATTERN (copy), copy, 0);
        emit_barrier_before (loop_start);
      }
+ 
+   emit_label_before (loop_pre_header_label, loop_start);
  
    /* Now scan from the first insn we copied to the last insn we copied
       (copy) for new pseudo registers.  Do this after the code to jump to


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