mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-27 14:45:50 +00:00
9cd9e4bb2c
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 |
||
---|---|---|
.. | ||
SPARC | ||
X86 | ||
2002-05-21-PHIElimination.ll | ||
2002-09-24-PHIAssertion.ll | ||
2003-03-07-DominateProblem.ll | ||
2003-08-05-InvokeCrash.ll | ||
2003-08-17-BranchFold.ll | ||
2003-08-17-BranchFoldOrdering.ll | ||
2003-08-17-FoldSwitch-dbg.ll | ||
2003-08-17-FoldSwitch.ll | ||
2004-12-10-SimplifyCFGCrash.ll | ||
2005-06-16-PHICrash.ll | ||
2005-08-01-PHIUpdateFail.ll | ||
2005-10-02-InvokeSimplify.ll | ||
2005-12-03-IncorrectPHIFold.ll | ||
2006-02-17-InfiniteUnroll.ll | ||
2006-06-12-InfLoop.ll | ||
2006-08-03-Crash.ll | ||
2006-10-19-UncondDiv.ll | ||
2006-12-08-Ptr-ICmp-Branch.ll | ||
2007-11-22-InvokeNoUnwind.ll | ||
2007-12-21-Crash.ll | ||
2008-01-02-hoist-fp-add.ll | ||
2008-05-16-PHIBlockMerge.ll | ||
2008-07-13-InfLoopMiscompile.ll | ||
2008-09-08-MultiplePred.ll | ||
2008-09-17-SpeculativeHoist.ll | ||
2008-10-03-SpeculativelyExecuteBeforePHI.ll | ||
2008-12-06-SingleEntryPhi.ll | ||
2008-12-16-DCECond.ll | ||
2009-01-18-PHIPropCrash.ll | ||
2009-01-19-UnconditionalTrappingConstantExpr.ll | ||
2009-05-12-externweak.ll | ||
2010-03-30-InvokeCrash.ll | ||
2011-03-08-UnreachableUse.ll | ||
2011-09-05-TrivialLPad.ll | ||
assume.ll | ||
attr-noduplicate.ll | ||
basictest.ll | ||
branch-cond-merge.ll | ||
branch-cond-prop.ll | ||
branch-fold-dbg.ll | ||
branch-fold-test.ll | ||
branch-fold-threshold.ll | ||
branch-fold.ll | ||
branch-phi-thread.ll | ||
BrUnwind.ll | ||
common-dest-folding.ll | ||
CoveredLookupTable.ll | ||
dbginfo.ll | ||
dce-cond-after-folding-terminator.ll | ||
DeadSetCC.ll | ||
duplicate-phis.ll | ||
EmptyBlockMerge.ll | ||
EqualPHIEdgeBlockMerge.ll | ||
extract-cost.ll | ||
ForwardSwitchConditionToPHI.ll | ||
hoist-common-code.ll | ||
hoist-dbgvalue.ll | ||
hoist-with-range.ll | ||
HoistCode.ll | ||
indirectbr.ll | ||
invoke_unwind.ll | ||
invoke.ll | ||
iterative-simplify.ll | ||
lifetime.ll | ||
MagicPointer.ll | ||
multiple-phis.ll | ||
no_speculative_loads_with_tsan.ll | ||
noreturn-call.ll | ||
phi-undef-loadstore.ll | ||
PhiBlockMerge2.ll | ||
PhiBlockMerge.ll | ||
PhiEliminate2.ll | ||
PhiEliminate3.ll | ||
PhiEliminate.ll | ||
PHINode.ll | ||
PhiNoEliminate.ll | ||
PR9946.ll | ||
PR16069.ll | ||
PR17073.ll | ||
preserve-branchweights-partial.ll | ||
preserve-branchweights-switch-create.ll | ||
preserve-branchweights.ll | ||
return-merge.ll | ||
select-gep.ll | ||
sink-common-code.ll | ||
speculate-math.ll | ||
speculate-store.ll | ||
speculate-vector-ops.ll | ||
speculate-with-offset.ll | ||
SpeculativeExec.ll | ||
switch_create.ll | ||
switch_switch_fold.ll | ||
switch_thread.ll | ||
switch-masked-bits.ll | ||
switch-on-const-select.ll | ||
switch-simplify-crash.ll | ||
switch-to-icmp.ll | ||
trap-debugloc.ll | ||
trapping-load-unreachable.ll | ||
trivial-throw.ll | ||
two-entry-phi-return.ll | ||
UncondBranchToReturn.ll | ||
unreachable-blocks.ll | ||
UnreachableEliminate.ll | ||
volatile-phioper.ll |