Extract the logic for inserting a subvector into a vector alloca.

No functionality changed. Another step of refactoring toward solving
PR14487.

llvm-svn: 170300
This commit is contained in:
Chandler Carruth 2012-12-17 04:07:35 +00:00
parent 514f34f9c4
commit eae65a5629
1 changed files with 49 additions and 37 deletions

View File

@ -2506,27 +2506,24 @@ private:
return !LI.isVolatile() && !IsPtrAdjusted;
}
bool rewriteVectorizedStoreInst(IRBuilder<> &IRB, Value *V,
StoreInst &SI, Value *OldOp) {
unsigned BeginIndex = getIndex(BeginOffset);
unsigned EndIndex = getIndex(EndOffset);
assert(EndIndex > BeginIndex && "Empty vector!");
Value *insertVector(IRBuilder<> &IRB, Value *V,
unsigned BeginIndex, unsigned EndIndex) {
assert(VecTy && "Can only insert a vector into a vector alloca");
unsigned NumElements = EndIndex - BeginIndex;
assert(NumElements <= VecTy->getNumElements() && "Too many elements!");
Type *PartitionTy
= (NumElements == 1) ? ElementTy
: VectorType::get(ElementTy, NumElements);
if (V->getType() != PartitionTy)
V = convertValue(TD, IRB, V, PartitionTy);
if (NumElements < VecTy->getNumElements()) {
// We need to mix in the existing elements.
if (NumElements == VecTy->getNumElements())
return convertValue(TD, IRB, V, VecTy);
LoadInst *LI = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(),
getName(".load"));
if (NumElements == 1) {
V = IRB.CreateInsertElement(LI, V, IRB.getInt32(BeginIndex),
getName(".insert"));
DEBUG(dbgs() << " insert: " << *V << "\n");
} else {
return V;
}
// When inserting a smaller vector into the larger to store, we first
// use a shuffle vector to widen it with undef elements, and then
// a second shuffle vector to select between the loaded vector and the
@ -2552,10 +2549,25 @@ private:
V = IRB.CreateShuffleVector(V, LI, ConstantVector::get(Mask),
getName("insert"));
DEBUG(dbgs() << " shuffle2: " << *V << "\n");
return V;
}
} else {
V = convertValue(TD, IRB, V, VecTy);
}
bool rewriteVectorizedStoreInst(IRBuilder<> &IRB, Value *V,
StoreInst &SI, Value *OldOp) {
unsigned BeginIndex = getIndex(BeginOffset);
unsigned EndIndex = getIndex(EndOffset);
assert(EndIndex > BeginIndex && "Empty vector!");
unsigned NumElements = EndIndex - BeginIndex;
assert(NumElements <= VecTy->getNumElements() && "Too many elements!");
Type *PartitionTy
= (NumElements == 1) ? ElementTy
: VectorType::get(ElementTy, NumElements);
if (V->getType() != PartitionTy)
V = convertValue(TD, IRB, V, PartitionTy);
// Mix in the existing elements.
V = insertVector(IRB, V, BeginIndex, EndIndex);
StoreInst *Store = IRB.CreateAlignedStore(V, &NewAI, NewAI.getAlignment());
Pass.DeadInsts.insert(&SI);