From: Jan Hubicka Date: Thu, 27 Jul 2023 13:57:54 +0000 (+0200) Subject: Fix profile_count::apply_probability X-Git-Tag: basepoints/gcc-15~7317 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=499b8079a6419bb8082de062ec30772296c6700c;p=thirdparty%2Fgcc.git 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. --- diff --git a/gcc/profile-count.h b/gcc/profile-count.h index bf1136782a3b..88a6431c21a0 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;