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]

Re: [PATCH][2/2] Fix expansion slowness of PR60291


On Fri, 21 Feb 2014, Richard Biener wrote:

> On Fri, 21 Feb 2014, Richard Biener wrote:
> 
> > Last statistics: http://gcc.gnu.org/ml/gcc-patches/2011-08/msg01784.html
> 
> With the patch below to get some statistics we see that one important
> piece of sharing not covered by above measurements is RTX copying(?).
> 
> On the testcase for this PR I get at -O1 and without the patch
> to clear the hashtable after each function
> 
> 142489 mem_attrs created (142439 for new, 50 for modification)
> 1983225 mem_attrs shared (4044 for new, 820241 for modification, 1158940 
> by rtx copying)
> 0 mem_attrs dropped
> 
> and with the patch to clear after each function
> 
> 364411 mem_attrs created (144478 for new, 219933 for modification)
> 1761303 mem_attrs shared (2005 for new, 600358 for modification, 1158940 
> by rtx copying)
> 0 mem_attrs dropped
> 
> while for dwarf2out.c I see without the clearing
> 
> 24399 mem_attrs created (6929 for new, 17470 for modification)
> 102676 mem_attrs shared (10878 for new, 29265 for modification, 62533 by 
> rtx copying)
> 16 mem_attrs dropped

Oh, and more than half of shared-modified are actually not modified
so are false sharing reports (set_mem_attrs (mem, MEM_ATTRS (mem))).

24399 mem_attrs created (6929 for new, 17470 for modification)
85801 mem_attrs shared (10878 for new, 12390 for modification, 62533 by 
rtx copying)
16 mem_attrs dropped

when dropping sharing completely you "win" creations for modification
but lose shares for "new" and "copy".  Losing the "copy" case makes
it a loss overall which you can eventually offset by using a ref-counting
scheme (or better by avoiding copying the MEM in the first place,
a MEM is currently 24 bytes while its attrs are 40 bytes).

Richard.

Index: gcc/rtl.c
===================================================================
--- gcc/rtl.c	(revision 207938)
+++ gcc/rtl.c	(working copy)
@@ -326,6 +326,8 @@ copy_rtx (rtx orig)
   return copy;
 }
 
+unsigned long mem_attrs_shared_copy;
+
 /* Create a new copy of an rtx.  Only copy just one level.  */
 
 rtx
@@ -333,6 +335,8 @@ shallow_copy_rtx_stat (const_rtx orig ME
 {
   const unsigned int size = rtx_size (orig);
   rtx const copy = ggc_alloc_rtx_def_stat (size PASS_MEM_STAT);
+  if (MEM_P (orig) && MEM_ATTRS (orig))
+    mem_attrs_shared_copy++;
   return (rtx) memcpy (copy, orig, size);
 }
 
Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c	(revision 207938)
+++ gcc/emit-rtl.c	(working copy)
@@ -290,6 +290,12 @@ mem_attrs_htab_eq (const void *x, const
   return mem_attrs_eq_p ((const mem_attrs *) x, (const mem_attrs *) y);
 }
 
+unsigned long mem_attrs_dropped;
+unsigned long mem_attrs_new;
+unsigned long mem_attrs_new_modified;
+unsigned long mem_attrs_shared;
+unsigned long mem_attrs_shared_modified;
+
 /* Set MEM's memory attributes so that they are the same as ATTRS.  */
 
 static void
@@ -300,6 +306,8 @@ set_mem_attrs (rtx mem, mem_attrs *attrs
   /* If everything is the default, we can just clear the attributes.  */
   if (mem_attrs_eq_p (attrs, mode_mem_attrs[(int) GET_MODE (mem)]))
     {
+      if (MEM_ATTRS (mem))
+	mem_attrs_dropped++;
       MEM_ATTRS (mem) = 0;
       return;
     }
@@ -309,6 +317,20 @@ set_mem_attrs (rtx mem, mem_attrs *attrs
     {
       *slot = ggc_alloc_mem_attrs ();
       memcpy (*slot, attrs, sizeof (mem_attrs));
+      if (MEM_ATTRS (mem))
+	mem_attrs_new_modified++;
+      else
+	mem_attrs_new++;
+    }
+  else
+    {
+      if (MEM_ATTRS (mem))
+	{
+	  if (MEM_ATTRS (mem) != *slot)
+	    mem_attrs_shared_modified++;
+	}
+      else
+	mem_attrs_shared++;
     }
 
   MEM_ATTRS (mem) = (mem_attrs *) *slot;
Index: gcc/toplev.c
===================================================================
--- gcc/toplev.c	(revision 207938)
+++ gcc/toplev.c	(working copy)
@@ -1989,6 +2023,26 @@ toplev_main (int argc, char **argv)
   if (!exit_after_options)
     do_compile ();
 
+    {
+      extern unsigned long mem_attrs_dropped;
+      extern unsigned long mem_attrs_new;
+      extern unsigned long mem_attrs_new_modified;
+      extern unsigned long mem_attrs_shared;
+      extern unsigned long mem_attrs_shared_modified;
+      extern unsigned long mem_attrs_shared_copy;
+      fprintf (stderr, "%lu mem_attrs created (%lu for new, %lu for "
+	       "modification)\n",
+	       mem_attrs_new + mem_attrs_new_modified,
+	       mem_attrs_new, mem_attrs_new_modified);
+      fprintf (stderr, "%lu mem_attrs shared (%lu for new, %lu for "
+	       "modification, %lu by rtx copying)\n",
+	       mem_attrs_shared + mem_attrs_shared_modified
+	       + mem_attrs_shared_copy,
+	       mem_attrs_shared, mem_attrs_shared_modified,
+	       mem_attrs_shared_copy);
+      fprintf (stderr, "%lu mem_attrs dropped\n", mem_attrs_dropped);
+    }
+
   if (warningcount || errorcount || werrorcount)
     print_ignored_options ();
 


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