From c330ee6f0245569ade06f72af30bd85ae3cb3341 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 26 Feb 2003 21:57:23 +0000 Subject: [PATCH] Fix bug: BasicAA/2003-02-26-AccessSizeTest.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5645 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BasicAliasAnalysis.cpp | 47 ++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index a4465eb2b29..2242d4f5b39 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -142,19 +142,44 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size, std::swap(V1Size, V2Size); } - if (const GetElementPtrInst *GEP = dyn_cast(V1)) { - AliasResult R = alias(GEP->getOperand(0), V1Size, V2, V2Size); - if (R == NoAlias) return NoAlias; - if (R == MustAlias) { - // 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(GEP->getOperand(i))) - if (!C->isNullValue()) + if (V1Size != ~0U && V2Size != ~0U) + if (const GetElementPtrInst *GEP = dyn_cast(V1)) { + AliasResult R = alias(GEP->getOperand(0), V1Size, V2, V2Size); + if (R == NoAlias) return NoAlias; + if (R == MustAlias) { + // If there is at least one non-zero constant index, we know they cannot + // alias. + bool ConstantFound = false; + for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i) + if (const Constant *C = dyn_cast(GEP->getOperand(i))) + if (!C->isNullValue()) { + ConstantFound = true; + break; + } + if (ConstantFound) { + if (V2Size <= 1 && V1Size <= 1) // Just pointer check? return NoAlias; + + // Otherwise we have to check to see that the distance is more than + // the size of the argument... build an index vector that is equal to + // the arguments provided, except substitute 0's for any variable + // indexes we find... + + std::vector Indices; + Indices.reserve(GEP->getNumOperands()-1); + for (unsigned i = 1; i != GEP->getNumOperands(); ++i) + if (const Constant *C = dyn_cast(GEP->getOperand(i))) + Indices.push_back((Value*)C); + else + Indices.push_back(Constant::getNullValue(Type::LongTy)); + const Type *Ty = GEP->getOperand(0)->getType(); + int Offset = getTargetData().getIndexedOffset(Ty, Indices); + if (Offset >= (int)V2Size || Offset <= -(int)V1Size) + return NoAlias; + } + } } - } - + return MayAlias; }