[PATCH] D73032: [WIP][DependenceAnalysis] Fix for PR42733.

Evgeniy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 04:44:52 PST 2020


ebrevnov created this revision.
Herald added subscribers: llvm-commits, bmahjour, hiraditya.
Herald added a project: LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73032

Files:
  llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h
  llvm/lib/Analysis/MemoryDependenceAnalysis.cpp


Index: llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -1033,7 +1033,8 @@
     Instruction *QueryInst, const PHITransAddr &Pointer,
     const MemoryLocation &Loc, bool isLoad, BasicBlock *StartBB,
     SmallVectorImpl<NonLocalDepResult> &Result,
-    DenseMap<BasicBlock *, Value *> &Visited, bool SkipFirstBlock) {
+    DenseMap<BasicBlock *, Value *> &Visited, bool SkipFirstBlock,
+    bool IsIncomplete) {
   // Look up the cached info for Pointer.
   ValueIsLoadPair CacheKey(Pointer.getAddr(), isLoad);
 
@@ -1082,12 +1083,16 @@
           if (Instruction *Inst = Entry.getResult().getInst())
             RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey);
         CacheInfo->NonLocalDeps.clear();
+        // The cache is cleared (in the above line) but list of visited blocks
+        // is not. That means the cache will be missing information about
+        // visited blocks, thus incomplete.
+        IsIncomplete = true;
       } else {
         // This query's Size is less than the cached one. Conservatively restart
         // the query using the greater size.
         return getNonLocalPointerDepFromBB(
             QueryInst, Pointer, Loc.getWithNewSize(CacheInfo->Size), isLoad,
-            StartBB, Result, Visited, SkipFirstBlock);
+            StartBB, Result, Visited, SkipFirstBlock, IsIncomplete);
       }
     }
 
@@ -1102,11 +1107,15 @@
           if (Instruction *Inst = Entry.getResult().getInst())
             RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey);
         CacheInfo->NonLocalDeps.clear();
+        // The cache is cleared (in the above line) but list of visited blocks
+        // is not. That means the cache will be missing information about
+        // visited blocks, thus incomplete.
+        IsIncomplete = true;
       }
       if (Loc.AATags)
         return getNonLocalPointerDepFromBB(
             QueryInst, Pointer, Loc.getWithoutAATags(), isLoad, StartBB, Result,
-            Visited, SkipFirstBlock);
+            Visited, SkipFirstBlock, IsIncomplete);
     }
   }
 
@@ -1116,7 +1125,8 @@
   // investigating, just return it with no recomputation.
   // Don't use cached information for invariant loads since it is valid for
   // non-invariant loads only.
-  if (!isInvariantLoad &&
+  //
+  if (!IsIncomplete && !isInvariantLoad &&
       CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) {
     // We have a fully cached result for this query then we can just return the
     // cached results and populate the visited set.  However, we have to verify
@@ -1158,9 +1168,9 @@
   if (!isInvariantLoad) {
     // Otherwise, either this is a new block, a block with an invalid cache
     // pointer or one that we're about to invalidate by putting more info into
-    // it than its valid cache info.  If empty, the result will be valid cache
-    // info, otherwise it isn't.
-    if (Cache->empty())
+    // it than its valid cache info.  If empty and not explicitly indicated as
+    // incomplete, the result will be valid cache info, otherwise it isn't.
+    if (!IsIncomplete && Cache->empty())
       CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock);
     else
       CacheInfo->Pair = BBSkipFirstBlockPair();
Index: llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h
===================================================================
--- llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h
+++ llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h
@@ -481,7 +481,8 @@
                                    BasicBlock *BB,
                                    SmallVectorImpl<NonLocalDepResult> &Result,
                                    DenseMap<BasicBlock *, Value *> &Visited,
-                                   bool SkipFirstBlock = false);
+                                   bool SkipFirstBlock = false,
+                                   bool IsIncomplete = false);
   MemDepResult GetNonLocalInfoForBlock(Instruction *QueryInst,
                                        const MemoryLocation &Loc, bool isLoad,
                                        BasicBlock *BB, NonLocalDepInfo *Cache,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73032.239078.patch
Type: text/x-patch
Size: 4303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200120/a747fc0a/attachment.bin>


More information about the llvm-commits mailing list