-
Notifications
You must be signed in to change notification settings - Fork 13.6k
MemoryDependenceAnalysis: Consider a pointer clobbered if it is saved #142096
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
base: main
Are you sure you want to change the base?
Conversation
In MemoryDependenceResults::getSimplePointerDependencyFrom, when we find the instruction that a LoadInst depends, if we find an store instruction that save the pointer used by LoadInst, we consider the pointer may be clobbered.
@llvm/pr-subscribers-llvm-analysis Author: YunQiang Su (wzssyqa) ChangesIn MemoryDependenceResults::getSimplePointerDependencyFrom, when we find the instruction that a LoadInst depends, if we find an store instruction that save the pointer used by LoadInst, we consider the pointer may be clobbered. Full diff: https://github.com/llvm/llvm-project/pull/142096.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
index f062189bac6a0..00f36b9e088ad 100644
--- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -564,6 +564,11 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
if (!QueryInst || QueryInst->isVolatile())
return MemDepResult::getClobber(SI);
+ // If we store the pointer of QueryInst, it is danger due to that the address
+ // may be modified with other reference.
+ if (QueryInst && QueryInst->getOperand(0) == SI->getOperand(0))
+ return MemDepResult::getClobber(SI);
+
// If alias analysis can tell that this store is guaranteed to not modify
// the query pointer, ignore it. Use getModRefInfo to handle cases where
// the query pointer points to constant memory etc.
|
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp -- llvm/lib/Analysis/MemoryDependenceAnalysis.cpp View the diff from clang-format here.diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
index 00f36b9e0..a907e22ba 100644
--- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -564,8 +564,8 @@ MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom(
if (!QueryInst || QueryInst->isVolatile())
return MemDepResult::getClobber(SI);
- // If we store the pointer of QueryInst, it is danger due to that the address
- // may be modified with other reference.
+ // If we store the pointer of QueryInst, it is danger due to that the
+ // address may be modified with other reference.
if (QueryInst && QueryInst->getOperand(0) == SI->getOperand(0))
return MemDepResult::getClobber(SI);
|
I find this problem when working on
can reproduce this problem. The difference is in function
in baiscblock In fact the contents of For C code, please see: I failed to reduce this cases, thus I cannot figure out a test case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handled by AA/CaptureTracking. Needs a reduced reproducer to understand why it fails.
In MemoryDependenceResults::getSimplePointerDependencyFrom, when we find the instruction that a LoadInst depends, if we find an store instruction that save the pointer used by LoadInst, we consider the pointer may be clobbered.