[llvm-commits] [llvm] r83992 - /llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp
Dan Gohman
gohman at apple.com
Tue Oct 13 10:50:43 PDT 2009
Author: djg
Date: Tue Oct 13 12:50:43 2009
New Revision: 83992
URL: http://llvm.org/viewvc/llvm-project?rev=83992&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp?rev=83992&r1=83991&r2=83992&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp Tue Oct 13 12:50:43 2009
@@ -56,9 +56,11 @@
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 @@
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;
}
More information about the llvm-commits
mailing list