diff --git a/llvm/include/llvm/Analysis/Dominators.h b/llvm/include/llvm/Analysis/Dominators.h index b539a788a220..587307314736 100644 --- a/llvm/include/llvm/Analysis/Dominators.h +++ b/llvm/include/llvm/Analysis/Dominators.h @@ -820,7 +820,7 @@ public: DT->splitBlock(NewBB); } - bool isReachableFromEntry(const BasicBlock* A) { + bool isReachableFromEntry(const BasicBlock* A) const { return DT->isReachableFromEntry(A); } diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 37253f72cf6b..b518d0ca71cd 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -92,7 +92,8 @@ static bool ValueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT) { // If we have a DominatorTree then do a precise test. if (DT) - return DT->dominates(I, P); + return !DT->isReachableFromEntry(P->getParent()) || + !DT->isReachableFromEntry(I->getParent()) || DT->dominates(I, P); // Otherwise, if the instruction is in the entry block, and is not an invoke, // then it obviously dominates all phi nodes.