[llvm] [PGO] Sampled instrumentation in PGO to speed up instrumentation binary (PR #69535)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 20 11:35:06 PDT 2023


================
@@ -412,30 +424,91 @@ PreservedAnalyses InstrProfiling::run(Module &M, ModuleAnalysisManager &AM) {
   return PreservedAnalyses::none();
 }
 
+// Perform instrumentation sampling.
+// We transform:
+//   Increment_Instruction;
+// to:
+//   if (__llvm_profile_sampling__ <= SampleDuration) {
+//     Increment_Instruction;
+//   }
+//   __llvm_profile_sampling__ += 1;
----------------
xur-llvm wrote:

__llvm_profile_sampling__ is not shared by all PGO counters. It's s thread-local variable. All the counters in one thread shared the value.

This is burst sampling. We used to have to parameters (i.e. changing 64K to another used specified value).  Using 64K value does increase the chances of bias. But I do think the chances are low in real programs.

Of course, I can write a test case to show the method will result in a bias profile. This is sampling after all. There will be always corner cases that gets biased result. 

https://github.com/llvm/llvm-project/pull/69535


More information about the llvm-commits mailing list