[IRBuilder][VectorCombine] make and use a convenience function for unary shuffle; NFC

This reduces code duplication for common construct.
Follow-ups can use this in SLP, LoopVectorizer, and other passes.
This commit is contained in:
Sanjay Patel 2020-09-21 13:27:40 -04:00
parent 03111e5e7a
commit 1e6b240d7d
2 changed files with 10 additions and 5 deletions

View File

@ -2431,6 +2431,13 @@ public:
return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
}
/// Create a unary shuffle. The second vector operand of the IR instruction
/// is undefined.
Value *CreateShuffleVector(Value *V, ArrayRef<int> Mask,
const Twine &Name = "") {
return CreateShuffleVector(V, UndefValue::get(V->getType()), Mask, Name);
}
Value *CreateExtractValue(Value *Agg,
ArrayRef<unsigned> Idxs,
const Twine &Name = "") {

View File

@ -154,7 +154,7 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) {
SmallVector<int, 16> Mask(OutputNumElts, UndefMaskElem);
for (unsigned i = 0; i < OutputNumElts && i < MinVecNumElts; ++i)
Mask[i] = i;
VecLd = Builder.CreateShuffleVector(VecLd, UndefValue::get(MinVecTy), Mask);
VecLd = Builder.CreateShuffleVector(VecLd, Mask);
}
replaceValue(I, *VecLd);
++NumVecLoad;
@ -304,8 +304,7 @@ static Value *createShiftShuffle(Value *Vec, unsigned OldIndex,
auto *VecTy = cast<FixedVectorType>(Vec->getType());
SmallVector<int, 32> ShufMask(VecTy->getNumElements(), UndefMaskElem);
ShufMask[NewIndex] = OldIndex;
Value *Undef = UndefValue::get(VecTy);
return Builder.CreateShuffleVector(Vec, Undef, ShufMask, "shift");
return Builder.CreateShuffleVector(Vec, ShufMask, "shift");
}
/// Given an extract element instruction with constant index operand, shuffle
@ -475,8 +474,7 @@ bool VectorCombine::foldBitcastShuf(Instruction &I) {
// bitcast (shuf V, MaskC) --> shuf (bitcast V), MaskC'
++NumShufOfBitcast;
Value *CastV = Builder.CreateBitCast(V, DestTy);
Value *Shuf =
Builder.CreateShuffleVector(CastV, UndefValue::get(DestTy), NewMask);
Value *Shuf = Builder.CreateShuffleVector(CastV, NewMask);
replaceValue(I, *Shuf);
return true;
}