[llvm-commits] [llvm] r66368 - in /llvm/trunk: lib/Transforms/Scalar/ScalarReplAggregates.cpp test/Transforms/ScalarRepl/vector_memcpy.ll
Chris Lattner
sabre at nondot.org
Sat Mar 7 20:17:09 PST 2009
Author: lattner
Date: Sat Mar 7 22:17:04 2009
New Revision: 66368
URL: http://llvm.org/viewvc/llvm-project?rev=66368&view=rev
Log:
teach SROA to handle promoting vector allocas with a memset into them into
a vector type instead of into an integer type.
Modified:
llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
llvm/trunk/test/Transforms/ScalarRepl/vector_memcpy.ll
Modified: llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=66368&r1=66367&r2=66368&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp Sat Mar 7 22:17:04 2009
@@ -1350,8 +1350,6 @@
// Store of constant value and constant size.
if (isa<ConstantInt>(MSI->getValue()) &&
isa<ConstantInt>(MSI->getLength())) {
- // FIXME (!): Why reset VecTy?
- VecTy = Type::VoidTy;
IsNotTrivial = true;
continue;
}
@@ -1628,21 +1626,25 @@
const Type *AllocaType = Old->getType();
if (const VectorType *VTy = dyn_cast<VectorType>(AllocaType)) {
- // If the result alloca is a vector type, this is either an element
- // access or a bitcast to another vector type.
- if (isa<VectorType>(SV->getType())) {
- SV = Builder.CreateBitCast(SV, AllocaType, "tmp");
- } else {
- // Must be an element insertion.
- unsigned Elt = Offset/TD->getTypePaddedSizeInBits(VTy->getElementType());
-
- if (SV->getType() != VTy->getElementType())
- SV = Builder.CreateBitCast(SV, VTy->getElementType(), "tmp");
-
- SV = Builder.CreateInsertElement(Old, SV,
- ConstantInt::get(Type::Int32Ty, Elt),
- "tmp");
- }
+ uint64_t VecSize = TD->getTypePaddedSizeInBits(VTy);
+ uint64_t ValSize = TD->getTypePaddedSizeInBits(SV->getType());
+
+ // Changing the whole vector with memset or with an access of a different
+ // vector type?
+ if (ValSize == VecSize)
+ return Builder.CreateBitCast(SV, AllocaType, "tmp");
+
+ uint64_t EltSize = TD->getTypePaddedSizeInBits(VTy->getElementType());
+
+ // Must be an element insertion.
+ unsigned Elt = Offset/EltSize;
+
+ if (SV->getType() != VTy->getElementType())
+ SV = Builder.CreateBitCast(SV, VTy->getElementType(), "tmp");
+
+ SV = Builder.CreateInsertElement(Old, SV,
+ ConstantInt::get(Type::Int32Ty, Elt),
+ "tmp");
return SV;
}
Modified: llvm/trunk/test/Transforms/ScalarRepl/vector_memcpy.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ScalarRepl/vector_memcpy.ll?rev=66368&r1=66367&r2=66368&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ScalarRepl/vector_memcpy.ll (original)
+++ llvm/trunk/test/Transforms/ScalarRepl/vector_memcpy.ll Sat Mar 7 22:17:04 2009
@@ -1,4 +1,7 @@
-; RUN: llvm-as < %s | opt -scalarrepl | llvm-dis | grep {ret <16 x float> %A}
+; RUN: llvm-as < %s | opt -scalarrepl | llvm-dis > %t
+; RUN: grep {ret <16 x float> %A} %t
+; RUN: grep {ret <16 x float> zeroinitializer} %t
+
define <16 x float> @foo(<16 x float> %A) nounwind {
%tmp = alloca <16 x float>, align 16
%tmp2 = alloca <16 x float>, align 16
@@ -11,5 +14,16 @@
ret <16 x float> %R
}
-declare void @llvm.memcpy.i64(i8* nocapture, i8* nocapture, i64, i32) nounwind
+define <16 x float> @foo2(<16 x float> %A) nounwind {
+ %tmp2 = alloca <16 x float>, align 16
+ %s2 = bitcast <16 x float>* %tmp2 to i8*
+ call void @llvm.memset.i64(i8* %s2, i8 0, i64 64, i32 16)
+
+ %R = load <16 x float>* %tmp2
+ ret <16 x float> %R
+}
+
+
+declare void @llvm.memcpy.i64(i8* nocapture, i8* nocapture, i64, i32) nounwind
+declare void @llvm.memset.i64(i8* nocapture, i8, i64, i32) nounwind
More information about the llvm-commits
mailing list