[PATCH] Improve PR12245 compile-time by 50%

Richard Guenther rguenther@suse.de
Mon Oct 3 14:40:00 GMT 2005


This simple patch causes compile-time of PR12245 to drop by 50%.
We spend nearly all compile-time in searching the large integer
cache hashtable - which has a stupid hashfn that results in an
average of 4.7 collisions per bucket for storing integers [0, n]
which happens for those large initializers.

Fixed by tweaking the hashfn down to in average 0.37 collisions.
Memory usage is unchanged (we pin down all the integers, both in
the cache and the CONSTRUCTOR).  Compile-time goes down from 16s
to 10s for an equivalent manually-crafted testcase.

The hashfn cannot be worse than before.  Btw. the extra function
call does not make a difference here, the XORs cause problems,
so does the >>3 of the type address.

Ok for mainline and 4.0?

Thanks,
Richard.


2005-03-10  Richard Guenther  <rguenther@suse.de>

	* tree.c (int_cst_hash_hash): Tweak hashfn.

Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.506
diff -c -3 -p -r1.506 tree.c
*** tree.c	3 Oct 2005 08:43:45 -0000	1.506
--- tree.c	3 Oct 2005 14:32:50 -0000
*************** int_cst_hash_hash (const void *x)
*** 712,719 ****
  {
    tree t = (tree) x;
  
!   return (TREE_INT_CST_HIGH (t) ^ TREE_INT_CST_LOW (t)
! 	  ^ htab_hash_pointer (TREE_TYPE (t)));
  }
  
  /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)
--- 712,719 ----
  {
    tree t = (tree) x;
  
!   return (TREE_INT_CST_HIGH (t) + TREE_INT_CST_LOW (t)
! 	  + (long)TREE_TYPE (t));
  }
  
  /* Return nonzero if the value represented by *X (an INTEGER_CST tree node)



More information about the Gcc-patches mailing list