diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index 2012ab473c9..1cd16bb06de 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -19,6 +19,7 @@ #include "llvm/Instructions.h" #include "llvm/Function.h" #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/Dominators.h" #include "llvm/Support/CFG.h" #include "llvm/Support/CommandLine.h" #include "llvm/Target/TargetData.h" @@ -82,6 +83,7 @@ void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); AU.addRequiredTransitive(); AU.addRequiredTransitive(); + AU.addRequiredTransitive(); } /// getCallSiteDependency - Private helper for finding the local dependencies @@ -222,6 +224,17 @@ void MemoryDependenceAnalysis::nonLocalHelper(Instruction* query, continue; } + // Don't recur upwards if the current block is unreachable. + // Instead, mark it as having no dependency on this path, + // which will block optzns from occuring. For this reason, + // eliminating unreachable blocks before running a memdep + // based optimization is recommended. + DominatorTree& DT = getAnalysis(); + if (!DT.isReachableFromEntry(BB)) { + resp.insert(std::make_pair(BB, None)); + continue; + } + // If we didn't find anything, recurse on the precessors of this block // Only do this for blocks with a small number of predecessors. bool predOnStack = false;