[PATCH] D12603: Use fixed-point representation for BranchProbability

Cong Hou via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 3 11:08:45 PDT 2015


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

BranchProbability now is represented by its numerator and denominator in uint32_t type. This patch changes this representation into a fixed point that is represented by the numerator in uint32_t type and a constant denominator  UINT32_MAX. This is quite similar to the representation of BlockMass in BlockFrequencyInfoImpl.h. There are several pros and cons of this change:

Pros:

1. It uses only a half space of the current one.
2. Some operations are much faster like plus, subtraction, comparison, and scaling by an integer. 

Cons:

1. Constructing a probability using arbitrary numerator and denominator needs additional calculations.
2. It is a little less precise than before as we use a fixed denominator. For example, 1 - 1/2 may not be exactly identical to 1 / 2 (this will lead to many BranchProbability unit test failures). This should not matter when we only use it for branch probability. If we use it like a rational value for some precise calculations we may need another construct like ValueRatio.

One important reason for this change is that we propose to store branch probabilities instead of edge weights in MachineBasicBlock (see http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20150803/291610.html for the proposal and discussions). We also want clients to use probability instead of weight when adding successors to a MBB. The current BranchProbability has more space which may be a concern.

Most test cases are updated with this change, except those of BranchProbability and BlockFrequency unit tests, which fail due to imprecise representation. If this patch is approved I will update them later.



http://reviews.llvm.org/D12603

Files:
  include/llvm/Support/BranchProbability.h
  lib/Support/BranchProbability.cpp
  test/Analysis/BlockFrequencyInfo/bad_input.ll
  test/Analysis/BlockFrequencyInfo/basic.ll
  test/Analysis/BlockFrequencyInfo/double_backedge.ll
  test/Analysis/BlockFrequencyInfo/double_exit.ll
  test/Analysis/BlockFrequencyInfo/irreducible.ll
  test/Analysis/BlockFrequencyInfo/loop_with_branch.ll
  test/Analysis/BlockFrequencyInfo/loops_with_profile_info.ll
  test/Analysis/BlockFrequencyInfo/nested_loop_with_branches.ll
  test/Analysis/BranchProbabilityInfo/basic.ll
  test/Analysis/BranchProbabilityInfo/loop.ll
  test/Analysis/BranchProbabilityInfo/noreturn.ll
  test/Analysis/BranchProbabilityInfo/pr18705.ll
  test/Analysis/BranchProbabilityInfo/pr22718.ll
  test/CodeGen/AArch64/aarch64-deferred-spilling.ll
  test/Transforms/SampleProfile/branch.ll
  test/Transforms/SampleProfile/calls.ll
  test/Transforms/SampleProfile/discriminator.ll
  test/Transforms/SampleProfile/fnptr.ll
  test/Transforms/SampleProfile/propagate.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12603.33893.patch
Type: text/x-patch
Size: 53957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150903/1468d5c5/attachment-0001.bin>


More information about the llvm-commits mailing list