Re: [PATCH 1/3] profile-count: Handle signed values in profile_probability::apply
Jeffrey Law <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
On 8/10/2026 8:26 AM, [email protected] wrote: > From: Kyrylo Tkachov <[email protected]> > > profile_probability::apply uses RDIV, which adds half the denominator > before division. This does not round negative values correctly. > Multiplying the signed input by the fixed-point probability can also > overflow for large inputs. > > Scale the unsigned magnitude with safe_scale_64bit, then restore the sign. > Return the input directly for a unit probability so that the minimum > gcov_type value remains representable. Preserve the existing truncation > for uninitialized probabilities. > > Add selftests for signed rounding, zero and unit probabilities, > uninitialized probabilities, and the minimum and maximum gcov_type values. > > Bootstrapped and tested on aarch64-none-linux and x86_64-linux. > Ok for trunk? > Thanks, > Kyrill > > gcc/ChangeLog: > > * profile-count.h (profile_probability::apply): Scale an unsigned > magnitude with safe_scale_64bit. > * profile-count.cc (test_profile_probability_apply): New. > (profile_count_cc_tests): New. > * selftest.h (profile_count_cc_tests): Declare. > * selftest-run-tests.cc (selftest::run_tests): Run it. > > Signed-off-by: Kyrylo Tkachov <[email protected]> OK unless Richi objects. So give him ~48hrs before committing to chime back in. jeff