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]

loop.c BCT fix


	Can I install the following patch which is a beginning at fixing
the branch on counter optimization?  There still is some more subtle
problem, but this fixes the most significant failure.

Thanks, David

	* toplev.c (rest_of_compilation): Set bct_p on second call to
	loop_optimize.
	* loop.c (loop_optimize, scan_loop, strength_reduce): New argument
	bct_p.
	(strength_reduce): Only call analyze_loop_iterations and
	insert_bct if bct_p set.
	(check_dbra_loop): Fix typo.
	(insert_bct, instrument_loop_bct): Use word_mode instead of SImode.
	* rtl.h (loop_optimize): Update prototype.

Index: toplev.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/toplev.c,v
retrieving revision 1.94
diff -c -p -r1.94 toplev.c
*** toplev.c	1998/09/10 00:40:19	1.94
--- toplev.c	1998/09/13 03:00:32
*************** rest_of_compilation (decl)
*** 3519,3525 ****
  	     {
  	       /* We only want to perform unrolling once.  */
  	       
! 	       loop_optimize (insns, rtl_dump_file, 0);
  	       
  	
  	       /* The first call to loop_optimize makes some instructions
--- 3519,3525 ----
  	     {
  	       /* We only want to perform unrolling once.  */
  	       
! 	       loop_optimize (insns, rtl_dump_file, 0, 0);
  	       
  	
  	       /* The first call to loop_optimize makes some instructions
*************** rest_of_compilation (decl)
*** 3532,3538 ****
  		  analysis code depends on this information.  */
  	       reg_scan (insns, max_reg_num (), 1);
  	     }
! 	   loop_optimize (insns, rtl_dump_file, flag_unroll_loops);
  	 });
        
        /* Dump rtl code after loop opt, if we are doing that.  */
--- 3532,3538 ----
  		  analysis code depends on this information.  */
  	       reg_scan (insns, max_reg_num (), 1);
  	     }
! 	   loop_optimize (insns, rtl_dump_file, flag_unroll_loops, 1);
  	 });
        
        /* Dump rtl code after loop opt, if we are doing that.  */
Index: loop.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/loop.c,v
retrieving revision 1.75
diff -c -p -r1.75 loop.c
*** loop.c	1998/09/09 13:15:23	1.75
--- loop.c	1998/09/13 03:00:33
*************** static void count_loop_regs_set PROTO((r
*** 310,316 ****
  				       int *, int)); 
  static void note_addr_stored PROTO((rtx, rtx));
  static int loop_reg_used_before_p PROTO((rtx, rtx, rtx, rtx, rtx));
! static void scan_loop PROTO((rtx, rtx, int));
  #if 0
  static void replace_call_address PROTO((rtx, rtx, rtx));
  #endif
--- 310,316 ----
  				       int *, int)); 
  static void note_addr_stored PROTO((rtx, rtx));
  static int loop_reg_used_before_p PROTO((rtx, rtx, rtx, rtx, rtx));
! static void scan_loop PROTO((rtx, rtx, int, int));
  #if 0
  static void replace_call_address PROTO((rtx, rtx, rtx));
  #endif
