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] tree-phinodes.c: Speed up PHI node allocation/resizing.


Hi,

Attached is a patch to speed up the PHI node allocation/resizing by
removing unnecessary zeroing of PHI nodes.

Whenever we allocate (or take from the free list) a PHI node, we zero
it, including the associated PHI arguments.  This is wasteful.

The patch reduces the number of bytes that are zeroed.  Specifically,
we zero only the first

  sizeof (struct tree_phi_node) - sizeof (struct phi_arg_d))

bytes of a PHI node.

The only problem with not zeroing PHI arguments is that the garbage
collector would crash by following garbage pointers in PHI arguments.
The patch prevents this problem by telling the garbage collector to
chase up to num_args PHI arguments.

Here is the timing in seconds for 3 runs of

  ./cc1plus -quiet -O2 -o /dev/null ir.ii  (from PR 13776)

      current  patched
real: 303.102  301.723 (0.454% down)
user: 297.562  296.934 (0.211% down)

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

Kazu Hirata

2004-10-28  Kazu Hirata  <kazu@cs.umass.edu>

	* tree-phinodes.c (make_phi_node, resize_phi_node): Don't zero
	the whole PHI node.
	* tree.h (tree_phi_node): Tell the garbage collector to chase
	num_args arguments.

Index: tree-phinodes.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-phinodes.c,v
retrieving revision 2.11
diff -u -d -p -r2.11 tree-phinodes.c
--- tree-phinodes.c	28 Oct 2004 14:41:05 -0000	2.11
+++ tree-phinodes.c	28 Oct 2004 16:19:53 -0000
@@ -199,7 +199,7 @@ make_phi_node (tree var, int len)
 
     }
 
-  memset (phi, 0, size);
+  memset (phi, 0, sizeof (struct tree_phi_node) - sizeof (struct phi_arg_d));
   TREE_SET_CODE (phi, PHI_NODE);
   PHI_ARG_CAPACITY (phi) = len;
   TREE_TYPE (phi) = TREE_TYPE (var);
@@ -234,7 +234,7 @@ resize_phi_node (tree *phi, int len)
 {
   int size, old_size;
   tree new_phi;
-  int i, old_len, bucket = NUM_BUCKETS - 2;
+  int bucket = NUM_BUCKETS - 2;
 
   gcc_assert (len >= PHI_ARG_CAPACITY (*phi));
 
@@ -271,16 +271,8 @@ resize_phi_node (tree *phi, int len)
 
   memcpy (new_phi, *phi, old_size);
 
-  old_len = PHI_ARG_CAPACITY (new_phi);
   PHI_ARG_CAPACITY (new_phi) = len;
 
-  for (i = old_len; i < len; i++)
-    {
-      SET_PHI_ARG_DEF (new_phi, i, NULL_TREE);
-      PHI_ARG_EDGE (new_phi, i) = NULL;
-      PHI_ARG_NONZERO (new_phi, i) = false;
-    }
-
   *phi = new_phi;
 }
 
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.641
diff -u -d -p -r1.641 tree.h
--- tree.h	27 Oct 2004 20:27:20 -0000	1.641
+++ tree.h	28 Oct 2004 16:19:55 -0000
@@ -1407,7 +1407,7 @@ struct tree_phi_node GTY(())
   /* Dataflow information.  */
   struct dataflow_d *df;
 
-  struct phi_arg_d GTY ((length ("((tree)&%h)->phi.capacity"))) a[1];
+  struct phi_arg_d GTY ((length ("((tree)&%h)->phi.num_args"))) a[1];
 };
 
 


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