[llvm-commits] [llvm] r128146 - in /llvm/trunk: lib/Transforms/Scalar/ScalarReplAggregates.cpp test/Transforms/ScalarRepl/vector_promote.ll
Cameron Zwarich
zwarich at apple.com
Tue Mar 22 22:25:55 PDT 2011
Author: zwarich
Date: Wed Mar 23 00:25:55 2011
New Revision: 128146
URL: http://llvm.org/viewvc/llvm-project?rev=128146&view=rev
Log:
Fix PR9464 by correcting some math that just happened to be right in most cases
that were hit in practice.
Modified:
llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
llvm/trunk/test/Transforms/ScalarRepl/vector_promote.ll
Modified: llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=128146&r1=128145&r2=128146&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp Wed Mar 23 00:25:55 2011
@@ -654,18 +654,18 @@
/// 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 @@
"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 @@
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,
Modified: llvm/trunk/test/Transforms/ScalarRepl/vector_promote.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ScalarRepl/vector_promote.ll?rev=128146&r1=128145&r2=128146&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ScalarRepl/vector_promote.ll (original)
+++ llvm/trunk/test/Transforms/ScalarRepl/vector_promote.ll Wed Mar 23 00:25:55 2011
@@ -171,3 +171,19 @@
; CHECK: @test11
; CHECK-NOT: alloca
}
+
+define void @test12() {
+entry:
+ %a = alloca <64 x i8>, align 64
+ store <64 x i8> undef, <64 x i8>* %a, align 64
+ %p = bitcast <64 x i8>* %a to <16 x i8>*
+ %0 = load <16 x i8>* %p, align 64
+ store <16 x i8> undef, <16 x i8>* %p, align 64
+ %q = bitcast <16 x i8>* %p to <64 x i8>*
+ %1 = load <64 x i8>* %q, align 64
+ ret void
+; CHECK: @test12
+; CHECK-NOT: alloca
+; CHECK: extractelement <4 x i128>
+; CHECK: insertelement <4 x i128>
+}
More information about the llvm-commits
mailing list