diff options
author | Chen Li <meloli87@gmail.com> | 2015-08-13 05:24:29 +0000 |
---|---|---|
committer | Chen Li <meloli87@gmail.com> | 2015-08-13 05:24:29 +0000 |
commit | f458c6f31387c131613305bb3885cd319e27865d (patch) | |
tree | 9f80253280d546dbe5b80743c00fa22b4468c1d3 /llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | |
parent | 1193f2cbc021f040eef6f97ec72dad5fb1efb7b1 (diff) | |
download | llvm-f458c6f31387c131613305bb3885cd319e27865d.zip llvm-f458c6f31387c131613305bb3885cd319e27865d.tar.gz llvm-f458c6f31387c131613305bb3885cd319e27865d.tar.bz2 |
[LoopUnswitch] Check OptimizeForSize before traversing over all basic blocks in current loop
Summary: This patch moves the check of OptimizeForSize before traversing over all basic blocks in current loop. If OptimizeForSize is set to true, no non-trivial unswitch is ever allowed. Therefore, the early exit will help reduce compilation time. This patch should be NFC.
Reviewers: reames, weimingz, broune
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D11997
llvm-svn: 244868
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopUnswitch.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopUnswitch.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp index 08b52d6..62047b9 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -463,6 +463,12 @@ bool LoopUnswitch::processCurrentLoop() { return true; } + // Do not do non-trivial unswitch while optimizing for size. + // FIXME: Use Function::optForSize(). + if (OptimizeForSize || + loopHeader->getParent()->hasFnAttribute(Attribute::OptimizeForSize)) + return false; + // Loop over all of the basic blocks in the loop. If we find an interior // block that is branching on a loop-invariant condition, we can unswitch this // loop. @@ -586,8 +592,6 @@ static BasicBlock *isTrivialLoopExitBlock(Loop *L, BasicBlock *BB) { /// unswitch the loop, reprocess the pieces, then return true. bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val, TerminatorInst *TI) { - Function *F = loopHeader->getParent(); - // Check to see if it would be profitable to unswitch current loop. if (!BranchesInfo.CostAllowsUnswitching()) { DEBUG(dbgs() << "NOT unswitching loop %" @@ -598,11 +602,6 @@ bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val, return false; } - // Do not do non-trivial unswitch while optimizing for size. - // FIXME: Use Function::optForSize(). - if (OptimizeForSize || F->hasFnAttribute(Attribute::OptimizeForSize)) - return false; - UnswitchNontrivialCondition(LoopCond, Val, currentLoop, TI); return true; } |