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
- Repository
 - rL LLVM
 
Event Timeline
| include/llvm/ProfileData/InstrProf.h | ||
|---|---|---|
| 421 ↗ | (On Diff #40841) | 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 ↗ | (On Diff #40841) | Or perhaps just NewCount = SaturatingAdd(....); Result = ... Counts[I] = NewCount; 
  | 
| include/llvm/ProfileData/InstrProf.h | ||
|---|---|---|
| 421 ↗ | (On Diff #40841) | I like that!  | 
| lib/ProfileData/InstrProfWriter.cpp | ||
|---|---|---|
| 118 ↗ | (On Diff #40934) | This line does not look right. Is it needed?  | 
Updated for davidxl's comment.
| include/llvm/ProfileData/InstrProf.h | ||
|---|---|---|
| 421 ↗ | (On Diff #40934) | 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 ↗ | (On Diff #40934) | Good point. Not needed.  | 
| include/llvm/ProfileData/InstrProf.h | ||
|---|---|---|
| 428 ↗ | (On Diff #40978) | Should this be Result != success?  | 
Updated for davidxl's comments.
| include/llvm/ProfileData/InstrProf.h | ||
|---|---|---|
| 428 ↗ | (On Diff #40978) | 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 ↗ | (On Diff #40978) | Ah -- I misread the code -- but it indeed was confusing -- the new way is better.  |