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 optimizer and barriers


Hi,
inspired by the last bugfix for loop.c and having other loop unrolling
failurs, I've started checking unroller code for similar problems
(expecting exactly one barrier exactly after an insn) and the loop
optimizer is having too many places where he assumes so to make
it parctical to fix it.

So I suggest following simple pass to put the barriers to "proper"
places called before the loop optimizer (and before final, as
machine dependent reorgs may have similar assumption).  Rest of
compiler should more or less rely on CFG and be independent on that.
I've checked cse and reload.

It has fixed an latent failure in spec2000 twolf test and loop unrolling.
AJ: I am not sure this is the last one.

Testing i686. OK assuming it suceeds?

Thu Jul 26 20:50:52 CEST 2001  Jan Hubicka  <jh@suse.cz>
	* rtl.h (cleanup_barriers): Declare.
	* jump.c (cleanup_barriers): New function.
	* toplev.c (rest_of_compilation): Call cleanup_barriers
	before loop optimizer and after bb_reorder.

Index: rtl.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/rtl.h,v
retrieving revision 1.278
diff -c -3 -p -r1.278 rtl.h
*** rtl.h	2001/07/24 18:34:06	1.278
--- rtl.h	2001/07/26 18:50:15
*************** extern enum rtx_code swap_condition	PARA
*** 1286,1291 ****
--- 1286,1292 ----
  extern enum rtx_code unsigned_condition	PARAMS ((enum rtx_code));
  extern enum rtx_code signed_condition	PARAMS ((enum rtx_code));
  extern void mark_jump_label		PARAMS ((rtx, rtx, int));
+ extern void cleanup_barriers		PARAMS ((void));
  
  /* In jump.c */
  extern rtx squeeze_notes		PARAMS ((rtx, rtx));
Index: jump.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/jump.c,v
retrieving revision 1.186
diff -c -3 -p -r1.186 jump.c
*** jump.c	2001/07/22 19:34:12	1.186
--- jump.c	2001/07/26 18:50:16
*************** rebuild_jump_labels (f)
*** 100,105 ****
--- 100,127 ----
        LABEL_NUSES (XEXP (insn, 0))++;
  }
  
+ /* Some of the old code expect exactly barrier to appear as next insns after an
+    JUMP_INSN.  This is not generally true, so look trought the insn stream,
+    move the barriers to the insns causing them and remove duplicated barriers.
+  */
+ void
+ cleanup_barriers ()
+ {
+   rtx insn, next, prev;
+   for (insn = get_insns (); insn; insn = next)
+     {
+       next = NEXT_INSN (insn);
+       if (GET_CODE (insn) == BARRIER)
+ 	{
+ 	  prev = prev_nonnote_insn (insn);
+ 	  if (GET_CODE (prev) == BARRIER)
+ 	    delete_barrier (insn);
+ 	  else if (prev != PREV_INSN (insn))
+ 	    reorder_insns (insn, insn, prev);
+ 	}
+     }
+ }
+ 
  void
  copy_loop_headers (f)
       rtx f;
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/toplev.c,v
retrieving revision 1.499
diff -c -3 -p -r1.499 toplev.c
*** toplev.c	2001/07/26 06:56:12	1.499
--- toplev.c	2001/07/26 18:50:17
*************** rest_of_compilation (decl)
*** 3096,3101 ****
--- 3096,3103 ----
  
        if (flag_rerun_loop_opt)
  	{
+ 	  cleanup_barriers ();
+ 
  	  /* We only want to perform unrolling once.  */
  
  	  loop_optimize (insns, rtl_dump_file, 0);
*************** rest_of_compilation (decl)
*** 3110,3115 ****
--- 3112,3118 ----
  		  analysis code depends on this information.  */
  	  reg_scan (insns, max_reg_num (), 1);
  	}
+       cleanup_barriers ();
        loop_optimize (insns, rtl_dump_file,
  		     (flag_unroll_loops ? LOOP_UNROLL : 0) | LOOP_BCT);
  
*************** rest_of_compilation (decl)
*** 3614,3619 ****
--- 3617,3623 ----
    /* CFG no longer kept up to date.  */
  
    purge_line_number_notes (insns);
+   cleanup_barriers ();
  
    /* If a scheduling pass for delayed branches is to be done,
       call the scheduling code.  */


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