diff options
| author | Dan Gohman <gohman@apple.com> | 2009-10-13 17:50:43 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-10-13 17:50:43 +0000 |
| commit | 71ca6524757fff5399080891ed72ab13aa54067c (patch) | |
| tree | c716cac7db226e0eb1863f63f8b11f3462dbbafc /llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | |
| parent | aa61f41e56fc94361126f684fcf3623daf7d0504 (diff) | |
| download | bcm5719-llvm-71ca6524757fff5399080891ed72ab13aa54067c.tar.gz bcm5719-llvm-71ca6524757fff5399080891ed72ab13aa54067c.zip | |
Make LoopUnswitch's cost estimation count Instructions, rather than
BasicBlocks, so that it doesn't blindly procede in the presence of
large individual BasicBlocks. This addresses a class of code-size
expansion problems.
llvm-svn: 83992
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopUnswitch.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index b1f421467ec..f116d5314e9 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -56,9 +56,11 @@ STATISTIC(NumSelects , "Number of selects unswitched"); STATISTIC(NumTrivial , "Number of unswitches that are trivial"); STATISTIC(NumSimplify, "Number of simplifications of unswitched code"); +// The specific value of 50 here was chosen based only on intuition and a +// few specific examples. static cl::opt<unsigned> Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), - cl::init(10), cl::Hidden); + cl::init(50), cl::Hidden); namespace { class LoopUnswitch : public LoopPass { @@ -406,27 +408,13 @@ unsigned LoopUnswitch::getLoopUnswitchCost(Value *LIC) { if (IsTrivialUnswitchCondition(LIC)) return 0; - // FIXME: This is really overly conservative. However, more liberal - // estimations have thus far resulted in excessive unswitching, which is bad - // both in compile time and in code size. This should be replaced once - // someone figures out how a good estimation. - return currentLoop->getBlocks().size(); - + // FIXME: This is really overly conservative and brain dead. unsigned Cost = 0; - // FIXME: this is brain dead. It should take into consideration code - // shrinkage. for (Loop::block_iterator I = currentLoop->block_begin(), E = currentLoop->block_end(); - I != E; ++I) { - BasicBlock *BB = *I; - // Do not include empty blocks in the cost calculation. This happen due to - // loop canonicalization and will be removed. - if (BB->begin() == BasicBlock::iterator(BB->getTerminator())) - continue; - - // Count basic blocks. - ++Cost; - } + I != E; ++I) + // Count instructions. + Cost += (*I)->size(); return Cost; } |

