aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-11-26 19:20:01 +0000
committerChris Lattner <sabre@nondot.org>2004-11-26 19:20:01 +0000
commit0a1ac907c30cd3a5d0d8f96c1015bdb1c7461290 (patch)
tree4c88a2a06e42c7ee12f12263f0af99b0a72c4414
parent4e4f7312e00fe9346e54b40d0fc56533ad713f00 (diff)
downloadexternal_llvm-0a1ac907c30cd3a5d0d8f96c1015bdb1c7461290.zip
external_llvm-0a1ac907c30cd3a5d0d8f96c1015bdb1c7461290.tar.gz
external_llvm-0a1ac907c30cd3a5d0d8f96c1015bdb1c7461290.tar.bz2
A store or load cannot alias a global if the accessed amount is larger then
the global. This implements Regression/Analysis/BasicAA/global-size.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18261 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp69
1 files changed, 49 insertions, 20 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index 875530d..3ab2744 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -265,28 +265,57 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
const Value *O2 = getUnderlyingObject(V2);
// Pointing at a discernible object?
- if (O1 && O2) {
- if (isa<Argument>(O1)) {
- // Incoming argument cannot alias locally allocated object!
- if (isa<AllocationInst>(O2)) return NoAlias;
- // Otherwise, nothing is known...
- } else if (isa<Argument>(O2)) {
- // Incoming argument cannot alias locally allocated object!
- if (isa<AllocationInst>(O1)) return NoAlias;
- // Otherwise, nothing is known...
- } else {
- // If they are two different objects, we know that we have no alias...
- if (O1 != O2) return NoAlias;
+ if (O1) {
+ if (O2) {
+ if (isa<Argument>(O1)) {
+ // Incoming argument cannot alias locally allocated object!
+ if (isa<AllocationInst>(O2)) return NoAlias;
+ // Otherwise, nothing is known...
+ } else if (isa<Argument>(O2)) {
+ // Incoming argument cannot alias locally allocated object!
+ if (isa<AllocationInst>(O1)) return NoAlias;
+ // Otherwise, nothing is known...
+ } else if (O1 != O2) {
+ // If they are two different objects, we know that we have no alias...
+ return NoAlias;
+ }
+
+ // If they are the same object, they we can look at the indexes. If they
+ // index off of the object is the same for both pointers, they must alias.
+ // If they are provably different, they must not alias. Otherwise, we
+ // can't tell anything.
}
- // If they are the same object, they we can look at the indexes. If they
- // index off of the object is the same for both pointers, they must alias.
- // If they are provably different, they must not alias. Otherwise, we can't
- // tell anything.
- } else if (O1 && !isa<Argument>(O1) && isa<ConstantPointerNull>(V2)) {
- return NoAlias; // Unique values don't alias null
- } else if (O2 && !isa<Argument>(O2) && isa<ConstantPointerNull>(V1)) {
- return NoAlias; // Unique values don't alias null
+
+ if (!isa<Argument>(O1) && isa<ConstantPointerNull>(V2))
+ return NoAlias; // Unique values don't alias null
+
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(O1))
+ if (GV->getType()->getElementType()->isSized()) {
+ // If the size of the other access is larger than the total size of the
+ // global, it cannot be accessing the global (it's undefined to load or
+ // store bytes after the global).
+ unsigned GlobalSize =
+ getTargetData().getTypeSize(GV->getType()->getElementType());
+ if (GlobalSize < V2Size)
+ return NoAlias;
+ }
+ }
+
+ if (O2) {
+ if (!isa<Argument>(O2) && isa<ConstantPointerNull>(V1))
+ return NoAlias; // Unique values don't alias null
+
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(O2))
+ if (GV->getType()->getElementType()->isSized()) {
+ // If the size of the other access is larger than the total size of the
+ // global, it cannot be accessing the global (it's undefined to load or
+ // store bytes after the global).
+ unsigned GlobalSize =
+ getTargetData().getTypeSize(GV->getType()->getElementType());
+ if (GlobalSize < V1Size)
+ return NoAlias;
+ }
}
// If we have two gep instructions with must-alias'ing base pointers, figure