Fix ICE in partial inlining profile scaling

Message ID 20180111101618.GA96001@kam.mff.cuni.cz
State New
Headers show
Series
  • Fix ICE in partial inlining profile scaling
Related show

Commit Message

Jan Hubicka Jan. 11, 2018, 10:16 a.m.
Hi,
ipa-fnsplit sometimes ICEs on profile update because profile_count::adjust_for_ipa_scaling
is called too early.

Bootstrapped/regtested x86_64-linux, will commit it shortly.

	PR middle-end/83718
	* tree-inline.c (copy_cfg_body): Adjust num&den for scaling
	after they are computed.
	* g++.dg/torture/pr83718.C: New testcase.

Patch

Index: tree-inline.c
===================================================================
--- tree-inline.c	(revision 256479)
+++ tree-inline.c	(working copy)
@@ -2683,8 +2683,6 @@  copy_cfg_body (copy_body_data * id,
   profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
   profile_count num = entry_block_map->count;
 
-  profile_count::adjust_for_ipa_scaling (&num, &den);
-
   cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);
 
   /* Register specific tree functions.  */
@@ -2707,6 +2705,8 @@  copy_cfg_body (copy_body_data * id,
       ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = den;
     }
 
+  profile_count::adjust_for_ipa_scaling (&num, &den);
+
   /* Must have a CFG here at this point.  */
   gcc_assert (ENTRY_BLOCK_PTR_FOR_FN
 	      (DECL_STRUCT_FUNCTION (callee_fndecl)));
Index: testsuite/g++.dg/torture/pr83718.C
===================================================================
--- testsuite/g++.dg/torture/pr83718.C	(revision 0)
+++ testsuite/g++.dg/torture/pr83718.C	(working copy)
@@ -0,0 +1,115 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -std=c++11" } */
+
+class a
+{
+public:
+  int c (const char *);
+};
+class B
+{
+  virtual int *d (a, bool);
+};
+
+bool e, f, g;
+
+class: B
+{
+  int ah;
+  int *
+  d (a, bool)
+  {
+    if (e)
+      return &ah;
+    a bj;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (f)
+      return &ah;
+    bj.c ("");
+    if (g)
+      return &ah;
+    if (f)
+      return &ah;
+      e = a ().c("");
+    return &ah;
+  }
+} b;
+