Use 'continue' to reduce nesting in this loop. No functionality change.
authorChris Lattner <sabre@nondot.org>
Thu, 22 May 2008 00:53:38 +0000 (00:53 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 22 May 2008 00:53:38 +0000 (00:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51399 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LICM.cpp

index 695a4fb0159fe4ba5a2be0d36ec14e1df70e509a..8ebe2b6812f0f3668fa1a0de4d7599babb38b19f 100644 (file)
@@ -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";
   }
 }