[llvm-profdata] Adjust profile supplementation heuristics

1) We now use the count size in FDO as the main factor to deal with pre-inliner.
Currently we use the number of sample records in the SampleFDO profile. But
that only counts the top-level body sample records (not including the nested
call-sites). We are seeing some big functions not being updated because of
this. I think using the count size in FDO profile is more reasonable to judge if
the function is likely to be inlined to the callers in pre-inliner.

(2) We use getMaxCount in SampleFDO rather the HeadSample to determine if
if the function is hot in SampleFDO. This is in-sync with the logic
in the compiler (also HeadSample can be 0).

Differential Revision: https://reviews.llvm.org/D132602
This commit is contained in:
Rong Xu 2022-08-24 11:28:02 -07:00
parent 4c10646367
commit d22c5d0f55
3 changed files with 27 additions and 7 deletions

View File

@ -0,0 +1,18 @@
:ir
foo
7
1
0
goo
5
3
0
0
0
moo
9
1
0

View File

@ -64,21 +64,21 @@ than suppl-min-size-threshold.
RUN: llvm-profdata merge \
RUN: -supplement-instr-with-sample=%p/Inputs/mix_sample.proftext \
RUN: -suppl-min-size-threshold=2 -zero-counter-threshold=0.7 \
RUN: -instr-prof-cold-threshold=30 %p/Inputs/mix_instr.proftext -o %t
RUN: -instr-prof-cold-threshold=30 %p/Inputs/mix_instr_small.proftext -o %t
RUN: llvm-profdata show %t -all-functions -counts | FileCheck %s --check-prefix=MIX4
MIX4: foo:
MIX4-NEXT: Hash: 0x0000000000000007
MIX4-NEXT: Counters: 5
MIX4-NEXT: Block counts: [12, 13, 0, 0, 0]
MIX4-NEXT: Counters: 1
MIX4-NEXT: Block counts: [0]
MIX4: goo:
MIX4-NEXT: Hash: 0x0000000000000005
MIX4-NEXT: Counters: 3
MIX4-NEXT: Block counts: [18446744073709551615, 18446744073709551615, 18446744073709551615]
MIX4: moo:
MIX4-NEXT: Hash: 0x0000000000000009
MIX4-NEXT: Counters: 4
MIX4-NEXT: Block counts: [3000, 1000, 2000, 500]
MIX4-NEXT: Counters: 1
MIX4-NEXT: Block counts: [0]
Test profile summary won't be affected by -1 counter.
RUN: llvm-profdata merge \

View File

@ -461,6 +461,7 @@ static void mergeInstrProfile(const WeightedFileVector &Inputs,
/// The profile entry for a function in instrumentation profile.
struct InstrProfileEntry {
uint64_t MaxCount = 0;
uint64_t NumEdgeCounters = 0;
float ZeroCounterRatio = 0.0;
InstrProfRecord *ProfRecord;
InstrProfileEntry(InstrProfRecord *Record);
@ -476,6 +477,7 @@ InstrProfileEntry::InstrProfileEntry(InstrProfRecord *Record) {
ZeroCntNum += !Record->Counts[I];
}
ZeroCounterRatio = (float)ZeroCntNum / CntNum;
NumEdgeCounters = CntNum;
}
/// Either set all the counters in the instr profile entry \p IFE to -1
@ -584,10 +586,10 @@ adjustInstrProfile(std::unique_ptr<WriterContext> &WC,
auto &FContext = PD.first;
const sampleprof::FunctionSamples &FS = PD.second;
auto It = InstrProfileMap.find(FContext.toString());
if (FS.getHeadSamples() > ColdSampleThreshold &&
if (FS.getMaxCountInside() > ColdSampleThreshold &&
It != InstrProfileMap.end() &&
It->second.MaxCount <= ColdInstrThreshold &&
FS.getBodySamples().size() >= SupplMinSizeThreshold) {
It->second.NumEdgeCounters >= SupplMinSizeThreshold) {
updateInstrProfileEntry(It->second, HotInstrThreshold,
ZeroCounterThreshold);
}