[compiler-rt] [llvm] [MemProf] Change histogram storage from uint64_t to uint8_t (PR #147854)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 23 17:05:28 PDT 2025
================
@@ -219,7 +218,11 @@ void Merge(const MemInfoBlock &newMIB) {
ShorterHistogramSize = newMIB.AccessHistogramSize;
}
for (size_t i = 0; i < ShorterHistogramSize; ++i) {
- ((uint64_t *)AccessHistogram)[i] += ((uint64_t *)ShorterHistogram)[i];
+ // Cast to uint8_t* and cap the sum at 255 to prevent overflow
+ uint8_t *CurrentHistPtr = (uint8_t *)AccessHistogram;
+ uint8_t *ShorterHistPtr = (uint8_t *)ShorterHistogram;
+ uint32_t sum = CurrentHistPtr[i] + ShorterHistPtr[i];
+ CurrentHistPtr[i] = (sum > 255) ? 255 : (uint8_t)sum;
----------------
snehasish wrote:
I discussed this with Matt and he mentioned the desire to use log based counting in the shadow memory so clamping it to 255 here would be counter-productive. So I reverted this part of the logic and implemented a 16b fp-like format which can represent counts up to 100s of M. Take a look at the new unit test for details.
https://github.com/llvm/llvm-project/pull/147854
More information about the llvm-commits
mailing list