llvm-6502/lib
Jingyue Wu 9cd9e4bb2c [SimplifyCFG] threshold for folding branches with common destination
Summary:
This patch adds a threshold that controls the number of bonus instructions
allowed for folding branches with common destination. The original code allows
at most one bonus instruction. With this patch, users can customize the
threshold to allow multiple bonus instructions. The default threshold is still
1, so that the code behaves the same as before when users do not specify this
threshold.

The motivation of this change is that tuning this threshold significantly (up
to 25%) improves the performance of some CUDA programs in our internal code
base. In general, branch instructions are very expensive for GPU programs.
Therefore, it is sometimes worth trading more arithmetic computation for a more
straightened control flow. Here's a reduced example:

  __global__ void foo(int a, int b, int c, int d, int e, int n,
                      const int *input, int *output) {
    int sum = 0;
    for (int i = 0; i < n; ++i)
      sum += (((i ^ a) > b) && (((i | c ) ^ d) > e)) ? 0 : input[i];
    *output = sum;
  }

The select statement in the loop body translates to two branch instructions "if
((i ^ a) > b)" and "if (((i | c) ^ d) > e)" which share a common destination.
With the default threshold, SimplifyCFG is unable to fold them, because
computing the condition of the second branch "(i | c) ^ d > e" requires two
bonus instructions. With the threshold increased, SimplifyCFG can fold the two
branches so that the loop body contains only one branch, making the code
conceptually look like:

  sum += (((i ^ a) > b) & (((i | c ) ^ d) > e)) ? 0 : input[i];

Increasing the threshold significantly improves the performance of this
particular example. In the configuration where both conditions are guaranteed
to be true, increasing the threshold from 1 to 2 improves the performance by
18.24%. Even in the configuration where the first condition is false and the
second condition is true, which favors shortcuts, increasing the threshold from
1 to 2 still improves the performance by 4.35%.

We are still looking for a good threshold and maybe a better cost model than
just counting the number of bonus instructions. However, according to the above
numbers, we think it is at least worth adding a threshold to enable more
experiments and tuning. Let me know what you think. Thanks!

Test Plan: Added one test case to check the threshold is in effect

Reviewers: nadav, eliben, meheff, resistor, hfinkel

Reviewed By: hfinkel

Subscribers: hfinkel, llvm-commits

Differential Revision: http://reviews.llvm.org/D5529

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218711 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-30 22:23:38 +00:00
..
Analysis Ignore annotation function calls in cost computation 2014-09-26 17:48:40 +00:00
AsmParser Make CallingConv::ID an alias of "unsigned". 2014-09-10 18:00:17 +00:00
Bitcode Do not destroy external linkage when deleting function body 2014-09-23 12:54:19 +00:00
CodeGen Disable the -gmlt optimization implemented in r218129 under Darwin due to issues with dsymutil. 2014-09-30 21:28:32 +00:00
DebugInfo Store TypeUnits in a SmallVector<DWARFUnitSection> instead of a single DWARFUnitSection. 2014-09-29 13:56:39 +00:00
ExecutionEngine Unit test r218187, changing RTDyldMemoryManager::getSymbolAddress's behavior favor mangled lookup over unmangled lookup. 2014-09-29 21:25:13 +00:00
IR [AVX512] Added intrinsics for VPCMPEQB and VPCMPEQW. 2014-09-30 11:32:22 +00:00
IRReader Pass a && to getLazyBitcodeModule. 2014-09-03 17:31:46 +00:00
LineEditor
Linker Merge alignment of common GlobalValue. 2014-09-09 17:48:18 +00:00
LTO LTO: introduce object file-based on-disk module format. 2014-09-18 21:28:49 +00:00
MC Extend C disassembler API to allow specifying target features 2014-09-30 16:31:40 +00:00
Object Object: BSS/virtual sections don't have contents 2014-09-26 22:32:16 +00:00
Option Add an overload of getLastArgNoClaim taking two OptSpecifiers. 2014-09-12 19:42:53 +00:00
ProfileData llvm-cov: Use the number of executed functions for the function coverage metric. 2014-09-30 12:45:13 +00:00
Support Fix llvm::huge_valf multiple initializations with Visual C++. 2014-09-27 14:41:29 +00:00
TableGen Refactoring: raw pointer -> unique_ptr 2014-09-25 19:55:58 +00:00
Target Split the estimate() interface into separate functions for each type. NFC. 2014-09-30 20:28:48 +00:00
Transforms [SimplifyCFG] threshold for folding branches with common destination 2014-09-30 22:23:38 +00:00
CMakeLists.txt
LLVMBuild.txt
Makefile