Patchwork Fix PR gcov-profile/55551 (issue6868045)

login
register
mail settings
Submitter Teresa Johnson
Date Dec. 2, 2012, 7:10 a.m.
Message ID <20121202071038.CBA1561422@tjsboxrox.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/203196/
State New
Headers show

Comments

Teresa Johnson - Dec. 2, 2012, 7:10 a.m.
2012-12-01  Teresa Johnson  <tejohnson@google.com>

        PR gcov-profile/55551
	* lto-cgraph.c (merge_profile_summaries): Handle scaled histogram
        entries that map to the same index.


--
This patch is available for review at 5
Jan Hubicka - Dec. 2, 2012, 9:47 a.m.
> 2012-12-01  Teresa Johnson  <tejohnson@google.com>
> 
>         PR gcov-profile/55551
> 	* lto-cgraph.c (merge_profile_summaries): Handle scaled histogram
>         entries that map to the same index.
Path is OK.
It would be nice to figure out why you have non-zero runs and sum_max zero.
It is legally possible when you build your main w/o profiling and exit early,
but I would expect this to be bug in Mozilla's FDO build rather than intention.
It can easilly happen when you profile library and load it into something that
do not use it.

Honza

Patch

Index: lto-cgraph.c
===================================================================
--- lto-cgraph.c	(revision 193999)
+++ lto-cgraph.c	(working copy)
@@ -1345,7 +1345,8 @@  merge_profile_summaries (struct lto_file_decl_data
         /* Save a pointer to the profile_info with the largest
            scaled sum_all and the scale for use in merging the
            histogram.  */
-        if (lto_gcov_summary.sum_all > saved_sum_all)
+        if (!saved_profile_info
+            || lto_gcov_summary.sum_all > saved_sum_all)
           {
             saved_profile_info = &file_data->profile_info;
             saved_sum_all = lto_gcov_summary.sum_all;
@@ -1363,17 +1364,20 @@  merge_profile_summaries (struct lto_file_decl_data
          above. Use that to find the new histogram index.  */
       int scaled_min = RDIV (saved_profile_info->histogram[h_ix].min_value
                              * saved_scale, REG_BR_PROB_BASE);
+      /* The new index may be shared with another scaled histogram entry,
+         so we need to account for a non-zero histogram entry at new_ix.  */
       unsigned new_ix = gcov_histo_index (scaled_min);
-      lto_gcov_summary.histogram[new_ix].min_value = scaled_min;
+      lto_gcov_summary.histogram[new_ix].min_value
+          = MIN (lto_gcov_summary.histogram[new_ix].min_value, scaled_min);
       /* Some of the scaled counter values would ostensibly need to be placed
          into different (larger) histogram buckets, but we keep things simple
          here and place the scaled cumulative counter value in the bucket
          corresponding to the scaled minimum counter value.  */
       lto_gcov_summary.histogram[new_ix].cum_value
-          = RDIV (saved_profile_info->histogram[h_ix].cum_value
-                  * saved_scale, REG_BR_PROB_BASE);
+          += RDIV (saved_profile_info->histogram[h_ix].cum_value
+                   * saved_scale, REG_BR_PROB_BASE);
       lto_gcov_summary.histogram[new_ix].num_counters
-          = saved_profile_info->histogram[h_ix].num_counters;
+          += saved_profile_info->histogram[h_ix].num_counters;
     }
 
   /* Watch roundoff errors.  */