[PATCH] D13745: Replace all uses of branch weights by branch probabilities on machine code level passes.
Cong Hou via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 14 14:56:09 PDT 2015
congh created this revision.
congh added reviewers: dexonsmith, davidxl.
congh added a subscriber: llvm-commits.
Herald added a subscriber: dsanders.
This patch replaces all uses of branch weights by branch probabilities on machine code level passes. Each machine basic block now stores successors' probabilities, which are represented by fixed points with constant denominator. Therefore there is no additional space overhead as branch probability is also 32-bit. The sum of all successors' probabilities should be approximate one (not exact one due to rounding issues when calculating probabilities). There are several advantages of using probabilities instead of weights:
It is much faster and convenient to calculate branch probability for each successor. Previously, in order to get the branch probability, the sum of weights of all successors is calculated first, which is not quite efficient as the potential overflow is considered. When iterating successors and get their probabilities, the code is usually written as (for performance reason) getting the sum first and use the sum and scale value to calculate each successor's probability, which is odd and inconvenient. With this patch, probabilities are directly stored in each machine basic block and all issues above are gone.
Weights are suffering from some maintenance issues, and probabilities are easier to understand and maintain. David's proposal has stated it clearly: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20150803/291610.html
It is easier to validate the correctness of probabilities list rather than weights list: the sum of the former should be 1 while there is not restriction to the latter. This is quite useful when checking the probability updates after a CFG transformation are correct or not.
http://reviews.llvm.org/D13745
Files:
include/llvm/Analysis/BranchProbabilityInfo.h
include/llvm/CodeGen/MachineBasicBlock.h
include/llvm/CodeGen/MachineBranchProbabilityInfo.h
include/llvm/Support/BranchProbability.h
lib/Analysis/BranchProbabilityInfo.cpp
lib/CodeGen/BranchFolding.cpp
lib/CodeGen/IfConversion.cpp
lib/CodeGen/MIRParser/MIParser.cpp
lib/CodeGen/MIRPrinter.cpp
lib/CodeGen/MachineBasicBlock.cpp
lib/CodeGen/MachineBlockPlacement.cpp
lib/CodeGen/MachineBranchProbabilityInfo.cpp
lib/CodeGen/SelectionDAG/FastISel.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/CodeGen/TailDuplication.cpp
lib/Target/AArch64/AArch64FastISel.cpp
lib/Target/Mips/MipsDelaySlotFiller.cpp
lib/Target/PowerPC/PPCISelLowering.cpp
lib/Target/X86/X86FrameLowering.cpp
test/CodeGen/ARM/ifcvt-branch-weight-bug.ll
test/CodeGen/ARM/ifcvt-branch-weight.ll
test/CodeGen/ARM/ifcvt-iter-indbr.ll
test/CodeGen/ARM/tail-merge-branch-weight.ll
test/CodeGen/ARM/taildup-branch-weight.ll
test/CodeGen/Generic/MachineBranchProb.ll
test/CodeGen/Hexagon/ifcvt-edge-weight.ll
test/CodeGen/MIR/X86/successor-basic-blocks-weights.mir
test/CodeGen/PowerPC/sjlj.ll
test/CodeGen/X86/MachineBranchProb.ll
test/CodeGen/X86/catchpad-weight.ll
test/CodeGen/X86/stack-protector-weight.ll
test/CodeGen/X86/switch-edge-weight.ll
test/CodeGen/X86/switch-jump-table.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13745.37392.patch
Type: text/x-patch
Size: 101006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151014/de23dee9/attachment-0001.bin>
More information about the llvm-commits
mailing list