aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/AliasAnalysis.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-02-09 19:38:11 +0000
committerChris Lattner <sabre@nondot.org>2003-02-09 19:38:11 +0000
commit762d2f0897a453bab92800b7aaadb0872e98aabd (patch)
tree6b8a9e31dbb696bc02242b8d71f2427d292beae4 /lib/Analysis/AliasAnalysis.cpp
parent44f340250e3648e4bab6623d1546a3f84f3b29ef (diff)
Implement knowledge in BasicAA that &A->field != &A and (P+1) != P
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5519 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/AliasAnalysis.cpp')
-rw-r--r--lib/Analysis/AliasAnalysis.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Analysis/AliasAnalysis.cpp b/lib/Analysis/AliasAnalysis.cpp
index 510db5700e..57867dd6ee 100644
--- a/lib/Analysis/AliasAnalysis.cpp
+++ b/lib/Analysis/AliasAnalysis.cpp
@@ -220,5 +220,22 @@ AliasAnalysis::Result BasicAliasAnalysis::alias(const Value *V1,
return NoAlias; // Unique values don't alias null
}
+ // Check to see if these two pointers are related by a getelementptr
+ // instruction. If one pointer is a GEP with a non-zero index of the other
+ // pointer, we know they cannot alias.
+ //
+ if (isa<GetElementPtrInst>(V2))
+ std::swap(V1, V2);
+
+ if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(V1))
+ if (GEP->getOperand(0) == V2) {
+ // If there is at least one non-zero constant index, we know they cannot
+ // alias.
+ for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i)
+ if (const Constant *C = dyn_cast<Constant>(GEP->getOperand(i)))
+ if (!C->isNullValue())
+ return NoAlias;
+ }
+
return MayAlias;
}