This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] for PR 26570


Hello,

> > in this PR, we manage to free "values" array two times (one of them using
> > really ugly trick); however, there is no reason for that -- the "values"
> > array is used only in the branch_prob function, so we can simply free it
> > there.
> > 
> > Bootstrapped & regtested on x86_64 and ppc.
> 
> Changelog?
> :)

this logically had to happen on day I chose to lecture others about
proper conventions regarding patch submission :-) Here is the patch with
the missing bits (changelog and testcase).

Zdenek

	PR gcov/profile/26570
	* value-prof.c (static_values): Removed.
	(tree_find_values_to_profile): Do not set static_values.
	(find_values_to_profile): Do not free static_values.
	* profile.c (instrument_values): Do not free the values.
	(branch_prob): Free the values.

	* gcc.dg/pr26570.c: New test.

Index: value-prof.c
===================================================================
*** value-prof.c	(revision 116087)
--- value-prof.c	(working copy)
*************** Software Foundation, 51 Franklin Street,
*** 46,57 ****
  
  static struct value_prof_hooks *value_prof_hooks;
  
- /* This is the vector of histograms.  Created in find_values_to_profile.
-    During profile generation, freed by instrument_values.
-    During profile use, freed by value_profile_transformations.  */
- 
- static histogram_values static_values = NULL;
- 
  /* In this file value profile based optimizations are placed.  Currently the
     following optimizations are implemented (for more detailed descriptions
     see comments at value_profile_transformations):
--- 46,51 ----
*************** tree_find_values_to_profile (histogram_v
*** 797,803 ****
    FOR_EACH_BB (bb)
      for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
        tree_values_to_profile (bsi_stmt (bsi), values);
-   static_values = *values;
    
    for (i = 0; VEC_iterate (histogram_value, *values, i, hist); i++)
      {
--- 791,796 ----
*************** find_values_to_profile (histogram_values
*** 875,883 ****
  bool
  value_profile_transformations (void)
  {
!   bool retval = (value_prof_hooks->value_profile_transformations) ();
!   VEC_free (histogram_value, heap, static_values);
!   return retval;
  }
  
  
--- 868,874 ----
  bool
  value_profile_transformations (void)
  {
!   return (value_prof_hooks->value_profile_transformations) ();
  }
  
  
Index: testsuite/gcc.dg/pr26570.c
===================================================================
*** testsuite/gcc.dg/pr26570.c	(revision 0)
--- testsuite/gcc.dg/pr26570.c	(revision 0)
***************
*** 0 ****
--- 1,7 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -fprofile-generate -fprofile-use" } */
+ 
+ unsigned test (unsigned a, unsigned b)
+ {
+   return a / b;
+ } /* { dg-warning "execution counts estimated" } */
Index: profile.c
===================================================================
*** profile.c	(revision 116087)
--- profile.c	(working copy)
*************** instrument_values (histogram_values valu
*** 220,226 ****
  	  gcc_unreachable ();
  	}
      }
-   VEC_free (histogram_value, heap, values);
  }
  
  
--- 220,225 ----
*************** branch_prob (void)
*** 1049,1054 ****
--- 1048,1054 ----
  
    free_aux_for_edges ();
  
+   VEC_free (histogram_value, heap, values);
    free_edge_list (el);
    if (flag_branch_probabilities)
      profile_status = PROFILE_READ;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]