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] passes.c: Run CSE only once after GCSE instead of twice ormore.


Hi,

Attached is a patch to run CSE only once after GCSE instead of twice
or more.

The motivation here is of course compile time improvement.  Note that
rest_of_handle_gcse calls so many mini passes after calling gcse_main.
The problem is that some of them aren't effective.

All of the following observations were gathered while compiling cc1-i
files.

1. The "while" loop shown in the patch never iterated more than once.

2. cleanup_cfg did some work 131 times out of 5377 calls from
   rest_of_handle_gcse.

3. cse_main, to be removed by this patch, always returned 0, meaning
   that no conditonal jumps were changed to unconditonal ones or fall
   through.  Note that this is the reason for #1 above.

4. We are effectively running delete_trivially_dead_insn twice in a
   row if this cse_main doesn't modify the instruction stream.  This
   is less obvious, but let me explain.  If cleanup_cfg does
   something, it always runs d_t_d_i before returning to its caller.
   Otherwise, we call d_t_d_i a few lines up in rest_of_handle_gcse.
   Note that recently I emperically showed that iterating d_t_d_i did
   not help remove more insns.

5. purge_all_dead_edges always returned 0.

6. d_t_d_i here removed only 1 insn.

7. The best part of the story - there was no difference in the generated
   assembly code with or without my patch.  This was also true when I
   tried preprocessed files from the Linux kernel.

The patch changes the "while" loop to an "if" statement and removes
those mini passes that are not effective.

Here is a timing in second of compiling cc1-i files with ./cc1 -quiet
-O2.

              original patched   diff%
c-common.i      18.272  17.905 -2.008%
combine.i       17.471  17.084 -2.215%
fold-const.i    37.927  37.256 -1.769%
insn-attrtab.i 168.136 166.172 -1.168%
reload1.i       14.598  13.834 -5.233%
reload.i        13.345  13.036 -2.315%
cc1-i files    211.177 207.943 -1.531%

cc1-i files were compiled only once.mini

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2005-02-10  Kazu Hirata  <kazu@cs.umass.edu>

	* passes.c (rest_of_handle_gcse): Don't run cse_main and
	delete_trivially_dead_insns too many times.

Index: passes.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/passes.c,v
retrieving revision 2.65
diff -u -d -p -r2.65 passes.c
--- passes.c	1 Feb 2005 10:03:09 -0000	2.65
+++ passes.c	10 Feb 2005 02:46:59 -0000
@@ -1049,23 +1049,13 @@ rest_of_handle_gcse (void)
 
   /* If gcse or cse altered any jumps, rerun jump optimizations to clean
      things up.  Then possibly re-run CSE again.  */
-  while (tem || tem2)
+  if (tem || tem2)
     {
       tem = tem2 = 0;
       timevar_push (TV_JUMP);
       rebuild_jump_labels (get_insns ());
       cleanup_cfg (CLEANUP_EXPENSIVE | CLEANUP_PRE_LOOP);
       timevar_pop (TV_JUMP);
-
-      if (flag_expensive_optimizations)
-	{
-	  timevar_push (TV_CSE);
-	  reg_scan (get_insns (), max_reg_num ());
-	  tem2 = cse_main (get_insns (), max_reg_num (), dump_file);
-	  purge_all_dead_edges (0);
-	  delete_trivially_dead_insns (get_insns (), max_reg_num ());
-	  timevar_pop (TV_CSE);
-	}
     }
 
   close_dump_file (DFI_gcse, print_rtl_with_bb, get_insns ());


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