summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/TargetTransformInfo.cpp
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2018-06-12 16:12:29 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2018-06-12 16:12:29 +0000
commite39fa6cbbb368df3f8365a4d2311b079de921dd7 (patch)
treef0a18f086b49c53fd65315ea36dccbe14d6cb71d /llvm/lib/Analysis/TargetTransformInfo.cpp
parentf69316c6179aa9b96e4fe04ec109c64e1995786c (diff)
downloadbcm5719-llvm-e39fa6cbbb368df3f8365a4d2311b079de921dd7.tar.gz
bcm5719-llvm-e39fa6cbbb368df3f8365a4d2311b079de921dd7.zip
[CostModel] Replace ShuffleKind::SK_Alternate with ShuffleKind::SK_Select (PR33744)
As discussed on PR33744, this patch relaxes ShuffleKind::SK_Alternate which requires shuffle masks to only match an alternating pattern from its 2 sources: e.g. v4f32: <0,5,2,7> or <4,1,6,3> This seems far too restrictive as most SIMD hardware which will implement it using a general blend/bit-select instruction, so replaces it with SK_Select, permitting elements from either source as long as they are inline: e.g. v4f32: <0,5,2,7>, <4,1,6,3>, <0,1,6,7>, <4,1,2,3> etc. This initial patch just updates the name and cost model shuffle mask analysis, later patch reviews will update SLP to better utilise this - it still limits itself to SK_Alternate style patterns. Differential Revision: https://reviews.llvm.org/D47985 llvm-svn: 334513
Diffstat (limited to 'llvm/lib/Analysis/TargetTransformInfo.cpp')
-rw-r--r--llvm/lib/Analysis/TargetTransformInfo.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 19eed2fbe3c..a4bb9dd84c9 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -674,29 +674,25 @@ static bool isIdentityVectorMask(ArrayRef<int> Mask) {
return IdentityLHS || IdentityRHS;
}
-static bool isAlternateVectorMask(ArrayRef<int> Mask) {
- bool isAlternate = true;
+static bool isSelectVectorMask(ArrayRef<int> Mask) {
+ bool IsSelect = true;
+ bool FoundLHS = false;
+ bool FoundRHS = false;
unsigned MaskSize = Mask.size();
- // Example: shufflevector A, B, <0,5,2,7>
- for (unsigned i = 0; i < MaskSize && isAlternate; ++i) {
- if (Mask[i] < 0)
- continue;
- isAlternate = Mask[i] == (int)((i & 1) ? MaskSize + i : i);
- }
-
- if (isAlternate)
- return true;
-
- isAlternate = true;
+ // Example: shufflevector A, B, <0,1,6,3>
// Example: shufflevector A, B, <4,1,6,3>
- for (unsigned i = 0; i < MaskSize && isAlternate; ++i) {
+ for (unsigned i = 0; i < MaskSize && IsSelect; ++i) {
if (Mask[i] < 0)
continue;
- isAlternate = Mask[i] == (int)((i & 1) ? i : MaskSize + i);
+ bool IsLHS = (Mask[i] == (int)i);
+ bool IsRHS = (Mask[i] == (int)(i + MaskSize));
+ FoundLHS |= IsLHS;
+ FoundRHS |= IsRHS;
+ IsSelect = IsLHS || IsRHS;
}
-
- return isAlternate;
+ // If we don't use both vectors this is really an Identity mask.
+ return IsSelect && FoundLHS && FoundRHS;
}
static bool isTransposeVectorMask(ArrayRef<int> Mask) {
@@ -1236,8 +1232,8 @@ int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
return TTIImpl->getShuffleCost(TargetTransformInfo::SK_Reverse,
VecTypOp0, 0, nullptr);
- if (isAlternateVectorMask(Mask))
- return TTIImpl->getShuffleCost(TargetTransformInfo::SK_Alternate,
+ if (isSelectVectorMask(Mask))
+ return TTIImpl->getShuffleCost(TargetTransformInfo::SK_Select,
VecTypOp0, 0, nullptr);
if (isTransposeVectorMask(Mask))
OpenPOWER on IntegriCloud