Go to file
Jingyue Wu fc0296704c [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

llvm-svn: 218711
2014-09-30 22:23:38 +00:00
clang InstrProf: Remove an unused member (NFC) 2014-09-30 20:21:50 +00:00
clang-tools-extra [clang-tidy] Updated documentation 2014-09-27 21:47:01 +00:00
compiler-rt [UBsan] Disable summary.cpp on Darwin. The test requires ubsan-asan, which does not work yet. 2014-09-30 13:55:44 +00:00
debuginfo-tests relax testcase for LLDB output format compatibility. 2014-03-19 23:06:18 +00:00
libclc Remove more redundant semi-colons 2014-09-18 09:23:40 +00:00
libcxx Mark module atomic as cplusplus11. 2014-09-24 04:44:54 +00:00
libcxxabi Adding ABI support for __cxa_throw_bad_array_new_length. 2014-09-11 17:26:43 +00:00
lld [PECOFF] Fix /entry option. 2014-09-30 21:39:49 +00:00
lldb Not all processes have a Dynamic Loader. Be sure to check that it exists before using it. 2014-09-30 20:33:25 +00:00
llvm [SimplifyCFG] threshold for folding branches with common destination 2014-09-30 22:23:38 +00:00
openmp Fix a crash that occurred under obscure circumstances during library shutdown 2014-09-03 11:34:33 +00:00
polly Disable runtime alias checks when we ignore aliasing. 2014-09-29 17:06:29 +00:00