public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Make cgraph frequencies more precise
@ 2015-10-12  6:07 Jan Hubicka
  2015-10-12 15:08 ` H.J. Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Hubicka @ 2015-10-12  6:07 UTC (permalink / raw)
  To: gcc-patches, dje.gcc

Hi,
this patch fixes a case of extreme imprecision I noticed while looking into
profiles of PHP interpretter. There is a function that is called 22 times
and contains the main loop.  Now since the frequency of entry block is dropped
to 0, we do not have any information of relative frequencies in the colder
areas of the function.

Hope all this uglyness with go away with conversion to sreals soonish.

Profiledbootstrapped/regtested ppc64le-linux, comitted.
	* cgraphbuild.c (compute_call_stmt_bb_frequency): Use
	counts when these are more informative.
Index: cgraphbuild.c
===================================================================
--- cgraphbuild.c	(revision 228684)
+++ cgraphbuild.c	(working copy)
@@ -202,15 +202,21 @@
 {
   int entry_freq = ENTRY_BLOCK_PTR_FOR_FN
   		     (DECL_STRUCT_FUNCTION (decl))->frequency;
-  int freq = bb->frequency;
+  gcov_type entry_count = ENTRY_BLOCK_PTR_FOR_FN
+			    (DECL_STRUCT_FUNCTION (decl))->count;
+  gcov_type freq = bb->frequency;
 
   if (profile_status_for_fn (DECL_STRUCT_FUNCTION (decl)) == PROFILE_ABSENT)
     return CGRAPH_FREQ_BASE;
 
-  if (!entry_freq)
-    entry_freq = 1, freq++;
-
-  freq = freq * CGRAPH_FREQ_BASE / entry_freq;
+  if (entry_count > entry_freq)
+    freq = RDIV (bb->count * CGRAPH_FREQ_BASE, entry_count);
+  else
+    {
+      if (!entry_freq)
+        entry_freq = 1, freq++;
+      freq = RDIV (freq * CGRAPH_FREQ_BASE, entry_freq);
+    }
   if (freq > CGRAPH_FREQ_MAX)
     freq = CGRAPH_FREQ_MAX;
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Make cgraph frequencies more precise
  2015-10-12  6:07 Make cgraph frequencies more precise Jan Hubicka
@ 2015-10-12 15:08 ` H.J. Lu
  2015-10-12 18:53   ` Jan Hubicka
  0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2015-10-12 15:08 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches, David Edelsohn

On Sun, Oct 11, 2015 at 11:07 PM, Jan Hubicka <hubicka@ucw.cz> wrote:
> Hi,
> this patch fixes a case of extreme imprecision I noticed while looking into
> profiles of PHP interpretter. There is a function that is called 22 times
> and contains the main loop.  Now since the frequency of entry block is dropped
> to 0, we do not have any information of relative frequencies in the colder
> areas of the function.
>
> Hope all this uglyness with go away with conversion to sreals soonish.
>
> Profiledbootstrapped/regtested ppc64le-linux, comitted.
>         * cgraphbuild.c (compute_call_stmt_bb_frequency): Use
>         counts when these are more informative.

This caused:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67931

-- 
H.J.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Make cgraph frequencies more precise
  2015-10-12 15:08 ` H.J. Lu
@ 2015-10-12 18:53   ` Jan Hubicka
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Hubicka @ 2015-10-12 18:53 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Jan Hubicka, GCC Patches, David Edelsohn

> On Sun, Oct 11, 2015 at 11:07 PM, Jan Hubicka <hubicka@ucw.cz> wrote:
> > Hi,
> > this patch fixes a case of extreme imprecision I noticed while looking into
> > profiles of PHP interpretter. There is a function that is called 22 times
> > and contains the main loop.  Now since the frequency of entry block is dropped
> > to 0, we do not have any information of relative frequencies in the colder
> > areas of the function.
> >
> > Hope all this uglyness with go away with conversion to sreals soonish.
> >
> > Profiledbootstrapped/regtested ppc64le-linux, comitted.
> >         * cgraphbuild.c (compute_call_stmt_bb_frequency): Use
> >         counts when these are more informative.
> 
> This caused:
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67931

Hmm, interesting it does not show on ppcle.  The problem is however obvious,
while we scale counts we get into roundoff errors that affects the new definition
of bb frequencies.  I have reverted the patch as the actual effect on generated
code should be minimal - we use counts instead of frequences when available
on all relevant places.

Honza
> 
> -- 
> H.J.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-10-12 18:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-12  6:07 Make cgraph frequencies more precise Jan Hubicka
2015-10-12 15:08 ` H.J. Lu
2015-10-12 18:53   ` Jan Hubicka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).