diff mbox series

handle profile_probability::always in profile_count::split better

Message ID 20181128203150.walaw7jengdjmze5@kam.mff.cuni.cz
State New
Headers show
Series handle profile_probability::always in profile_count::split better | expand

Commit Message

Jan Hubicka Nov. 28, 2018, 8:31 p.m. UTC
Hi,
this fixes (minor) profile updating issue which was uncovered by
somewhat devilish testcase Jakub accidentally created for branch
prediction code.

When expanding if (cond) goto xxx; gimple stmt with probability
profile_count::one into mutliple conditionals, we may end up predicting
whole chain with "guessed" quality which is unnecesary downgrade of
information we already have in CFG.

Bootstrapped/regtested x86_64-linux, comitted.

Honza

	* profile-count.h (profile_count::split): Give better result when
	splitting profile_probability::always.
diff mbox series

Patch

Index: profile-count.h
===================================================================
--- profile-count.h	(revision 266450)
+++ profile-count.h	(working copy)
@@ -447,8 +447,12 @@  public:
     {
       profile_probability ret = *this * cprob;
       /* The following is equivalent to:
-         *this = cprob.invert () * *this / ret.invert ();  */
-      *this = (*this - ret) / ret.invert ();
+         *this = cprob.invert () * *this / ret.invert ();
+	 Avoid scaling when overall outcome is supposed to be always.
+	 Without knowing that one is inverse of toher, the result would be
+	 conservative.  */
+      if (!(*this == profile_probability::always ()))
+        *this = (*this - ret) / ret.invert ();
       return ret;
     }