[all-commits] [llvm/llvm-project] 9fb074: [BPI] Improve static heuristics for "cold" paths.

ebrevnov via All-commits all-commits at lists.llvm.org
Wed Dec 23 07:48:03 PST 2020


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9fb074e7bb12ba20ca5ca628a11d4cb30e7c87cc
      https://github.com/llvm/llvm-project/commit/9fb074e7bb12ba20ca5ca628a11d4cb30e7c87cc
  Author: Evgeniy Brevnov <evgueni.brevnov at gmail.com>
  Date:   2020-12-23 (Wed, 23 Dec 2020)

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

  Log Message:
  -----------
  [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




More information about the All-commits mailing list