*************** static int rtx_equal_for_loop_p PROTO((r
*** 324,330 ****
  static void add_label_notes PROTO((rtx, rtx));
  static void move_movables PROTO((struct movable *, int, int, rtx, rtx, int));
  static int count_nonfixed_reads PROTO((rtx));
! static void strength_reduce PROTO((rtx, rtx, rtx, int, rtx, rtx, int));
  static void find_single_use_in_loop PROTO((rtx, rtx, varray_type));
  static int valid_initial_value_p PROTO((rtx, rtx, int, rtx));
  static void find_mem_givs PROTO((rtx, rtx, int, rtx, rtx));
--- 324,330 ----
  static void add_label_notes PROTO((rtx, rtx));
  static void move_movables PROTO((struct movable *, int, int, rtx, rtx, int));
  static int count_nonfixed_reads PROTO((rtx));
! static void strength_reduce PROTO((rtx, rtx, rtx, int, rtx, rtx, int, int));
  static void find_single_use_in_loop PROTO((rtx, rtx, varray_type));
  static int valid_initial_value_p PROTO((rtx, rtx, int, rtx));
  static void find_mem_givs PROTO((rtx, rtx, int, rtx, rtx));
*************** init_loop ()
*** 440,450 ****
     (or 0 if none should be output).  */
  
  void
! loop_optimize (f, dumpfile, unroll_p)
       /* f is the first instruction of a chain of insns for one function */
       rtx f;
       FILE *dumpfile;
!      int unroll_p;
  {
    register rtx insn;
    register int i;
--- 440,450 ----
     (or 0 if none should be output).  */
  
  void
! loop_optimize (f, dumpfile, unroll_p, bct_p)
       /* f is the first instruction of a chain of insns for one function */
       rtx f;
       FILE *dumpfile;
!      int unroll_p, bct_p;
  {
    register rtx insn;
    register int i;
*************** loop_optimize (f, dumpfile, unroll_p)
*** 589,595 ****
    for (i = max_loop_num-1; i >= 0; i--)
      if (! loop_invalid[i] && loop_number_loop_ends[i])
        scan_loop (loop_number_loop_starts[i], loop_number_loop_ends[i],
! 		 unroll_p);
  
    /* If debugging and unrolling loops, we must replicate the tree nodes
       corresponding to the blocks inside the loop, so that the original one
--- 589,595 ----
    for (i = max_loop_num-1; i >= 0; i--)
      if (! loop_invalid[i] && loop_number_loop_ends[i])
        scan_loop (loop_number_loop_starts[i], loop_number_loop_ends[i],
! 		 unroll_p, bct_p);
  
    /* If debugging and unrolling loops, we must replicate the tree nodes
       corresponding to the blocks inside the loop, so that the original one
*************** next_insn_in_loop (insn, start, end, loo
*** 643,651 ****
     write, then we can also mark the memory read as invariant.  */
  
  static void
! scan_loop (loop_start, end, unroll_p)
       rtx loop_start, end;
!      int unroll_p;
  {
    register int i;
    rtx p;
--- 643,651 ----
     write, then we can also mark the memory read as invariant.  */
  
  static void
! scan_loop (loop_start, end, unroll_p, bct_p)
       rtx loop_start, end;
!      int unroll_p, bct_p;
  {
    register int i;
    rtx p;
*************** scan_loop (loop_start, end, unroll_p)
*** 1185,1191 ****
      {
        the_movables = movables;
        strength_reduce (scan_start, end, loop_top,
! 		       insn_count, loop_start, end, unroll_p);
      }
  
    VARRAY_FREE (n_times_set);
--- 1185,1191 ----
      {
        the_movables = movables;
        strength_reduce (scan_start, end, loop_top,
! 		       insn_count, loop_start, end, unroll_p, bct_p);
      }
  
    VARRAY_FREE (n_times_set);
*************** static rtx addr_placeholder;
*** 3562,3575 ****
  
  static void
  strength_reduce (scan_start, end, loop_top, insn_count,
! 		 loop_start, loop_end, unroll_p)
       rtx scan_start;
       rtx end;
       rtx loop_top;
       int insn_count;
       rtx loop_start;
       rtx loop_end;
!      int unroll_p;
  {
    rtx p;
    rtx set;
--- 3562,3575 ----
  
  static void
  strength_reduce (scan_start, end, loop_top, insn_count,
! 		 loop_start, loop_end, unroll_p, bct_p)
       rtx scan_start;
       rtx end;
       rtx loop_top;
       int insn_count;
       rtx loop_start;
       rtx loop_end;
!      int unroll_p, bct_p;
  {
    rtx p;
    rtx set;
*************** strength_reduce (scan_start, end, loop_t
*** 4089,4095 ****
       the loop.  Unrolling may update part of this information, and the
       correct data will be used for generating the BCT.  */
  #ifdef HAVE_decrement_and_branch_on_count
!   if (HAVE_decrement_and_branch_on_count)
      analyze_loop_iterations (loop_start, loop_end);
  #endif
  #endif  /* HAIFA */
--- 4089,4095 ----
       the loop.  Unrolling may update part of this information, and the
       correct data will be used for generating the BCT.  */
  #ifdef HAVE_decrement_and_branch_on_count
!   if (HAVE_decrement_and_branch_on_count && bct_p)
      analyze_loop_iterations (loop_start, loop_end);
  #endif
  #endif  /* HAIFA */
*************** strength_reduce (scan_start, end, loop_t
*** 4596,4602 ****
  #ifdef HAIFA
    /* instrument the loop with bct insn */
  #ifdef HAVE_decrement_and_branch_on_count
!   if (HAVE_decrement_and_branch_on_count)
      insert_bct (loop_start, loop_end);
  #endif
  #endif  /* HAIFA */
--- 4596,4602 ----
  #ifdef HAIFA
    /* instrument the loop with bct insn */
  #ifdef HAVE_decrement_and_branch_on_count
!   if (HAVE_decrement_and_branch_on_count && bct_p)
      insert_bct (loop_start, loop_end);
  #endif
  #endif  /* HAIFA */
*************** check_dbra_loop (loop_end, insn_count, l
*** 6964,6970 ****
  		  /* If we have a decrement_and_branch_on_count, prefer
  		     the NE test, since this will allow that instruction to
  		     be generated.  */
! #if ! defined (HAVE_decrement_and_branch_on_zero) && defined (HAVE_decrement_and_branch_on_count)
  		  && (add_val != 1 || ! vtop)
  #endif
  		  && GET_CODE (comparison_value) == CONST_INT
--- 6964,6970 ----
  		  /* If we have a decrement_and_branch_on_count, prefer
  		     the NE test, since this will allow that instruction to
  		     be generated.  */
! #if ! defined (HAVE_decrement_and_branch_until_zero) && defined (HAVE_decrement_and_branch_on_count)
  		  && (add_val != 1 || ! vtop)
  #endif
  		  && GET_CODE (comparison_value) == CONST_INT
*************** insert_bct (loop_start, loop_end)
*** 8172,8178 ****
  
    /* the only machine mode we work with - is the integer of the size that the
       machine has */
!   enum machine_mode loop_var_mode = SImode;
  
    int loop_num = uid_loop_num [INSN_UID (loop_start)];
  
--- 8172,8178 ----
  
    /* the only machine mode we work with - is the integer of the size that the
       machine has */
!   enum machine_mode loop_var_mode = word_mode;
  
    int loop_num = uid_loop_num [INSN_UID (loop_start)];
  
*************** instrument_loop_bct (loop_start, loop_en
*** 8442,8448 ****
    rtx start_label;
  
    rtx sequence;
!   enum machine_mode loop_var_mode = SImode;
  
    if (HAVE_decrement_and_branch_on_count)
      {
--- 8442,8448 ----
    rtx start_label;
  
    rtx sequence;
!   enum machine_mode loop_var_mode = word_mode;
  
    if (HAVE_decrement_and_branch_on_count)
      {
Index: rtl.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/rtl.h,v
retrieving revision 1.50
diff -c -p -r1.50 rtl.h
*** rtl.h	1998/09/06 05:56:18	1.50
--- rtl.h	1998/09/13 03:00:33
*************** extern void print_inline_rtx		PROTO ((FI
*** 1339,1345 ****
  /* In loop.c */
  extern void init_loop			PROTO ((void));
  #ifdef BUFSIZ
! extern void loop_optimize		PROTO ((rtx, FILE *, int));
  #endif
  extern void record_excess_regs		PROTO ((rtx, rtx, rtx *));
  
--- 1339,1345 ----
  /* In loop.c */
  extern void init_loop			PROTO ((void));
  #ifdef BUFSIZ
! extern void loop_optimize		PROTO ((rtx, FILE *, int, int));
  #endif
  extern void record_excess_regs		PROTO ((rtx, rtx, rtx *));
  


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