diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-11-09 16:28:19 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-11-09 16:28:19 +0000 |
commit | d0c71609c52db321555672a7a827488d57b517ca (patch) | |
tree | f4d65ac9b3aba69c7b4190f3b1c40b72e7cb7b51 /llvm/lib/IR/Instructions.cpp | |
parent | 9920f8d0a710ae9f20a675dbaf2e6eb5143f12d9 (diff) | |
download | bcm5719-llvm-d0c71609c52db321555672a7a827488d57b517ca.tar.gz bcm5719-llvm-d0c71609c52db321555672a7a827488d57b517ca.zip |
[CostModel] Add SK_ExtractSubvector handling to getInstructionThroughput (PR39368)
Add ShuffleVectorInst::isExtractSubvectorMask helper to match shuffle masks.
llvm-svn: 346510
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 7d4b6df18d9..66fdb462e82 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -1798,6 +1798,35 @@ bool ShuffleVectorInst::isTransposeMask(ArrayRef<int> Mask) { return true; } +bool ShuffleVectorInst::isExtractSubvectorMask(ArrayRef<int> Mask, + int NumSrcElts, int &Index) { + // Must extract from a single source. + if (!isSingleSourceMaskImpl(Mask, NumSrcElts)) + return false; + + // Must be smaller (else this is an Identity shuffle). + if (NumSrcElts <= Mask.size()) + return false; + + // Find start of extraction, accounting that we may start with an UNDEF. + int SubIndex = -1; + for (int i = 0, e = Mask.size(); i != e; ++i) { + int M = Mask[i]; + if (M < 0) + continue; + int Offset = (M % NumSrcElts) - i; + if (0 <= SubIndex && SubIndex != Offset) + return false; + SubIndex = Offset; + } + + if (0 <= SubIndex) { + Index = SubIndex; + return true; + } + return false; +} + bool ShuffleVectorInst::isIdentityWithPadding() const { int NumOpElts = Op<0>()->getType()->getVectorNumElements(); int NumMaskElts = getType()->getVectorNumElements(); |