[PATCH] D132602: [llvm-profdata] Adjust profile supplementation heuristics

Rong Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 24 13:36:28 PDT 2022


xur created this revision.
xur added reviewers: davidxl, tmsriram.
Herald added a subscriber: wenlei.
Herald added a project: All.
xur requested review of this revision.
Herald added a project: LLVM.

(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).


https://reviews.llvm.org/D132602

Files:
  llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext
  llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
  llvm/tools/llvm-profdata/llvm-profdata.cpp


Index: llvm/tools/llvm-profdata/llvm-profdata.cpp
===================================================================
--- llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -461,6 +461,7 @@
 /// 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 @@
     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 @@
     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);
     }
Index: llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
===================================================================
--- llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
+++ llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
@@ -64,21 +64,21 @@
 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 \
Index: llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext
===================================================================
--- /dev/null
+++ 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
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132602.455353.patch
Type: text/x-patch
Size: 2926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220824/b37aad15/attachment.bin>


More information about the llvm-commits mailing list