public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: gcc-patches@gcc.gnu.org
Subject: Make profile update in inlining more robust
Date: Fri, 16 Jun 2017 11:46:00 -0000	[thread overview]
Message-ID: <20170616114641.GB6166@kam.mff.cuni.cz> (raw)

Hi,
when inlining last copy of function, we assume that the counts are already correct,
because all other execution paths has been inlined earlier.  While this is true in
simple cases of static functions, it can be wrong for comdats where we optimize
out the last copy but during training run we may have collected execution counts
from other units.  This could then resuit in quite large profile inconsistencies
and thus it is better to fix.

Of course this is not perfect if some offline copy of function is later produced,
because that one will have zero counts.  I do not think there is easy solution
for this problem except for LTO or possibly arranging profile counts of different
copies of same comdat to be shared which we don't have infrastructure for.

Bootstrapped/regtested x86_64-linux,
comitted.

Honza

	* ipa-inline-transform.c (update_noncloned_frequencies): Update also
	counts.
	(clone_inlined_nodes): Update.
Index: ipa-inline-transform.c
===================================================================
--- ipa-inline-transform.c	(revision 249227)
+++ ipa-inline-transform.c	(working copy)
@@ -54,10 +54,12 @@ int nfunctions_inlined;
 /* Scale frequency of NODE edges by FREQ_SCALE.  */
 
 static void
-update_noncloned_frequencies (struct cgraph_node *node,
-			      int freq_scale)
+update_noncloned_frequencies (struct cgraph_node *node, 
+			      int freq_scale, profile_count num,
+			      profile_count den)
 {
   struct cgraph_edge *e;
+  bool scale = (num == profile_count::zero () || den > 0);
 
   /* We do not want to ignore high loop nest after freq drops to 0.  */
   if (!freq_scale)
@@ -68,14 +70,20 @@ update_noncloned_frequencies (struct cgr
       if (e->frequency > CGRAPH_FREQ_MAX)
         e->frequency = CGRAPH_FREQ_MAX;
       if (!e->inline_failed)
-        update_noncloned_frequencies (e->callee, freq_scale);
+        update_noncloned_frequencies (e->callee, freq_scale, num, den);
+      if (scale)
+	e->count = e->count.apply_scale (num, den);
     }
   for (e = node->indirect_calls; e; e = e->next_callee)
     {
       e->frequency = e->frequency * (gcov_type) freq_scale / CGRAPH_FREQ_BASE;
       if (e->frequency > CGRAPH_FREQ_MAX)
         e->frequency = CGRAPH_FREQ_MAX;
+      if (scale)
+	e->count = e->count.apply_scale (num, den);
     }
+  if (scale)
+    node->count = node->count.apply_scale (num, den);
 }
 
 /* We removed or are going to remove the last call to NODE.
@@ -212,7 +220,8 @@ clone_inlined_nodes (struct cgraph_edge
 	    }
 	  duplicate = false;
 	  e->callee->externally_visible = false;
-          update_noncloned_frequencies (e->callee, e->frequency);
+          update_noncloned_frequencies (e->callee, e->frequency,
+					e->count, e->callee->count);
 
 	  dump_callgraph_transformation (e->callee, inlining_into,
 					 "inlining to");

                 reply	other threads:[~2017-06-16 11:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170616114641.GB6166@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).