diff options
| author | Chris Lattner <sabre@nondot.org> | 2003-02-09 19:38:11 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2003-02-09 19:38:11 +0000 |
| commit | 2393160bdee0a9306ea637f802279c9a17c1c190 (patch) | |
| tree | d248a58a97500af985eceb85eda7b1e43cf5b653 /llvm/lib/Analysis/AliasAnalysis.cpp | |
| parent | 1fbac976b9c0ae3559f77e45fd185997051985e9 (diff) | |
| download | bcm5719-llvm-2393160bdee0a9306ea637f802279c9a17c1c190.tar.gz bcm5719-llvm-2393160bdee0a9306ea637f802279c9a17c1c190.zip | |
Implement knowledge in BasicAA that &A->field != &A and (P+1) != P
llvm-svn: 5519
Diffstat (limited to 'llvm/lib/Analysis/AliasAnalysis.cpp')
| -rw-r--r-- | llvm/lib/Analysis/AliasAnalysis.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp index 510db5700e8..57867dd6eed 100644 --- a/llvm/lib/Analysis/AliasAnalysis.cpp +++ b/llvm/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; } |

