aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Hubicka <jh@suse.cz>2023-07-27 15:57:54 +0200
committerJan Hubicka <jh@suse.cz>2023-07-27 15:57:54 +0200
commit499b8079a6419bb8082de062ec30772296c6700c (patch)
tree56d09a9fc2c639193c954614e5c43f8c4eae95f9
parentd1c072a1c3411a6fe29900750b38210af8451eeb (diff)
downloadgcc-499b8079a6419bb8082de062ec30772296c6700c.zip
gcc-499b8079a6419bb8082de062ec30772296c6700c.tar.gz
gcc-499b8079a6419bb8082de062ec30772296c6700c.tar.bz2
Fix profile_count::apply_probability
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. gcc/ChangeLog: * profile-count.h (profile_count::apply_probability): Fix handling of uninitialized probabilities, optimize scaling by probability 1.
-rw-r--r--gcc/profile-count.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/profile-count.h b/gcc/profile-count.h
index bf11367..88a6431 100644
--- a/gcc/profile-count.h
+++ b/gcc/profile-count.h
@@ -1129,11 +1129,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;