This changes overflow handling during instrumentation profile merge. Rathar than throwing away records that would result in counter overflow, merged counts are instead clamped to the maximum representable value. A warning about counter overflow is still surfaced to the user as before.
Details
Diff Detail
Event Timeline
include/llvm/ProfileData/InstrProf.h | ||
---|---|---|
421 | Is this the right check? Seems like it would incorrectly fire when adding Counts[I] == "CounterMax - 1" and Other.Counts[I] == "1" since we are overwriting Counts[I] |
include/llvm/ProfileData/InstrProf.h | ||
---|---|---|
421 | Or perhaps just NewCount = SaturatingAdd(....); Result = ... Counts[I] = NewCount;
|
include/llvm/ProfileData/InstrProf.h | ||
---|---|---|
421 | I like that! |
lib/ProfileData/InstrProfWriter.cpp | ||
---|---|---|
118–119 | This line does not look right. Is it needed? |
Updated for davidxl's comment.
include/llvm/ProfileData/InstrProf.h | ||
---|---|---|
421 | The inline check for SaturatingAdd() overflow works well here, but thinking about the final weighted profile change - we need a way to check for SaturatingMultiply() overflow at multiple points in the code. I'll follow up this change with Sean's suggestion of adding a third optional argument to SaturatingAdd()/SaturatingMultiply() so the overflow check code can be encapsulated there. | |
lib/ProfileData/InstrProfWriter.cpp | ||
118–119 | Good point. Not needed. |
include/llvm/ProfileData/InstrProf.h | ||
---|---|---|
428 | Should this be Result != success? |
Updated for davidxl's comments.
include/llvm/ProfileData/InstrProf.h | ||
---|---|---|
428 | The idea here was to give the first error to occur priority. But really the ordering of multiple errors during merge isn't critical - or even obviously better either way. So the simpler check wins. |
include/llvm/ProfileData/InstrProf.h | ||
---|---|---|
428 | Ah -- I misread the code -- but it indeed was confusing -- the new way is better. |
Is this the right check? Seems like it would incorrectly fire when adding Counts[I] == "CounterMax - 1" and Other.Counts[I] == "1" since we are overwriting Counts[I]
The cleanest thing might be to add an optional argument bool *ResultOverflowed = nullptr to SaturatingAdd.