[BPI] Improve static heuristics for "cold" paths.
authorEvgeniy Brevnov <evgueni.brevnov@gmail.com>
Thu, 18 Jun 2020 09:20:55 +0000 (16:20 +0700)
committerEvgeniy Brevnov <ybrevnov@azul.com>
Wed, 23 Dec 2020 15:47:36 +0000 (22:47 +0700)
commit9fb074e7bb12ba20ca5ca628a11d4cb30e7c87cc
tree78bcdc60601da3f2c8aad8fc00be55e0c83435ed
parent2522fa053b62520ae48b4b27117ca003a2c878ab
[BPI] Improve static heuristics for "cold" paths.

Current approach doesn't work well in cases when multiple paths are predicted to be "cold". By "cold" paths I mean those containing "unreachable" instruction, call marked with 'cold' attribute and 'unwind' handler of 'invoke' instruction. The issue is that heuristics are applied one by one until the first match and essentially ignores relative hotness/coldness
 of other paths.

New approach unifies processing of "cold" paths by assigning predefined absolute weight to each block estimated to be "cold". Then we propagate these weights up/down IR similarly to existing approach. And finally set up edge probabilities based on estimated block weights.

One important difference is how we propagate weight up. Existing approach propagates the same weight to all blocks that are post-dominated by a block with some "known" weight. This is useless at least because it always gives 50\50 distribution which is assumed by default anyway. Worse, it causes the algorithm to skip further heuristics and can miss setting more accurate probability. New algorithm propagates the weight up only to the blocks that dominates and post-dominated by a block with some "known" weight. In other words, those blocks that are either always executed or not executed together.

In addition new approach processes loops in an uniform way as well. Essentially loop exit edges are estimated as "cold" paths relative to back edges and should be considered uniformly with other coldness/hotness markers.

Reviewed By: yrouban

Differential Revision: https://reviews.llvm.org/D79485
30 files changed:
llvm/include/llvm/Analysis/BranchProbabilityInfo.h
llvm/include/llvm/Analysis/LazyBranchProbabilityInfo.h
llvm/lib/Analysis/BranchProbabilityInfo.cpp
llvm/lib/Analysis/OptimizationRemarkEmitter.cpp
llvm/lib/Transforms/Scalar/LoopPredication.cpp
llvm/test/Analysis/BlockFrequencyInfo/redundant_edges.ll
llvm/test/Analysis/BranchProbabilityInfo/basic.ll
llvm/test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll
llvm/test/Analysis/BranchProbabilityInfo/deopt-invoke.ll [new file with mode: 0644]
llvm/test/Analysis/BranchProbabilityInfo/loop.ll
llvm/test/Analysis/BranchProbabilityInfo/noreturn.ll
llvm/test/Analysis/BranchProbabilityInfo/unreachable.ll [new file with mode: 0644]
llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-invoke-probabilities.ll
llvm/test/CodeGen/AMDGPU/transform-block-with-return-to-epilog.ll
llvm/test/CodeGen/ARM/ifcvt-branch-weight-bug.ll
llvm/test/CodeGen/ARM/sub-cmp-peephole.ll
llvm/test/CodeGen/ARM/v8m.base-jumptable_alignment.ll
llvm/test/CodeGen/PowerPC/p10-spill-crgt.ll
llvm/test/CodeGen/PowerPC/pr36292.ll
llvm/test/CodeGen/PowerPC/sms-cpy-1.ll
llvm/test/CodeGen/SPARC/missinglabel.ll
llvm/test/CodeGen/SystemZ/debuginstr-cgp.mir
llvm/test/CodeGen/WebAssembly/switch-unreachable-default.ll
llvm/test/CodeGen/X86/2008-04-17-CoalescerBug.ll
llvm/test/CodeGen/X86/block-placement.ll
llvm/test/CodeGen/X86/misched_phys_reg_assign_order.ll
llvm/test/CodeGen/X86/pr27501.ll
llvm/test/CodeGen/X86/pr37916.ll
llvm/test/CodeGen/X86/ragreedy-hoist-spill.ll
llvm/test/Transforms/JumpThreading/thread-prob-3.ll