profi - a flow-based profile inference algorithm: Part III (out of 3)
authorspupyrev <spupyrev@fb.com>
Thu, 2 Dec 2021 19:59:33 +0000 (11:59 -0800)
committerHongtao Yu <hoy@fb.com>
Thu, 2 Dec 2021 20:01:30 +0000 (12:01 -0800)
commit93a2c2919f7339bd9e942ef69ebbf0883a2ef727
treef0b93e3cf0f927d30d23dda2be054a98ae339e29
parentb87fe58dce17c37a56eae4f2c1af4eeb41a490a4
profi - a flow-based profile inference algorithm: Part III (out of 3)

This is a continuation of D109860 and D109903.

An important challenge for profile inference is caused by the fact that the
sample profile is collected on a fully optimized binary, while the block and
edge frequencies are consumed on an early stage of the compilation that operates
with a non-optimized IR. As a result, some of the basic blocks may not have
associated sample counts, and it is up to the algorithm to deduce missing
frequencies. The problem is illustrated in the figure where three basic
blocks are not present in the optimized binary and hence, receive no samples
during profiling.

We found that it is beneficial to treat all such blocks equally. Otherwise the
compiler may decide that some blocks are “cold” and apply undesirable
optimizations (e.g., hot-cold splitting) regressing the performance. Therefore,
we want to distribute the counts evenly along the blocks with missing samples.
This is achieved by a post-processing step that identifies "dangling" subgraphs
consisting of basic blocks with no sampled counts; once the subgraphs are
found, we rebalance the flow so as every branch probability is 50:50 within the
subgraphs.

Our experiments indicate up to 1% performance win using the optimization on
some binaries and a significant improvement in the quality of profile counts
(when compared to ground-truth instrumentation-based counts)

{F19093045}

Reviewed By: hoy

Differential Revision: https://reviews.llvm.org/D109980
llvm/lib/Transforms/Utils/SampleProfileInference.cpp
llvm/test/Transforms/SampleProfile/Inputs/profile-inference-noprobes.prof [new file with mode: 0644]
llvm/test/Transforms/SampleProfile/Inputs/profile-inference-rebalance.prof [new file with mode: 0644]
llvm/test/Transforms/SampleProfile/profile-inference-noprobes.ll [new file with mode: 0644]
llvm/test/Transforms/SampleProfile/profile-inference-rebalance.ll [new file with mode: 0644]
llvm/test/Transforms/SampleProfile/profile-inference.ll