[FSAFDO] Improve FS discriminator encoding
authorRong Xu <xur@google.com>
Fri, 10 Mar 2023 06:43:08 +0000 (22:43 -0800)
committerRong Xu <xur@google.com>
Fri, 10 Mar 2023 07:18:48 +0000 (23:18 -0800)
commitebe09e2a9556c411809f6c27f555299273442664
tree58e8a99d6bb97bcdc34f8aac0a254e9d46ac4b38
parentaf86957cbbffd3dfff3c6750ebddf118aebd0069
[FSAFDO] Improve FS discriminator encoding

This change improves FS discriminators in the following ways:
(1) use call-stack debug information in the the to generate
discriminators: the same (src/line) DILs can now have same
discriminator value if they come from different call-stacks.
This effectively increases the usable discriminator values
for each round of FS discriminator pass.
(2) don't generate the FS discriminator for meta instructions
(i.e. instructions not emitted). This reduces the number
discriminators conflicts (for the case we run out of discriminator
bits for that pass).
(3) use less expensive hashing of xxHash64.

These improvements should bring better performance for FSAFDO
and they should be used by default. But this change creates
incompatible FS discriminators. For the iterative profile users,
they might see a performance drop in the first release with
this change (due to the fact that the profiles have the old
discriminators and the compiler uses the new discriminator).
We have measured that this is not more than 1.5% on several
benchmarks. Note the degradation should be gone in the second
release and one should expect a performance gain over the binary
without this change.

One possible solution to the iterative profile issue would be
separating discriminators for profile-use and the ones emitted to
the binary. This would require a mechanism to allow two sets of
discriminators to be maintained and then phasing out the first
approach. This is too much churn in the compiler and the
performance implications do not seem to be worth the effort.

Instead, we put the changes under an option so iterative profile
users can do a gradual rollout of this change. We will make the
option default value to true in a later patch and eventually
purge this option from the code base.

Differential Revision: https://reviews.llvm.org/D145171
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp
llvm/lib/CodeGen/MIRFSDiscriminator.cpp
llvm/lib/CodeGen/MIRSampleProfile.cpp
llvm/lib/CodeGen/PseudoProbeInserter.cpp
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
llvm/test/CodeGen/X86/Inputs/fsloader_v1.afdo [new file with mode: 0644]
llvm/test/CodeGen/X86/fsafdo_test1.ll
llvm/test/CodeGen/X86/fsafdo_test2.ll
llvm/test/CodeGen/X86/fsafdo_test3.ll
llvm/test/CodeGen/X86/fsafdo_test4.ll