[CSSPGO][Preinliner] Trim cold call edges of the profiled call graph for a more stabl...
authorHongtao Yu <hoy@fb.com>
Mon, 27 Mar 2023 18:40:52 +0000 (11:40 -0700)
committerHongtao Yu <hoy@fb.com>
Tue, 28 Mar 2023 23:24:38 +0000 (16:24 -0700)
commit5c2ae37bbeff948540712bf02ac3eb5aa0b0d43a
tree0cb6fe65ae8158fdb6622d667ee9d4536cb144ef
parentfda53ad9374b60fc83f1a6065ae3e7985182a5d2
[CSSPGO][Preinliner] Trim cold call edges of the profiled call graph for a more stable profile generation.

I've noticed that for some services CSSPGO profile is less stable than non-CS AutoFDO profile from profiling to profiling without source changes. This is manifested by comparing profile similarities. For example in my experiments, AutoFDO profiles are always 99+% similar over same binary but different inputs (very close dynamic traffics) while CSSPGO profile similarity is around 90%.

The main source of the profile stability is the top-down order computed on the profiled call graph in the llvm-profgen CS preinliner. The top-down order is used to guide the CS preinliner to pre-compute an inline decision that is later on fulfilled by the compiler. A subtle change in the top-down order from run to run could cause a different inline decision computed. A deeper look in the diversion of the top-down order revealed that:
- The topological sorting inside one SCC isn't quite right. This is fixed by {D130717}.
- The profiled call graphs of the two sides of the A/B run isn't 100% the same. The call edges in the two runs do not subsume each other, and edges appear in both graphs may not have exactly the same weight. This is due to the nature that the graphs are dynamic. However, I saw that the graphs can be made more close by removing the cold edges from them and this bumped up the CSSPGO profile stableness to the same level of the AutoFDO profile.

Removing cold call edges from the dynamic call graph may have an impact on cold inlining, but so far I haven't seen any performance issues since the CS preinliner mainly targets hot callsites, and cold inlining can always be done by the compiler CGSCC inliner.

Also fixing an issue where the largest weight instead of the accumulated weight for a call edge is used in the profiled call graph.

Reviewed By: wenlei

Differential Revision: https://reviews.llvm.org/D147013
llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
llvm/tools/llvm-profgen/CSPreInliner.cpp