From 6fe7c8aa8c7546743ecd0ac0138c2cf5d8155386 Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Sun, 18 Jan 2009 06:42:49 +0000 Subject: Vector codegen improvements git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62458 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprScalar.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib/CodeGen/CGExprScalar.cpp') diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index d6cc16c10a..e6eb9c0b65 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -409,10 +409,26 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, } // A scalar can be splatted to an extended vector of the same element type - if (DstType->isExtVectorType() && !isa(SrcType) && - cast(DstTy)->getElementType() == Src->getType()) - return CGF.EmitVector(&Src, DstType->getAsVectorType()->getNumElements(), - true); + if (DstType->isExtVectorType() && !isa(SrcType)) { + // Cast the scalar to element type + QualType EltTy = DstType->getAsExtVectorType()->getElementType(); + llvm::Value *Elt = EmitScalarConversion(Src, SrcType, EltTy); + + // Insert the element in element zero of an undef vector + llvm::Value *UnV = llvm::UndefValue::get(DstTy); + llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); + UnV = Builder.CreateInsertElement(UnV, Elt, Idx, "tmp"); + + // Splat the element across to all elements + llvm::SmallVector Args; + unsigned NumElements = cast(DstTy)->getNumElements(); + for (unsigned i = 0; i < NumElements; i++) + Args.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); + + llvm::Constant *Mask = llvm::ConstantVector::get(&Args[0], NumElements); + llvm::Value *Yay = Builder.CreateShuffleVector(UnV, UnV, Mask, "splat"); + return Yay; + } // Allow bitcast from vector to integer/fp of the same size. if (isa(Src->getType()) || -- cgit v1.2.3