aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorCameron Zwarich <zwarich@apple.com>2011-03-23 05:25:55 +0000
committerCameron Zwarich <zwarich@apple.com>2011-03-23 05:25:55 +0000
commit1537ce75ed25bbca58096383bb1fb9dd427bf1aa (patch)
tree7469571d731ecd7fc08f3884f22a2ad9ab61bff1 /lib/Transforms
parent1e6c65dba706de80f5a4ceb8a1fc86bc3d0a61c6 (diff)
Fix PR9464 by correcting some math that just happened to be right in most cases
that were hit in practice. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128146 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index efc0df5ad3..c261dede92 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -654,18 +654,18 @@ void ConvertToScalarInfo::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI,
/// getScaledElementType - Gets a scaled element type for a partial vector
/// access of an alloca. The input type must be an integer or float, and
/// the resulting type must be an integer, float or double.
-static const Type *getScaledElementType(const Type *OldTy, unsigned Scale) {
+static const Type *getScaledElementType(const Type *OldTy,
+ unsigned NewBitWidth) {
assert((OldTy->isIntegerTy() || OldTy->isFloatTy()) && "Partial vector "
"accesses must be scaled from integer or float elements.");
LLVMContext &Context = OldTy->getContext();
- unsigned Size = OldTy->getPrimitiveSizeInBits() * Scale;
if (OldTy->isIntegerTy())
- return Type::getIntNTy(Context, Size);
- if (Size == 32)
+ return Type::getIntNTy(Context, NewBitWidth);
+ if (NewBitWidth == 32)
return Type::getFloatTy(Context);
- if (Size == 64)
+ if (NewBitWidth == 64)
return Type::getDoubleTy(Context);
llvm_unreachable("Invalid type for a partial vector access of an alloca!");
@@ -703,9 +703,9 @@ ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType,
"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;
+ const Type *CastElementTy = getScaledElementType(ToElementTy,
+ ToTypeSize * 8);
+ unsigned NumCastVectorElements = AllocaSize / ToTypeSize;
LLVMContext &Context = FromVal->getContext();
const Type *CastTy = VectorType::get(CastElementTy,
@@ -841,9 +841,8 @@ ConvertScalar_InsertValue(Value *SV, Value *Old,
const Type *ToElementTy =
cast<VectorType>(SV->getType())->getElementType();
- unsigned Scale = VecSize / ValSize;
- const Type *CastElementTy = getScaledElementType(ToElementTy, Scale);
- unsigned NumCastVectorElements = VTy->getNumElements() / Scale;
+ const Type *CastElementTy = getScaledElementType(ToElementTy, ValSize);
+ unsigned NumCastVectorElements = VecSize / ValSize;
LLVMContext &Context = SV->getContext();
const Type *OldCastTy = VectorType::get(CastElementTy,