diff options
author | Devang Patel <dpatel@apple.com> | 2007-06-28 02:05:46 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2007-06-28 02:05:46 +0000 |
commit | eb62eca5033f3b2f22a2d09362397660bf3b05f3 (patch) | |
tree | 67ebdab8d927496f31cc6147bd047ac0d82b1b86 /lib/Transforms/Scalar/LoopUnswitch.cpp | |
parent | cce624a7a9c0022fc75afe2e58997ed9f53d9adc (diff) |
- Undo previous check and allow loop switch for condtion that is not inside
loop.
- Avoid loop unswich for loop header branch.
- While cloning dominators fix typo and handle self dominating blocks.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37772 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopUnswitch.cpp')
-rw-r--r-- | lib/Transforms/Scalar/LoopUnswitch.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 142299dc99..157b00916c 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -136,13 +136,6 @@ static Value *FindLIVLoopCondition(Value *Cond, Loop *L, bool &Changed) { // Constants should be folded, not unswitched on! if (isa<Constant>(Cond)) return false; - // If cond is not in loop then it is not suitable. - if (Instruction *I = dyn_cast<Instruction>(Cond)) - if (!L->contains(I->getParent())) - return 0; - if (isa<Argument>(Cond)) - return 0; - // TODO: Handle: br (VARIANT|INVARIANT). // TODO: Hoist simple expressions out of loops. if (L->isLoopInvariant(Cond)) return Cond; @@ -173,6 +166,8 @@ bool LoopUnswitch::runOnLoop(Loop *L, LPPassManager &LPM_Ref) { // loop. for (Loop::block_iterator I = L->block_begin(), E = L->block_end(); I != E; ++I) { + if (*I == L->getHeader()) + continue; TerminatorInst *TI = (*I)->getTerminator(); if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { // If this isn't branching on an invariant condition, we can't unswitch @@ -491,7 +486,11 @@ void CloneDomInfo(BasicBlock *NewBB, BasicBlock *Orig, Loop *L, CloneDomInfo(NewIDom, OrigIDom, L, DT, VM); NewIDom = cast<BasicBlock>(VM[OrigIDom]); } - DT->addNewBlock(NewBB, OrigIDom); + if (NewBB == NewIDom) { + DT->addNewBlock(NewBB, OrigIDom); + DT->changeImmediateDominator(NewBB, NewIDom); + } else + DT->addNewBlock(NewBB, NewIDom); } /// CloneLoop - Recursively clone the specified loop and all of its children, |