fix two more cases where we could let the NLPDI cache get unsorted.
With this, sqlite3 now passes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62839 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp
index 8670890..6af365b 100644
--- a/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -788,10 +788,15 @@
     //     cerr << "OP:\t\t\t\t" << *PtrInst->getOperand(0);
   PredTranslationFailure:
     
-    // Refresh the CacheInfo/Cache pointer so that it isn't invalidated.
-    CacheInfo = &NonLocalPointerDeps[CacheKey];
-    Cache = &CacheInfo->second;
-    NumSortedEntries = Cache->size();
+    if (Cache == 0) {
+      // Refresh the CacheInfo/Cache pointer if it got invalidated.
+      CacheInfo = &NonLocalPointerDeps[CacheKey];
+      Cache = &CacheInfo->second;
+      NumSortedEntries = Cache->size();
+    } else if (NumSortedEntries != Cache->size()) {
+      std::sort(Cache->begin(), Cache->end());
+      NumSortedEntries = Cache->size();
+    }
 
     // Since we did phi translation, the "Cache" set won't contain all of the
     // results for the query.  This is ok (we can still use it to accelerate
@@ -821,7 +826,7 @@
       break;
     }
   }
-  
+
   // Okay, we're done now.  If we added new values to the cache, re-sort it.
   switch (Cache->size()-NumSortedEntries) {
   case 0:
@@ -1045,6 +1050,10 @@
         if (Instruction *NewDirtyInst = NewDirtyVal.getInst())
           ReversePtrDepsToAdd.push_back(std::make_pair(NewDirtyInst, P));
       }
+      
+      // Re-sort the NonLocalDepInfo.  Changing the dirty entry to its
+      // subsequent value may invalidate the sortedness.
+      std::sort(NLPDI.begin(), NLPDI.end());
     }
     
     ReverseNonLocalPtrDeps.erase(ReversePtrDepIt);