diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -597,17 +597,10 @@ if (Inv->getParent() != CxtI->getParent()) return false; - // If we have a dom tree, then we now know that the assume doesn't dominate - // the other instruction. If we don't have a dom tree then we can check if - // the assume is first in the BB. - if (!DT) { - // Search forward from the assume until we reach the context (or the end - // of the block); the common case is that the assume will come first. - for (auto I = std::next(BasicBlock::const_iterator(Inv)), - IE = Inv->getParent()->end(); I != IE; ++I) - if (&*I == CxtI) - return true; - } + // If Inv and CtxI are in the same block, check if the assume (Inv) is first + // in the BB. + if (Inv->comesBefore(CxtI)) + return true; // Don't let an assume affect itself - this would cause the problems // `isEphemeralValueOf` is trying to prevent, and it would also make