https://gcc.gnu.org/g:1123e52e811349dc880a5fc1abe4d5d427fcf70c
commit r17-5995-g1123e52e811349dc880a5fc1abe4d5d427fcf70c Author: Artemiy Volkov <[email protected]> Date: Thu Nov 5 14:05:11 2026 +0000 profile_probability: two fixes for ->sqrt () Firstly, so far, we've always been returning 'm_val' from this method (which is the input value of the algorithm) rather than 'val' (which is the value of the result). Fix that so we get correct values out of ->sqrt (). Additionally, change the while loop condition on l. 511 to avoid an unrecoverable infinite loop whenever min_range ends up being greater than max_range due to precision errors. Bootstrapped and regtested on aarch64-linux-gnu and x86_64-linux-gnu. OK for trunk and/or backports? gcc/ChangeLog: * profile-count.cc (profile_probability::sqrt): Return val instead of m_val. Alter the while loop condition. Diff: --- gcc/profile-count.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/profile-count.cc b/gcc/profile-count.cc index 9be209efda24..e00d11b6f026 100644 --- a/gcc/profile-count.cc +++ b/gcc/profile-count.cc @@ -508,12 +508,12 @@ profile_probability::sqrt () const max_range = 0; if (m_val == max_probability) min_range = max_probability; - while (min_range != max_range) + while (min_range < max_range) { uint32_t val = (min_range + max_range) / 2; uint32_t val2 = RDIV ((uint64_t)val * val, max_probability); if (val2 == m_val) - min_range = max_range = m_val; + min_range = max_range = val; else if (val2 > m_val) max_range = val - 1; else if (val2 < m_val)
