Offlining an unrealized inline instance can leave its call site without
samples.  When the instance had samples and the caller location is missing
or zero, keep a conservative count of one.  Preserve existing positive
samples without estimating an entry count from body samples.

Bootstrapped and regression tested on aarch64-linux-gnu.

gcc/ChangeLog:

        * auto-profile.cc (function_instance::offline_if_not_realized): Keep
        sampled offlined inline call sites nonzero.

Signed-off-by: Kugan Vivekanandarajah <[email protected]>
---
 gcc/auto-profile.cc | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index 174c3e86009..dc175708c93 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -2223,6 +2223,8 @@ function_instance::offline_if_not_realized
     if (!iter->second->realized_p ())
       {
        function_instance *f = iter->second;
+       unsigned loc = iter->first.first;
+       bool sampled = f->total_count () > 0;
        if (dump_file)
          {
            fprintf (dump_file, "Offlining unrealized inline ");
@@ -2231,6 +2233,16 @@ function_instance::offline_if_not_realized
          }
        iter = callsites.erase (iter);
        offline (f, new_functions);
+       /* Keep the call block sampled.  Preserve positive samples and replace
+          an explicit zero.  */
+       position_count_map::const_iterator pos = pos_counts.find (loc);
+       if (sampled
+           && (pos == pos_counts.end () || pos->second.count == 0))
+         {
+           pos_counts[loc].count = 1;
+           for (function_instance *s = this; s; s = s->inlined_to ())
+             s->total_count_++;
+         }
       }
     else
       {
-- 
2.34.1

Reply via email to