diff options
author | Cameron Zwarich <zwarich@apple.com> | 2011-03-09 07:34:11 +0000 |
---|---|---|
committer | Cameron Zwarich <zwarich@apple.com> | 2011-03-09 07:34:11 +0000 |
commit | 19f2b3c6522507b7835518f422985cf53e82e698 (patch) | |
tree | ec5b3fc39ddcde135ec9e0e55cc93e4743f11984 /llvm/lib/Transforms | |
parent | 5fe009660d6dd044e4755954a2da7095c7be495e (diff) | |
download | bcm5719-llvm-19f2b3c6522507b7835518f422985cf53e82e698.tar.gz bcm5719-llvm-19f2b3c6522507b7835518f422985cf53e82e698.zip |
Fix a crasher introduced by r127317 that is seen on the bots when using an
alloca as both integer and floating-point vectors of the same size. Bugpoint is
not cooperating with me, but I'll try to find a manual testcase tomorrow.
llvm-svn: 127320
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 1f64ad2606a..e1b79fb2dbd 100644 --- a/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -681,25 +681,28 @@ ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType, // access or a bitcast to another vector type of the same size. if (const VectorType *VTy = dyn_cast<VectorType>(FromVal->getType())) { if (ToType->isVectorTy()) { - if (isPowerOf2_64(AllocaSize / TD.getTypeAllocSize(ToType))) { - assert(Offset == 0 && "Can't extract a value of a smaller vector type " - "from a nonzero offset."); - - const Type *ToElementTy = cast<VectorType>(ToType)->getElementType(); - unsigned Scale = AllocaSize / TD.getTypeAllocSize(ToType); - const Type *CastElementTy = getScaledElementType(ToElementTy, Scale); - unsigned NumCastVectorElements = VTy->getNumElements() / Scale; - - LLVMContext &Context = FromVal->getContext(); - const Type *CastTy = VectorType::get(CastElementTy, - NumCastVectorElements); - Value *Cast = Builder.CreateBitCast(FromVal, CastTy, "tmp"); - Value *Extract = Builder.CreateExtractElement(Cast, ConstantInt::get( - Type::getInt32Ty(Context), 0), "tmp"); - return Builder.CreateBitCast(Extract, ToType, "tmp"); - } + unsigned ToTypeSize = TD.getTypeAllocSize(ToType); + if (ToTypeSize == AllocaSize) + return Builder.CreateBitCast(FromVal, ToType, "tmp"); + + assert(isPowerOf2_64(AllocaSize / ToTypeSize) && + "Partial vector access of an alloca must have a power-of-2 size " + "ratio."); + assert(Offset == 0 && "Can't extract a value of a smaller vector type " + "from a nonzero offset."); + + const Type *ToElementTy = cast<VectorType>(ToType)->getElementType(); + unsigned Scale = AllocaSize / ToTypeSize; + const Type *CastElementTy = getScaledElementType(ToElementTy, Scale); + unsigned NumCastVectorElements = VTy->getNumElements() / Scale; - return Builder.CreateBitCast(FromVal, ToType, "tmp"); + LLVMContext &Context = FromVal->getContext(); + const Type *CastTy = VectorType::get(CastElementTy, + NumCastVectorElements); + Value *Cast = Builder.CreateBitCast(FromVal, CastTy, "tmp"); + Value *Extract = Builder.CreateExtractElement(Cast, ConstantInt::get( + Type::getInt32Ty(Context), 0), "tmp"); + return Builder.CreateBitCast(Extract, ToType, "tmp"); } // Otherwise it must be an element access. |