From ea2abe23846ce1f4fa339dd2746348cd57715c46 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 3 Nov 2006 21:58:48 +0000 Subject: [PATCH] Fix BasicAA/2006-11-03-BasicAAVectorCrash.ll by handling out-of-range vector accesses like we handle out-of-range array accesses. llvm-svn: 31427 --- llvm/lib/Analysis/BasicAliasAnalysis.cpp | 28 +++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index d97472928973..0e7c244c022e 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -555,20 +555,21 @@ BasicAliasAnalysis::CheckGEPInstructions( } if (G1OC != G2OC) { - // Handle the "be careful" case above: if this is an array + // Handle the "be careful" case above: if this is an array/packed // subscript, scan for a subsequent variable array index. - if (isa(BasePtr1Ty)) { - const Type *NextTy =cast(BasePtr1Ty)->getElementType(); + if (isa(BasePtr1Ty)) { + const Type *NextTy = + cast(BasePtr1Ty)->getElementType(); bool isBadCase = false; for (unsigned Idx = FirstConstantOper+1; - Idx != MinOperands && isa(NextTy); ++Idx) { + Idx != MinOperands && isa(NextTy); ++Idx) { const Value *V1 = GEP1Ops[Idx], *V2 = GEP2Ops[Idx]; if (!isa(V1) || !isa(V2)) { isBadCase = true; break; } - NextTy = cast(NextTy)->getElementType(); + NextTy = cast(NextTy)->getElementType(); } if (isBadCase) G1OC = 0; @@ -668,10 +669,14 @@ BasicAliasAnalysis::CheckGEPInstructions( if (Op1) { if (const ConstantInt *Op1C = dyn_cast(Op1)) { // If this is an array index, make sure the array element is in range. - if (const ArrayType *AT = dyn_cast(BasePtr1Ty)) + if (const ArrayType *AT = dyn_cast(BasePtr1Ty)) { if (Op1C->getZExtValue() >= AT->getNumElements()) return MayAlias; // Be conservative with out-of-range accesses - + } else if (const PackedType *PT = dyn_cast(BasePtr1Ty)) { + if (Op1C->getZExtValue() >= PT->getNumElements()) + return MayAlias; // Be conservative with out-of-range accesses + } + } else { // GEP1 is known to produce a value less than GEP2. To be // conservatively correct, we must assume the largest possible @@ -685,15 +690,22 @@ BasicAliasAnalysis::CheckGEPInstructions( // if (const ArrayType *AT = dyn_cast(BasePtr1Ty)) GEP1Ops[i] = ConstantInt::get(Type::LongTy, AT->getNumElements()-1); + else if (const PackedType *PT = dyn_cast(BasePtr1Ty)) + GEP1Ops[i] = ConstantInt::get(Type::LongTy, PT->getNumElements()-1); + } } if (Op2) { if (const ConstantInt *Op2C = dyn_cast(Op2)) { // If this is an array index, make sure the array element is in range. - if (const ArrayType *AT = dyn_cast(BasePtr1Ty)) + if (const ArrayType *AT = dyn_cast(BasePtr1Ty)) { if (Op2C->getZExtValue() >= AT->getNumElements()) return MayAlias; // Be conservative with out-of-range accesses + } else if (const PackedType *PT = dyn_cast(BasePtr1Ty)) { + if (Op2C->getZExtValue() >= PT->getNumElements()) + return MayAlias; // Be conservative with out-of-range accesses + } } else { // Conservatively assume the minimum value for this index GEP2Ops[i] = Constant::getNullValue(Op2->getType()); }