diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2021-10-18 08:43:01 -0400 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2021-10-18 09:00:39 -0400 |
| commit | 2a3cc4d46184c347fd0d98ecda78ea7ec1144c5c (patch) | |
| tree | 2ace8f3f808547586b1794e909b7aec031d73735 /llvm/lib/Analysis/VectorUtils.cpp | |
| parent | 72d04d7b2b53eea977e160551077cf1a3f51ba9a (diff) | |
[Analysis] add utility function for unary shuffle mask creation
This is NFC-intended for the callers. Posting in case there are
other potential users that I missed.
I would also use this from VectorCombine in a patch for:
https://llvm.org/PR52178 ( D111901 )
Differential Revision: https://reviews.llvm.org/D111891
Diffstat (limited to 'llvm/lib/Analysis/VectorUtils.cpp')
| -rw-r--r-- | llvm/lib/Analysis/VectorUtils.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp index 8bb5861eedc5..655c248907f6 100644 --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -830,6 +830,23 @@ llvm::SmallVector<int, 16> llvm::createSequentialMask(unsigned Start, return Mask; } +llvm::SmallVector<int, 16> llvm::createUnaryMask(ArrayRef<int> Mask, + unsigned NumElts) { + // Avoid casts in the loop and make sure we have a reasonable number. + int NumEltsSigned = NumElts; + assert(NumEltsSigned > 0 && "Expected smaller or non-zero element count"); + + // If the mask chooses an element from operand 1, reduce it to choose from the + // corresponding element of operand 0. Undef mask elements are unchanged. + SmallVector<int, 16> UnaryMask; + for (int MaskElt : Mask) { + assert((MaskElt < NumEltsSigned * 2) && "Expected valid shuffle mask"); + int UnaryElt = MaskElt >= NumEltsSigned ? MaskElt - NumEltsSigned : MaskElt; + UnaryMask.push_back(UnaryElt); + } + return UnaryMask; +} + /// A helper function for concatenating vectors. This function concatenates two /// vectors having the same element type. If the second vector has fewer /// elements than the first, it is padded with undefs. |
