[llvm-commits] [llvm] r171349 - in /llvm/trunk: include/llvm/IRBuilder.h lib/Transforms/Scalar/SROA.cpp lib/Transforms/Vectorize/LoopVectorize.cpp
Benjamin Kramer
benny.kra at googlemail.com
Tue Jan 1 11:55:16 PST 2013
Author: d0k
Date: Tue Jan 1 13:55:16 2013
New Revision: 171349
URL: http://llvm.org/viewvc/llvm-project?rev=171349&view=rev
Log:
Add IRBuilder::CreateVectorSplat and use it to simplify code.
Modified:
llvm/trunk/include/llvm/IRBuilder.h
llvm/trunk/lib/Transforms/Scalar/SROA.cpp
llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
Modified: llvm/trunk/include/llvm/IRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IRBuilder.h?rev=171349&r1=171348&r2=171349&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IRBuilder.h (original)
+++ llvm/trunk/include/llvm/IRBuilder.h Tue Jan 1 13:55:16 2013
@@ -1367,6 +1367,22 @@
ConstantExpr::getSizeOf(ArgType->getElementType()),
Name);
}
+
+ /// CreateVectorSplat - Return a vector value that contains \arg V broadcasted
+ /// to \p NumElts elements.
+ Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") {
+ assert(NumElts > 0 && "Cannot splat to an empty vector!");
+
+ // First insert it into an undef vector so we can shuffle it.
+ Type *I32Ty = getInt32Ty();
+ Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts));
+ V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0),
+ Name + ".splatinsert");
+
+ // Shuffle the value across the desired number of elements.
+ Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts));
+ return CreateShuffleVector(V, Undef, Zeros, Name + ".splat");
+ }
};
}
Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=171349&r1=171348&r2=171349&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Tue Jan 1 13:55:16 2013
@@ -2660,18 +2660,7 @@
/// \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;
}
Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=171349&r1=171348&r2=171349&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Tue Jan 1 13:55:16 2013
@@ -150,11 +150,6 @@
}
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 @@
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)
More information about the llvm-commits
mailing list