Index: include/llvm/Analysis/AssumptionCache.h =================================================================== --- include/llvm/Analysis/AssumptionCache.h +++ include/llvm/Analysis/AssumptionCache.h @@ -70,6 +70,9 @@ /// Get the vector of assumptions which affect a value from the cache. SmallVector &getAffectedValues(Value *V); + /// Copy affected values in the cache for OV to be affected values for NV. + void copyAffectedValuesInCache(Value *OV, Value *NV); + /// \brief Flag tracking whether we have scanned the function yet. /// /// We want to be as lazy about this as possible, and so we scan the function Index: lib/Analysis/AssumptionCache.cpp =================================================================== --- lib/Analysis/AssumptionCache.cpp +++ lib/Analysis/AssumptionCache.cpp @@ -111,20 +111,25 @@ // 'this' now dangles! } +void AssumptionCache::copyAffectedValuesInCache(Value *OV, Value *NV) { + auto &NAVV = getAffectedValues(NV); + auto AVI = AffectedValues.find(OV); + if (AVI == AffectedValues.end()) + return; + + for (auto &A : AVI->second) + if (std::find(NAVV.begin(), NAVV.end(), A) == NAVV.end()) + NAVV.push_back(A); +} + void AssumptionCache::AffectedValueCallbackVH::allUsesReplacedWith(Value *NV) { if (!isa(NV) && !isa(NV)) return; // Any assumptions that affected this value now affect the new value. - auto &NAVV = AC->getAffectedValues(NV); - auto AVI = AC->AffectedValues.find(getValPtr()); - if (AVI == AC->AffectedValues.end()) - return; - - for (auto &A : AVI->second) - if (std::find(NAVV.begin(), NAVV.end(), A) == NAVV.end()) - NAVV.push_back(A); + AC->copyAffectedValuesInCache(getValPtr(), NV); + // 'this' now might dangle! } void AssumptionCache::scanFunction() {