Index: lib/Transforms/Scalar/LICM.cpp =================================================================== --- lib/Transforms/Scalar/LICM.cpp +++ lib/Transforms/Scalar/LICM.cpp @@ -165,10 +165,9 @@ /// Simple Analysis hook. Delete loop L from alias set map. void deleteAnalysisLoop(Loop *L) override; - /// Returns an owning pointer to an alias set which incorporates aliasing - /// info from all subloops of L, but does not include instructions in L - /// itself. - AliasSetTracker *collectAliasInfoFromSubLoops(Loop *L); + /// Calculates an alias set which incorporates aliasing info from all + /// subloops of L and L itself by using LoopToAliasSetMap. + void collectAliasInfoFastPath(Loop *L); }; } @@ -207,22 +206,25 @@ assert(L->isLCSSAForm(*DT) && "Loop is not in LCSSA form."); - CurAST = collectAliasInfoFromSubLoops(L); + // Use the fast path to collect alias info if no other loop passes can modify + // the sub loops. + bool FastPath = (LPM.getNumContainedPasses() == 1); + + if (FastPath) { + collectAliasInfoFastPath(L); + } else { + CurAST = new AliasSetTracker(*AA); + + // Loop over the body of this loop, looking for calls, invokes, and stores. + for (BasicBlock *BB : L->blocks()) + CurAST->add(*BB); // Incorporate the specified basic block + } CurLoop = L; // Get the preheader block to move instructions into... Preheader = L->getLoopPreheader(); - // Loop over the body of this loop, looking for calls, invokes, and stores. - // Because subloops have already been incorporated into AST, we skip blocks in - // subloops. - // - for (BasicBlock *BB : L->blocks()) { - if (LI->getLoopFor(BB) == L) // Ignore blocks in subloops. - CurAST->add(*BB); // Incorporate the specified basic block - } - // Compute loop safety information. LICMSafetyInfo SafetyInfo; computeLICMSafetyInfo(&SafetyInfo, CurLoop); @@ -282,7 +284,7 @@ // If this loop is nested inside of another one, save the alias information // for when we process the outer loop. - if (L->getParentLoop()) + if (L->getParentLoop() && FastPath) LoopToAliasSetMap[L] = CurAST; else delete CurAST; @@ -1057,17 +1059,16 @@ return Changed; } -/// Returns an owning pointer to an alias set which incorporates aliasing info -/// from all subloops of L, but does not include instructions in L itself. +/// Calculates an alias set which incorporates aliasing info from all subloops +/// of L and L itself by using LoopToAliasSetMap. /// -AliasSetTracker *LICM::collectAliasInfoFromSubLoops(Loop *L) { - AliasSetTracker *CurAST = nullptr; +void LICM::collectAliasInfoFastPath(Loop *L) { + CurAST = nullptr; for (Loop *InnerL : L->getSubLoops()) { AliasSetTracker *InnerAST = LoopToAliasSetMap[InnerL]; assert(InnerAST && "Where is my AST?"); if (CurAST != nullptr) { - // What if InnerLoop was modified by other passes ? CurAST->add(*InnerAST); // Once we've incorporated the inner loop's AST into ours, we don't need @@ -1080,7 +1081,17 @@ } if (CurAST == nullptr) CurAST = new AliasSetTracker(*AA); - return CurAST; + + // Loop over the body of this loop, looking for calls, invokes, and stores. + // Because subloops have already been incorporated into AST, we skip blocks in + // subloops. + // + for (BasicBlock *BB : L->blocks()) { + if (LI->getLoopFor(BB) == L) // Ignore blocks in subloops. + CurAST->add(*BB); // Incorporate the specified basic block + } + + return; } /// Simple analysis hook. Clone alias set info.