diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index e3ce9eb62a4..7799befb3c2 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -1054,7 +1054,8 @@ bool GVN::processInstruction(Instruction* I, if (CI->getCalledFunction() && !AA.doesNotAccessMemory(CI->getCalledFunction())) { MemoryDependenceAnalysis& MD = getAnalysis(); - if (MD.getDependency(CI) != MD.getDependency(cast(repl))) { + if (cast(repl)->getParent() != CI->getParent() || + MD.getDependency(CI) != MD.getDependency(cast(repl))) { // There must be an intervening may-alias store, so nothing from // this point on will be able to be replaced with the preceding call currAvail.erase(repl);