summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
diff options
context:
space:
mode:
authorRobin Morisset <morisset@google.com>2014-08-18 22:18:14 +0000
committerRobin Morisset <morisset@google.com>2014-08-18 22:18:14 +0000
commit9e98e7f7fc5b06db5c8fc6dc872689e7ef9b9888 (patch)
tree7bd6530ee71e5eefdf3b48567a16c4e576edcdde /llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
parent4ffe8aaa694acceb58c01ffea7c1684b3d80e2fe (diff)
downloadbcm5719-llvm-9e98e7f7fc5b06db5c8fc6dc872689e7ef9b9888.tar.gz
bcm5719-llvm-9e98e7f7fc5b06db5c8fc6dc872689e7ef9b9888.zip
Answer to Philip Reames comments
- add check for volatile (probably unneeded, but I agree that we should be conservative about it). - strengthen condition from isUnordered() to isSimple(), as I don't understand well enough Unordered semantics (and it also matches the comment better this way) to be confident in the previous behaviour (thanks for catching that one, I had missed the case Monotonic/Unordered). - separate a condition in two. - lengthen comment about aliasing and loads - add tests in GVN/atomic.ll llvm-svn: 215943
Diffstat (limited to 'llvm/lib/Analysis/MemoryDependenceAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/MemoryDependenceAnalysis.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
index 33fe425f135..8f22b0ed3de 100644
--- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
@@ -407,21 +407,33 @@ getPointerDependencyFrom(const AliasAnalysis::Location &MemLoc, bool isLoad,
// Values depend on loads if the pointers are must aliased. This means that
// a load depends on another must aliased load from the same value.
+ // One exception is atomic loads: a value can depend on an atomic load that it
+ // does not alias with when this atomic load indicates that another thread may
+ // be accessing the location.
if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) {
// Atomic loads have complications involved.
// A monotonic load is OK if the query inst is itself not atomic.
// FIXME: This is overly conservative.
if (!LI->isUnordered()) {
- if (!QueryInst || LI->getOrdering() != Monotonic)
+ if (!QueryInst)
+ return MemDepResult::getClobber(LI);
+ if (LI->getOrdering() != Monotonic)
return MemDepResult::getClobber(LI);
if (auto *QueryLI = dyn_cast<LoadInst>(QueryInst))
- if (!QueryLI->isUnordered())
+ if (!QueryLI->isSimple())
return MemDepResult::getClobber(LI);
if (auto *QuerySI = dyn_cast<StoreInst>(QueryInst))
- if (!QuerySI->isUnordered())
+ if (!QuerySI->isSimple())
return MemDepResult::getClobber(LI);
}
+ // FIXME: this is overly conservative.
+ // While volatile access cannot be eliminated, they do not have to clobber
+ // non-aliasing locations, as normal accesses can for example be reordered
+ // with volatile accesses.
+ if (LI->isVolatile())
+ return MemDepResult::getClobber(LI);
+
AliasAnalysis::Location LoadLoc = AA->getLocation(LI);
// If we found a pointer, check if it could be the same as our pointer.
@@ -481,16 +493,25 @@ getPointerDependencyFrom(const AliasAnalysis::Location &MemLoc, bool isLoad,
// A monotonic store is OK if the query inst is itself not atomic.
// FIXME: This is overly conservative.
if (!SI->isUnordered()) {
- if (!QueryInst || SI->getOrdering() != Monotonic)
+ if (!QueryInst)
+ return MemDepResult::getClobber(SI);
+ if (SI->getOrdering() != Monotonic)
return MemDepResult::getClobber(SI);
if (auto *QueryLI = dyn_cast<LoadInst>(QueryInst))
- if (!QueryLI->isUnordered())
+ if (!QueryLI->isSimple())
return MemDepResult::getClobber(SI);
if (auto *QuerySI = dyn_cast<StoreInst>(QueryInst))
- if (!QuerySI->isUnordered())
+ if (!QuerySI->isSimple())
return MemDepResult::getClobber(SI);
}
+ // FIXME: this is overly conservative.
+ // While volatile access cannot be eliminated, they do not have to clobber
+ // non-aliasing locations, as normal accesses can for example be reordered
+ // with volatile accesses.
+ if (SI->isVolatile())
+ 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.
OpenPOWER on IntegriCloud