[PATCH] D12418: Distribute the weight on the edge from switch to default statement to edges generated in lowering switch.

Cong Hou via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 16:50:27 PDT 2015


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

Currently, when edge weights are assigned to edges that are created when lowering switch statement, the weight on the edge to default statement (let's call it "default weight" here) is not considered. We need to distribute this weight properly. However, without value profiling, we have no idea how to distribute it. In this patch, I applied the heuristic that this weight is evenly distributed to successors.

For example, given a switch statement with cases 1,2,3,5,10,11,20, and every edge from switch to each successor has weight 10. If there is a binary search tree built to test if n < 10, then its two out-edges will have weight 4x10+10/2 = 45 and 3x10 + 10/2 = 35 respectively (currently they are 40 and 30 without considering the default weight). Each distribution (which is 5 here) will be stored in each SwitchWorkListItem for further distribution.

There are some exceptions:

1. For a jump table header which doesn't have any edge to default statement, we don't distribute the default weight to it.
2. For a bit test header which covers a contiguous range and hence has no edges to default statement, we don't distribute the default weight to it.
3. When the branch checks a single value or a contiguous range with no edge to default statement, we don't distribute the default weight to it.

In other cases, the default weight is evenly distributed to successors. 

http://reviews.llvm.org/D12418

Files:
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
  lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  test/CodeGen/AArch64/aarch64-deferred-spilling.ll
  test/CodeGen/ARM/jump-table-islands.ll
  test/CodeGen/Generic/MachineBranchProb.ll
  test/CodeGen/Thumb2/v8_IT_3.ll
  test/CodeGen/Thumb2/v8_IT_5.ll
  test/CodeGen/X86/2006-10-19-SwitchUnnecessaryBranching.ll
  test/CodeGen/X86/switch-bt.ll
  test/CodeGen/X86/switch-edge-weight.ll
  test/CodeGen/X86/switch-order-weight.ll
  test/CodeGen/X86/switch.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12418.33377.patch
Type: text/x-patch
Size: 17526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150827/3cacda39/attachment.bin>


More information about the llvm-commits mailing list