[llvm] MemoryDependenceAnalysis: Consider a pointer clobbered if it is saved (PR #142096)
YunQiang Su via llvm-commits
llvm-commits at lists.llvm.org
Fri May 30 00:10:01 PDT 2025
https://github.com/wzssyqa created https://github.com/llvm/llvm-project/pull/142096
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.
>From ebd9e35af9091338a5abdb5a499f5f68a6df9eea Mon Sep 17 00:00:00 2001
From: YunQiang Su <yunqiang at isrc.iscas.ac.cn>
Date: Fri, 30 May 2025 15:05:30 +0800
Subject: [PATCH] MemoryDependenceAnalysis: Consider a pointer clobbered if it
is saved
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/lib/Analysis/MemoryDependenceAnalysis.cpp | 5 +++++
1 file changed, 5 insertions(+)
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.
More information about the llvm-commits
mailing list