diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 20b886e4aa0..81194adb373 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -2468,6 +2468,11 @@ const SCEV *ScalarEvolution::getSCEV(Value *V) { std::map::const_iterator I = Scalars.find(V); if (I != Scalars.end()) return I->second; const SCEV *S = createSCEV(V); + + // The process of creating a SCEV for V may have caused other SCEVs + // to have been created, so it's necessary to insert the new entry + // from scratch, rather than trying to remember the insert position + // above. Scalars.insert(std::make_pair(SCEVCallbackVH(V, this), S)); return S; }