diff mbox series

Fix profile_count::max and profile_count::apply_scale WRT counts of different types

Message ID 20191128154757.nvxyebitpxfyv6am@kam.mff.cuni.cz
State New
Headers show
Series Fix profile_count::max and profile_count::apply_scale WRT counts of different types | expand

Commit Message

Jan Hubicka Nov. 28, 2019, 3:47 p.m. UTC
Hi,
profile_count::max and profile_count::apply_scale and two functions that needs
to work with pairs of counters from different functions (first is used to
obtain overall statistics used by e.g. inliner and profile_count::apply_scale
is used to scale function profile when inline clones are created).

profile_count::max needs to simply preffer global counts over local which is
implemented to converting to IPA.

profile_count::apply_scale needs to be careful about quality updates.
If NUM is GUESSED_GLOBAL0 or GUESSED_GLOBAL0_ADJUSTED the result needs to
be of same type and if NUM is other IPA count the result needs to be IPA too.

Bootstrapped/regtested x86_64-linux, will commit it shortly after testing on
Firefox.

	* profile-count.h (profile_count::max): Work on profiles of different
	type.
	(profile_count::apply_scale): Be sure that ret is not local or global0
	type if num is global.
diff mbox series

Patch

Index: profile-count.h
===================================================================
--- profile-count.h	(revision 278811)
+++ profile-count.h	(working copy)
@@ -992,6 +992,14 @@  public:
 
   profile_count max (profile_count other) const
     {
+      profile_count val = *this;
+
+      /* Always prefer nonzero IPA counts over local counts.  */
+      if (ipa ().nonzero_p () || other.ipa ().nonzero_p ())
+	{
+	  val = ipa ();
+	  other = other.ipa ();
+	}
       if (!initialized_p ())
 	return other;
       if (!other.initialized_p ())
@@ -1001,8 +1009,8 @@  public:
       if (other == zero ())
 	return *this;
       gcc_checking_assert (compatible_p (other));
-      if (m_val < other.m_val || (m_val == other.m_val
-				  && m_quality < other.m_quality))
+      if (val.m_val < other.m_val || (m_val == other.m_val
+				      && val.m_quality < other.m_quality))
 	return other;
       return *this;
     }
@@ -1075,8 +1083,11 @@  public:
       ret.m_val = MIN (val, max_count);
       ret.m_quality = MIN (MIN (MIN (m_quality, ADJUSTED),
 			        num.m_quality), den.m_quality);
-      if (num.ipa_p () && !ret.ipa_p ())
-	ret.m_quality = MIN (num.m_quality, GUESSED);
+      /* Be sure that ret is not local if num is global.
+	 Also ensure that ret is not global0 when num is global.  */
+      if (num.ipa_p ())
+	ret.m_quality = MAX (num.m_quality,
+			     num == num.ipa () ? GUESSED : num.m_quality);
       return ret;
     }