[PATCH] D11915: Let edge weight be always greater than zero in both BPI and MBPI.

Cong Hou via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 11:37:09 PDT 2015


congh created this revision.
congh added reviewers: dexonsmith, davidxl.
congh added a subscriber: llvm-commits.

Currently BPI requires that edge weights must be greater than 0, but MBPI doesn't have this requirement. In MBPI, when an edge weight is zero, it is treated as there is no weight info for that edge. At runtime, such a zero edge weight will be turned into a DEFAULT edge weight 16. This may lead to incorrect edge weights ratio when we originally have 0 and 1 as edge weights from the same block and later get 16 and 1. Zero weights can either mean no info or obtained from BPI or calculated by users, making it ambiguous. When we have all out-edges with zero weights from the same block, it is awkward to compute edge probabilities. Though this is worked-around by using default edge weights. However, if we require edge weights in MBPI also should be greater than zero, we won't have the issues above.

In addition, although BPI requires edge weights to be greater than zero, it doesn't guarantee this when weights are read from metadata. So we need to normalize edge weights when we read zero weight from metadata. For example, if we have 0 and 1 edge weights from the same block (assume it only has two out-edges), we can normalize them into 1 and UINT32_MAX - 1.

This patch contains the following changes:

1. Normalize edge weights in BPI to guarantee that they are greater than 0.
2. In MBPI don't turn zero edge weights into default weights as we should not have zero weights anymore.
3. (To discuss) Weight list can be empty previously when it is not used at all. I found it difficult to make weight list and successor list always synchronized so this patch will always update weight list whether it is used or not. Is this acceptable?
4. Adjust use and test cases accordingly.

http://reviews.llvm.org/D11915

Files:
  include/llvm/CodeGen/MachineBasicBlock.h
  lib/Analysis/BranchProbabilityInfo.cpp
  lib/CodeGen/MIRParser/MIRParser.cpp
  lib/CodeGen/MachineBasicBlock.cpp
  lib/CodeGen/SelectionDAG/FastISel.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  lib/Target/AArch64/AArch64FastISel.cpp
  lib/Target/PowerPC/PPCISelLowering.cpp
  lib/Target/X86/X86FastISel.cpp
  test/Analysis/BlockFrequencyInfo/bad_input.ll
  test/CodeGen/PowerPC/sjlj.ll
  test/Transforms/SampleProfile/branch.ll
  test/Transforms/SampleProfile/calls.ll
  test/Transforms/SampleProfile/propagate.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11915.31689.patch
Type: text/x-patch
Size: 23460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150810/2be367c6/attachment.bin>


More information about the llvm-commits mailing list