[CSSPGO] Unblocking optimizations by dangling pseudo probes.
authorHongtao Yu <hoy@fb.com>
Thu, 25 Feb 2021 08:52:58 +0000 (00:52 -0800)
committerHongtao Yu <hoy@fb.com>
Thu, 4 Mar 2021 06:44:42 +0000 (22:44 -0800)
commit89855158228644b7be273055efd728b82ea82803
treeb58bf3372eb91d5004f216ac900310f5edacd628
parentad2a59f5840482d7dd802e83b82262c97704a4eb
[CSSPGO] Unblocking optimizations by dangling pseudo probes.

This change fixes a couple places where the pseudo probe intrinsic blocks optimizations because they are not naturally removable. To unblock those optimizations, the blocking pseudo probes are moved out of the original blocks and tagged dangling, instead of allowing pseudo probes to be literally removed. The reason is that when the original block is removed, we won't be able to sample it. Instead of assigning it a zero weight, moving all its pseudo probes into another block and marking them dangling should allow the counts inference a chance to assign them a more reasonable weight. We have not seen counts quality degradation from our experiments.

The optimizations being unblocked are:

1. Removing conditional probes for if-converted branches. Conditional probes are tagged dangling when their homing branch arms are folded so that they will not be over-counted.
2. Unblocking jump threading from removing empty blocks. Pseudo probe prevents jump threading from removing logically empty blocks that only has one unconditional jump instructions.
3. Unblocking SimplifyCFG and MIR tail duplicate to thread empty blocks and blocks with redundant branch checks.

Since dangling probes are logically deleted, they should not consume any samples in LTO postLink. This can be achieved by setting their distribution factors to zero when dangled.

Reviewed By: wmi

Differential Revision: https://reviews.llvm.org/D97481
12 files changed:
llvm/include/llvm/CodeGen/MachineBasicBlock.h
llvm/include/llvm/IR/PseudoProbe.h
llvm/lib/CodeGen/BranchFolding.cpp
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/lib/CodeGen/TailDuplicator.cpp
llvm/lib/IR/PseudoProbe.cpp
llvm/lib/Transforms/IPO/SampleProfile.cpp
llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/SampleProfile/pseudo-probe-dangle.ll [new file with mode: 0644]