diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-01-01 19:55:16 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-01-01 19:55:16 +0000 |
commit | 6c3074958370bf25dc6e4e4b757f0c083e245dbe (patch) | |
tree | 5ef6b5fa3866483612737b9852a6d4a8f26fd3b0 /lib/Transforms | |
parent | 0ea4c3d8c0d6b0815aa1381167d0f53baf186dbd (diff) |
Add IRBuilder::CreateVectorSplat and use it to simplify code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171349 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/SROA.cpp | 13 | ||||
-rw-r--r-- | lib/Transforms/Vectorize/LoopVectorize.cpp | 13 |
2 files changed, 2 insertions, 24 deletions
diff --git a/lib/Transforms/Scalar/SROA.cpp b/lib/Transforms/Scalar/SROA.cpp index 05401fe1b3..4a20d69b91 100644 --- a/lib/Transforms/Scalar/SROA.cpp +++ b/lib/Transforms/Scalar/SROA.cpp @@ -2660,18 +2660,7 @@ private: /// \brief Compute a vector splat for a given element value. Value *getVectorSplat(IRBuilder<> &IRB, Value *V, unsigned NumElements) { - assert(NumElements > 0 && "Cannot splat to an empty vector."); - - // First insert it into a one-element vector so we can shuffle it. It is - // really silly that LLVM's IR requires this in order to form a splat. - Value *Undef = UndefValue::get(VectorType::get(V->getType(), 1)); - V = IRB.CreateInsertElement(Undef, V, IRB.getInt32(0), - getName(".splatinsert")); - - // Shuffle the value across the desired number of elements. - SmallVector<Constant*, 8> Mask(NumElements, IRB.getInt32(0)); - V = IRB.CreateShuffleVector(V, Undef, ConstantVector::get(Mask), - getName(".splat")); + V = IRB.CreateVectorSplat(NumElements, V, NamePrefix); DEBUG(dbgs() << " splat: " << *V << "\n"); return V; } diff --git a/lib/Transforms/Vectorize/LoopVectorize.cpp b/lib/Transforms/Vectorize/LoopVectorize.cpp index adf90818aa..aadc134313 100644 --- a/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -150,11 +150,6 @@ LoopVectorizationLegality::RuntimePointerCheck::insert(ScalarEvolution *SE, } Value *InnerLoopVectorizer::getBroadcastInstrs(Value *V) { - // Create the types. - LLVMContext &C = V->getContext(); - Type *VTy = VectorType::get(V->getType(), VF); - Type *I32 = IntegerType::getInt32Ty(C); - // Save the current insertion location. Instruction *Loc = Builder.GetInsertPoint(); @@ -167,14 +162,8 @@ Value *InnerLoopVectorizer::getBroadcastInstrs(Value *V) { if (Invariant) Builder.SetInsertPoint(LoopVectorPreHeader->getTerminator()); - Constant *Zero = ConstantInt::get(I32, 0); - Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32, VF)); - Value *UndefVal = UndefValue::get(VTy); - // Insert the value into a new vector. - Value *SingleElem = Builder.CreateInsertElement(UndefVal, V, Zero); // Broadcast the scalar into all locations in the vector. - Value *Shuf = Builder.CreateShuffleVector(SingleElem, UndefVal, Zeros, - "broadcast"); + Value *Shuf = Builder.CreateVectorSplat(VF, V, "broadcast"); // Restore the builder insertion point. if (Invariant) |