diff options
author | Chris Lattner <sabre@nondot.org> | 2008-05-22 00:53:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-05-22 00:53:38 +0000 |
commit | 29d929363d9b8a2c0d40c5d50fec022c736cb654 (patch) | |
tree | 2c3f88fa6cae6d4533e7204aa8a437e574efd70b /lib/Transforms/Scalar/LICM.cpp | |
parent | ddc4ee82b51b54605253ffe0e86ce6d38e7729d9 (diff) | |
download | external_llvm-29d929363d9b8a2c0d40c5d50fec022c736cb654.zip external_llvm-29d929363d9b8a2c0d40c5d50fec022c736cb654.tar.gz external_llvm-29d929363d9b8a2c0d40c5d50fec022c736cb654.tar.bz2 |
Use 'continue' to reduce nesting in this loop. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51399 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LICM.cpp')
-rw-r--r-- | lib/Transforms/Scalar/LICM.cpp | 105 |
1 files changed, 51 insertions, 54 deletions
diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp index 695a4fb..8ebe2b6 100644 --- a/lib/Transforms/Scalar/LICM.cpp +++ b/lib/Transforms/Scalar/LICM.cpp @@ -787,72 +787,69 @@ void LICM::FindPromotableValuesInLoop( // We can promote this alias set if it has a store, if it is a "Must" alias // set, if the pointer is loop invariant, and if we are not eliminating any // volatile loads or stores. - if (!AS.isForwardingAliasSet() && AS.isMod() && AS.isMustAlias() && - !AS.isVolatile() && CurLoop->isLoopInvariant(AS.begin()->first)) { - assert(!AS.empty() && - "Must alias set should have at least one pointer element in it!"); - Value *V = AS.begin()->first; - - // Check that all of the pointers in the alias set have the same type. We - // cannot (yet) promote a memory location that is loaded and stored in - // different sizes. + if (AS.isForwardingAliasSet() || !AS.isMod() || !AS.isMustAlias() || + AS.isVolatile() || !CurLoop->isLoopInvariant(AS.begin()->first)) + continue; + + assert(!AS.empty() && + "Must alias set should have at least one pointer element in it!"); + Value *V = AS.begin()->first; + + // Check that all of the pointers in the alias set have the same type. We + // cannot (yet) promote a memory location that is loaded and stored in + // different sizes. + { bool PointerOk = true; for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I) if (V->getType() != I->first->getType()) { PointerOk = false; break; } + if (!PointerOk) + continue; + } - // If one use of value V inside the loop is safe then it is OK to promote - // this value. On the otherside if there is not any unsafe use inside the - // loop then also it is OK to promote this value. Otherwise it is - // unsafe to promote this value. - if (PointerOk) { - bool oneSafeUse = false; - bool oneUnsafeUse = false; - for(Value::use_iterator UI = V->use_begin(), UE = V->use_end(); - UI != UE; ++UI) { - Instruction *Use = dyn_cast<Instruction>(*UI); - if (!Use || !CurLoop->contains(Use->getParent())) - continue; - for (SmallVector<Instruction *, 4>::iterator - ExitI = LoopExits.begin(), ExitE = LoopExits.end(); - ExitI != ExitE; ++ExitI) { - Instruction *Ex = *ExitI; - if (!isa<PHINode>(Use) && DT->dominates(Use, Ex)) { - oneSafeUse = true; - break; - } - else - oneUnsafeUse = true; - } + // If one use of value V inside the loop is safe then it is OK to promote + // this value. On the otherside if there is not any unsafe use inside the + // loop then also it is OK to promote this value. Otherwise it is + // unsafe to promote this value. + bool oneSafeUse = false; + bool oneUnsafeUse = false; + for(Value::use_iterator UI = V->use_begin(), UE = V->use_end(); + UI != UE; ++UI) { + Instruction *Use = dyn_cast<Instruction>(*UI); + if (!Use || !CurLoop->contains(Use->getParent())) + continue; + + for (SmallVector<Instruction *, 4>::iterator + ExitI = LoopExits.begin(), ExitE = LoopExits.end(); + ExitI != ExitE; ++ExitI) { + Instruction *Ex = *ExitI; + if (!isa<PHINode>(Use) && DT->dominates(Use, Ex)) { + oneSafeUse = true; + break; + } else + oneUnsafeUse = true; + } - if (oneSafeUse) - break; - } + if (oneSafeUse) + break; + } - if (oneSafeUse) - PointerOk = true; - else if (!oneUnsafeUse) - PointerOk = true; - else - PointerOk = false; - } - - if (PointerOk) { - const Type *Ty = cast<PointerType>(V->getType())->getElementType(); - AllocaInst *AI = new AllocaInst(Ty, 0, V->getName()+".tmp", FnStart); - PromotedValues.push_back(std::make_pair(AI, V)); + if (!oneSafeUse && oneUnsafeUse) + continue; + + const Type *Ty = cast<PointerType>(V->getType())->getElementType(); + AllocaInst *AI = new AllocaInst(Ty, 0, V->getName()+".tmp", FnStart); + PromotedValues.push_back(std::make_pair(AI, V)); - // Update the AST and alias analysis. - CurAST->copyValue(V, AI); + // Update the AST and alias analysis. + CurAST->copyValue(V, AI); - for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I) - ValueToAllocaMap.insert(std::make_pair(I->first, AI)); + for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I) + ValueToAllocaMap.insert(std::make_pair(I->first, AI)); - DOUT << "LICM: Promoting value: " << *V << "\n"; - } - } + DOUT << "LICM: Promoting value: " << *V << "\n"; } } |