diff options
| author | Devang Patel <dpatel@apple.com> | 2007-06-06 00:21:03 +0000 |
|---|---|---|
| committer | Devang Patel <dpatel@apple.com> | 2007-06-06 00:21:03 +0000 |
| commit | 506310d3ddd8415bf3da649595871b1c45a080e3 (patch) | |
| tree | 2b4e89105b0a0915a14efa493d153936bfa56918 /llvm/lib/Transforms | |
| parent | 31f82dff21ef07787a6333a1ff95f89d21fe9372 (diff) | |
| download | bcm5719-llvm-506310d3ddd8415bf3da649595871b1c45a080e3.tar.gz bcm5719-llvm-506310d3ddd8415bf3da649595871b1c45a080e3.zip | |
Avoid non-trivial loop unswitching while optimizing for size.
llvm-svn: 37446
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index 61510a71003..7ad3bd626c1 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -67,10 +67,12 @@ namespace { // after RewriteLoopBodyWithConditionConstant rewrites first loop. std::vector<Loop*> LoopProcessWorklist; SmallPtrSet<Value *,8> UnswitchedVals; - + + bool OptimizeForSize; public: static char ID; // Pass ID, replacement for typeid - LoopUnswitch() : LoopPass((intptr_t)&ID) {} + LoopUnswitch(bool Os = false) : + LoopPass((intptr_t)&ID), OptimizeForSize(Os) {} bool runOnLoop(Loop *L, LPPassManager &LPM); @@ -116,7 +118,9 @@ namespace { RegisterPass<LoopUnswitch> X("loop-unswitch", "Unswitch loops"); } -LoopPass *llvm::createLoopUnswitchPass() { return new LoopUnswitch(); } +LoopPass *llvm::createLoopUnswitchPass(bool Os) { + return new LoopUnswitch(Os); +} /// FindLIVLoopCondition - Cond is a condition that occurs in L. If it is /// invariant in the loop, or has an invariant piece, return the invariant. @@ -359,6 +363,11 @@ unsigned LoopUnswitch::getLoopUnswitchCost(Loop *L, Value *LIC) { bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val,Loop *L){ // Check to see if it would be profitable to unswitch this loop. unsigned Cost = getLoopUnswitchCost(L, LoopCond); + + // Do not do non-trivial unswitch while optimizing for size. + if (Cost && OptimizeForSize) + return false; + if (Cost > Threshold) { // FIXME: this should estimate growth by the amount of code shared by the // resultant unswitched loops. |

