aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJan Hubicka <hubicka@ucw.cz>2017-11-09 15:05:14 +0100
committerJan Hubicka <hubicka@gcc.gnu.org>2017-11-09 14:05:14 +0000
commite4373d41d67060e14bab0c984fb9f7cbc4c93f1b (patch)
treefb9d5143e4e5fd9e929fbb4c13e3bd4b71aaaa40 /gcc
parenta3a6d41f4610c67b9905b3796e441397cc240178 (diff)
downloadgcc-e4373d41d67060e14bab0c984fb9f7cbc4c93f1b.zip
gcc-e4373d41d67060e14bab0c984fb9f7cbc4c93f1b.tar.gz
gcc-e4373d41d67060e14bab0c984fb9f7cbc4c93f1b.tar.bz2
re PR ipa/82879 (ICE in max, at profile-count.h:889)
PR ipa/82879 * ipa-inline-transform.c (update_noncloned_frequencies): Use profile_count::adjust_for_ipa_scaling. * tree-inline.c (copy_bb, copy_cfg_body): Likewise. * profile-count.c (profile_count::adjust_for_ipa_scaling): New member function. * profile-count.h (profile_count::adjust_for_ipa_scaling): Declare. From-SVN: r254582
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/ipa-inline-transform.c12
-rw-r--r--gcc/profile-count.c26
-rw-r--r--gcc/profile-count.h5
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr82879.c11
-rw-r--r--gcc/tree-inline.c24
7 files changed, 59 insertions, 33 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index df371fd..0953b4a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2017-11-09 Jan Hubicka <hubicka@ucw.cz>
+
+ PR ipa/82879
+ * ipa-inline-transform.c (update_noncloned_frequencies): Use
+ profile_count::adjust_for_ipa_scaling.
+ * tree-inline.c (copy_bb, copy_cfg_body): Likewise.
+ * profile-count.c (profile_count::adjust_for_ipa_scaling): New member
+ function.
+ * profile-count.h (profile_count::adjust_for_ipa_scaling): Declare.
+
2017-11-09 Jakub Jelinek <jakub@redhat.com>
* gimple-ssa-store-merging.c (count_multiple_uses): New function.
diff --git a/gcc/ipa-inline-transform.c b/gcc/ipa-inline-transform.c
index e367df7..b2363e2 100644
--- a/gcc/ipa-inline-transform.c
+++ b/gcc/ipa-inline-transform.c
@@ -60,17 +60,7 @@ update_noncloned_frequencies (struct cgraph_node *node,
{
struct cgraph_edge *e;
- /* We always must scale to be sure counters end up compatible.
- If den is zero, just force it nonzero and hope for reasonable
- approximation.
- When num is forced nonzero, also update den, so we do not scale profile
- to 0. */
- if (!(num == den)
- && !(den.force_nonzero () == den))
- {
- den = den.force_nonzero ();
- num = num.force_nonzero ();
- }
+ profile_count::adjust_for_ipa_scaling (&num, &den);
/* We do not want to ignore high loop nest after freq drops to 0. */
if (!freq_scale)
diff --git a/gcc/profile-count.c b/gcc/profile-count.c
index d703140..9c57323 100644
--- a/gcc/profile-count.c
+++ b/gcc/profile-count.c
@@ -255,3 +255,29 @@ profile_count::to_cgraph_frequency (profile_count entry_bb_count) const
return CGRAPH_FREQ_MAX;
return MIN (scale, CGRAPH_FREQ_MAX);
}
+
+/* We want to scale profile across function boundary from NUM to DEN.
+ Take care of the side case when DEN is zeros. We still want to behave
+ sanely here which means
+ - scale to profile_count::zero () if NUM is profile_count::zero
+ - do not affect anything if NUM == DEN
+ - preserve counter value but adjust quality in other cases. */
+
+void
+profile_count::adjust_for_ipa_scaling (profile_count *num,
+ profile_count *den)
+{
+ /* Scaling is no-op if NUM and DEN are the same. */
+ if (*num == *den)
+ return;
+ /* Scaling to zero is always zeor. */
+ if (*num == profile_count::zero ())
+ return;
+ /* If den is non-zero we are safe. */
+ if (den->force_nonzero () == *den)
+ return;
+ /* Force both to non-zero so we do not push profiles to 0 when
+ both num == 0 and den == 0. */
+ *den = den->force_nonzero ();
+ *num = num->force_nonzero ();
+}
diff --git a/gcc/profile-count.h b/gcc/profile-count.h
index f16bbcb..aa42b4e 100644
--- a/gcc/profile-count.h
+++ b/gcc/profile-count.h
@@ -1044,6 +1044,11 @@ public:
/* Return true if THIS is known to differ significantly from OTHER. */
bool differs_from_p (profile_count other) const;
+ /* We want to scale profile across function boundary from NUM to DEN.
+ Take care of the side case when NUM and DEN are zeros of incompatible
+ kinds. */
+ static void adjust_for_ipa_scaling (profile_count *num, profile_count *den);
+
/* LTO streaming support. */
static profile_count stream_in (struct lto_input_block *);
void stream_out (struct output_block *);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e7867ec..7741f7f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2017-11-09 Jan Hubicka <hubicka@ucw.cz>
+
+ * gcc.c-torture/compile/pr82879.c: New testcase.
+
2017-11-09 Richard Biener <rguenther@suse.de>
PR tree-optimization/82902
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr82879.c b/gcc/testsuite/gcc.c-torture/compile/pr82879.c
new file mode 100644
index 0000000..fad3fed
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr82879.c
@@ -0,0 +1,11 @@
+int a, b;
+static __attribute__((cold)) void fn1() {
+ for (;;)
+ for (; a;)
+ ;
+}
+void fn2() {
+ if (b)
+ fn1();
+}
+
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 7ef1072..fc5d2c7 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -1771,17 +1771,7 @@ copy_bb (copy_body_data *id, basic_block bb,
tree decl;
basic_block prev;
- /* We always must scale to be sure counters end up compatible.
- If den is zero, just force it nonzero and hope for reasonable
- approximation.
- When num is forced nonzero, also update den, so we do not scale profile
- to 0. */
- if (!(num == den)
- && !(den.force_nonzero () == den))
- {
- den = den.force_nonzero ();
- num = num.force_nonzero ();
- }
+ profile_count::adjust_for_ipa_scaling (&num, &den);
/* Search for previous copied basic block. */
prev = bb->prev_bb;
@@ -2698,17 +2688,7 @@ copy_cfg_body (copy_body_data * id, profile_count,
profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count;
profile_count num = entry_block_map->count;
- /* We always must scale to be sure counters end up compatible.
- If den is zero, just force it nonzero and hope for reasonable
- approximation.
- When num is forced nonzero, also update den, so we do not scale profile
- to 0. */
- if (!(num == den)
- && !(den.force_nonzero () == den))
- {
- den = den.force_nonzero ();
- num = num.force_nonzero ();
- }
+ profile_count::adjust_for_ipa_scaling (&num, &den);
cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl);