[PATCH] D64405: [DependenceAnalysis] Dependecies for loads marked with "ivnariant.load" should not be shared with general accesses. Fix for https://bugs.llvm.org/show_bug.cgi?id=42151

Evgeniy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 9 05:08:32 PDT 2019


ebrevnov updated this revision to Diff 208646.
ebrevnov added a comment.

Remove accidental changes.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64405/new/

https://reviews.llvm.org/D64405

Files:
  lib/Analysis/MemoryDependenceAnalysis.cpp


Index: lib/Analysis/MemoryDependenceAnalysis.cpp
===================================================================
--- lib/Analysis/MemoryDependenceAnalysis.cpp
+++ lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -978,22 +978,32 @@
     Instruction *QueryInst, const MemoryLocation &Loc, bool isLoad,
     BasicBlock *BB, NonLocalDepInfo *Cache, unsigned NumSortedEntries) {
 
-  // Do a binary search to see if we already have an entry for this block in
-  // the cache set.  If so, find it.
-  NonLocalDepInfo::iterator Entry = std::upper_bound(
-      Cache->begin(), Cache->begin() + NumSortedEntries, NonLocalDepEntry(BB));
-  if (Entry != Cache->begin() && (Entry - 1)->getBB() == BB)
-    --Entry;
-
   NonLocalDepEntry *ExistingResult = nullptr;
-  if (Entry != Cache->begin() + NumSortedEntries && Entry->getBB() == BB)
-    ExistingResult = &*Entry;
-
-  // If we have a cached entry, and it is non-dirty, use it as the value for
-  // this dependency.
-  if (ExistingResult && !ExistingResult->getResult().isDirty()) {
-    ++NumCacheNonLocalPtr;
-    return ExistingResult->getResult();
+  bool isInvariantLoad = false;
+
+  if (LoadInst *LI = dyn_cast_or_null<LoadInst>(QueryInst))
+      isInvariantLoad = LI->getMetadata(LLVMContext::MD_invariant_load);
+
+  // Due to a semantic of invariant load many dependencies are ignored. Thus
+  // results of dependence analysis can't be shared with general case.
+  // Don't use cached results for invariant load.
+  if (!isInvariantLoad) {
+    // Do a binary search to see if we already have an entry for this block in
+    // the cache set.  If so, find it.
+    NonLocalDepInfo::iterator Entry = std::upper_bound(
+        Cache->begin(), Cache->begin() + NumSortedEntries, NonLocalDepEntry(BB));
+    if (Entry != Cache->begin() && (Entry - 1)->getBB() == BB)
+      --Entry;
+
+    if (Entry != Cache->begin() + NumSortedEntries && Entry->getBB() == BB)
+      ExistingResult = &*Entry;
+
+    // If we have a cached entry, and it is non-dirty, use it as the value for
+    // this dependency.
+    if (ExistingResult && !ExistingResult->getResult().isDirty()) {
+      ++NumCacheNonLocalPtr;
+      return ExistingResult->getResult();
+    }
   }
 
   // Otherwise, we have to scan for the value.  If we have a dirty cache
@@ -1017,12 +1027,14 @@
   MemDepResult Dep =
       getPointerDependencyFrom(Loc, isLoad, ScanPos, BB, QueryInst);
 
-  // If we had a dirty entry for the block, update it.  Otherwise, just add
-  // a new entry.
-  if (ExistingResult)
-    ExistingResult->setResult(Dep);
-  else
-    Cache->push_back(NonLocalDepEntry(BB, Dep));
+  // Don't put results of dependence analysis into cache.
+  if (!isInvariantLoad)
+    // If we had a dirty entry for the block, update it.  Otherwise, just add
+    // a new entry.
+    if (ExistingResult)
+      ExistingResult->setResult(Dep);
+    else
+      Cache->push_back(NonLocalDepEntry(BB, Dep));
 
   // If the block has a dependency (i.e. it isn't completely transparent to
   // the value), remember the reverse association because we just added it


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64405.208646.patch
Type: text/x-patch
Size: 3084 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190709/30f653e1/attachment.bin>


More information about the llvm-commits mailing list