diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index edbf9337f37..538a394d46d 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -135,6 +135,13 @@ void MemoryDependenceAnalysis::nonLocalHelper(Instruction* query, DenseMap& resp) { // Set of blocks that we've already visited in our DFS SmallPtrSet visited; + // If we're updating a dirtied cache entry, we don't need to reprocess + // already computed entries. + for (DenseMap::iterator I = resp.begin(), + E = resp.end(); I != E; ++I) + if (I->second != Dirty) + visited.insert(I->first); + // Current stack of the DFS SmallVector stack; stack.push_back(block); @@ -211,8 +218,28 @@ void MemoryDependenceAnalysis::nonLocalHelper(Instruction* query, void MemoryDependenceAnalysis::getNonLocalDependency(Instruction* query, DenseMap& resp) { if (depGraphNonLocal.count(query)) { - resp = depGraphNonLocal[query]; + DenseMap& cached = depGraphNonLocal[query]; NumCacheNonlocal++; + + SmallVector dirtied; + for (DenseMap::iterator I = cached.begin(), + E = cached.end(); I != E; ++I) + if (I->second == Dirty) + dirtied.push_back(I->first); + + for (SmallVector::iterator I = dirtied.begin(), + E = dirtied.end(); I != E; ++I) { + Instruction* localDep = getDependency(query, 0, *I); + if (localDep != NonLocal) + cached[*I] = localDep; + else { + cached.erase(*I); + nonLocalHelper(query, *I, cached); + } + } + + resp = cached; + return; } else NumUncacheNonlocal++; @@ -430,7 +457,11 @@ void MemoryDependenceAnalysis::removeInstruction(Instruction* rem) { SmallPtrSet& set = reverseDepNonLocal[rem]; for (SmallPtrSet::iterator I = set.begin(), E = set.end(); I != E; ++I) - depGraphNonLocal.erase(*I); + for (DenseMap::iterator DI = + depGraphNonLocal[*I].begin(), DE = depGraphNonLocal[*I].end(); + DI != DE; ++DI) + if (DI->second == rem) + DI->second = Dirty; reverseDepNonLocal.erase(rem); } diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index c6b50a4002d..d9cff01f2c3 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -834,7 +834,7 @@ bool GVN::processNonLocalLoad(LoadInst* L, return false; } else if (I->second == MemoryDependenceAnalysis::NonLocal) { continue; - }else if (StoreInst* S = dyn_cast(I->second)) { + } else if (StoreInst* S = dyn_cast(I->second)) { if (S->getPointerOperand() == L->getPointerOperand()) repl[I->first] = S->getOperand(0); else