public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix profile_count::apply_probability
@ 2023-07-27 14:19 Jan Hubicka
  0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2023-07-27 14:19 UTC (permalink / raw)
  To: gcc-patches

Hi,
profile_count::apply_probability misses check for uninitialized
probability which leads to completely random results on applying
uninitialized probability to initialized scale.  This can make
difference when i.e. inlining -fno-guess-branch-probability function to
-fguess-branch-probability one.

Boootstrapped/regtested x86_64-linux, commited.
gcc/ChangeLog:

	* profile-count.h (profile_count::apply_probability): Fix
	handling of uninitialized probabilities, optimize scaling
	by probability 1.

diff --git a/gcc/profile-count.h b/gcc/profile-count.h
index bf1136782a3..e860c5db540 100644
--- a/gcc/profile-count.h
+++ b/gcc/profile-count.h
@@ -1129,11 +1132,11 @@ public:
   /* Scale counter according to PROB.  */
   profile_count apply_probability (profile_probability prob) const
     {
-      if (*this == zero ())
+      if (*this == zero () || prob == profile_probability::always ())
 	return *this;
       if (prob == profile_probability::never ())
 	return zero ();
-      if (!initialized_p ())
+      if (!initialized_p () || !prob.initialized_p ())
 	return uninitialized ();
       profile_count ret;
       uint64_t tmp;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-27 14:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27 14:19 Fix profile_count::apply_probability Jan Hubicka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).