Add IRBuilder::CreateVectorSplat and use it to simplify code.

llvm-svn: 171349
This commit is contained in:
Benjamin Kramer
2013-01-01 19:55:16 +00:00
parent c003a4521b
commit 614b5e85b9
3 changed files with 18 additions and 24 deletions

View File

@@ -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)