Index: lib/Analysis/LazyValueInfo.cpp =================================================================== --- lib/Analysis/LazyValueInfo.cpp +++ lib/Analysis/LazyValueInfo.cpp @@ -820,11 +820,16 @@ if (!BBI) return; + BasicBlock *BB = BBI->getParent(); for (auto &AssumeVH : AC->assumptionsFor(Val)) { if (!AssumeVH) continue; + + // Only check assumes in the block of the context instruction. Other + // assumes will have already been taken into account when the value was + // propagated from predecessor blocks. auto *I = cast(AssumeVH); - if (!isValidAssumeForContext(I, BBI, DT)) + if (I->getParent() != BB || !isValidAssumeForContext(I, BBI)) continue; BBLV = intersect(BBLV, getValueFromCondition(Val, I->getArgOperand(0))); @@ -836,10 +841,10 @@ if (!GuardDecl || GuardDecl->use_empty()) return; - if (BBI->getIterator() == BBI->getParent()->begin()) + if (BBI->getIterator() == BB->begin()) return; for (Instruction &I : make_range(std::next(BBI->getIterator().getReverse()), - BBI->getParent()->rend())) { + BB->rend())) { Value *Cond = nullptr; if (match(&I, m_Intrinsic(m_Value(Cond)))) BBLV = intersect(BBLV, getValueFromCondition(Val, Cond));