[llvm] d22c5d0 - [llvm-profdata] Adjust profile supplementation heuristics
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 29 14:34:09 PDT 2022
Author: Rong Xu
Date: 2022-08-29T14:17:27-07:00
New Revision: d22c5d0f5520e2bf24f04e724157a06765eb7a0a
URL: https://github.com/llvm/llvm-project/commit/d22c5d0f5520e2bf24f04e724157a06765eb7a0a
DIFF: https://github.com/llvm/llvm-project/commit/d22c5d0f5520e2bf24f04e724157a06765eb7a0a.diff
LOG: [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
Added:
llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext
Modified:
llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
llvm/tools/llvm-profdata/llvm-profdata.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext b/llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext
new file mode 100644
index 000000000000..80a2303dcfb8
--- /dev/null
+++ b/llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext
@@ -0,0 +1,18 @@
+:ir
+foo
+7
+1
+0
+
+goo
+5
+3
+0
+0
+0
+
+moo
+9
+1
+0
+
diff --git a/llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test b/llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
index 8b1016eac670..ba9829cb42f8 100644
--- a/llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
+++ b/llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
@@ -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 \
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index e3921281b4af..de34f39eb391 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -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);
}
More information about the llvm-commits
mailing list