Skip to content

[GVN/MemDep] Limit the size of the cache for non-local dependencies. #150539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alinas
Copy link
Contributor

@alinas alinas commented Jul 24, 2025

An attempt to resolve the issue flagged in PR150531

@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Jul 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 24, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Alina Sbirlea (alinas)

Changes

An attempt to resolve the issue flagged in PR150531


Full diff: https://github.com/llvm/llvm-project/pull/150539.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/MemoryDependenceAnalysis.cpp (+9)
diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
index 3aa9909df8e55..20c38caaf37cd 100644
--- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -80,6 +80,10 @@ static cl::opt<unsigned>
                      cl::desc("The number of blocks to scan during memory "
                               "dependency analysis (default = 200)"));
 
+static cl::opt<unsigned> CacheGlobalLimit(
+    "cache-global-limit", cl::Hidden, cl::init(5000),
+    cl::desc("The max number of entries allowed in a cache (default = 5000)"));
+
 // Limit on the number of memdep results to process.
 static const unsigned int NumResultsLimit = 100;
 
@@ -1138,6 +1142,11 @@ bool MemoryDependenceResults::getNonLocalPointerDepFromBB(
     return true;
   }
 
+  // If the size of this cache has surpassed the global limit, stop here.
+  if (Cache->size() > CacheGlobalLimit) {
+    return false;
+  }
+
   // 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 and not explicitly indicated as

@alinas alinas added the llvm:GVN GVN and NewGVN stages (Global value numbering) label Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding llvm:GVN GVN and NewGVN stages (Global value numbering)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants