Skip to content

Commit 7f26478

Browse files
committed
[AArch64] use isTRNMask to calculate shuffle costs
1 parent 657317c commit 7f26478

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5918,6 +5918,19 @@ InstructionCost AArch64TTIImpl::getPartialReductionCost(
59185918
return Cost + 2;
59195919
}
59205920

5921+
TTI::ShuffleKind AArch64TTIImpl::improveShuffleKindFromMask(
5922+
TTI::ShuffleKind Kind, ArrayRef<int> Mask, VectorType *SrcTy, int &Index,
5923+
VectorType *&SubTy) const {
5924+
TTI::ShuffleKind SuperResult = BasicTTIImplBase::improveShuffleKindFromMask(
5925+
Kind, Mask, SrcTy, Index, SubTy);
5926+
if (SuperResult == TTI::ShuffleKind::SK_PermuteTwoSrc && !Mask.empty()) {
5927+
unsigned DummyUnsigned;
5928+
if (isTRNMask(Mask, Mask.size(), DummyUnsigned, DummyUnsigned))
5929+
return TTI::ShuffleKind::SK_Transpose;
5930+
}
5931+
return SuperResult;
5932+
}
5933+
59215934
InstructionCost
59225935
AArch64TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy,
59235936
VectorType *SrcTy, ArrayRef<int> Mask,

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ class AArch64TTIImpl final : public BasicTTIImplBase<AArch64TTIImpl> {
494494
bool IsUnsigned, unsigned RedOpcode, Type *ResTy, VectorType *Ty,
495495
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput) const override;
496496

497+
498+
TTI::ShuffleKind improveShuffleKindFromMask(TTI::ShuffleKind Kind,
499+
ArrayRef<int> Mask,
500+
VectorType *SrcTy, int &Index,
501+
VectorType *&SubTy) const;
502+
497503
InstructionCost
498504
getShuffleCost(TTI::ShuffleKind Kind, VectorType *DstTy, VectorType *SrcTy,
499505
ArrayRef<int> Mask, TTI::TargetCostKind CostKind, int Index,

llvm/test/Transforms/SLPVectorizer/AArch64/transpose-with-constants.ll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ entry:
2828
define dso_local <16 x i8> @transpose_constants_splat(i8 noundef %x) {
2929
; CHECK-LABEL: @transpose_constants_splat(
3030
; CHECK-NEXT: entry:
31-
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <16 x i8> <i8 0, i8 poison, i8 1, i8 poison, i8 2, i8 poison, i8 3, i8 poison, i8 4, i8 poison, i8 5, i8 poison, i8 6, i8 poison, i8 7, i8 poison>, i8 [[X:%.*]], i64 1
32-
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <16 x i8> [[TMP0]], i8 [[X]], i64 3
33-
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <16 x i8> [[TMP1]], i8 [[X]], i64 5
34-
; CHECK-NEXT: [[TMP7:%.*]] = insertelement <16 x i8> [[TMP2]], i8 [[X]], i64 7
35-
; CHECK-NEXT: [[TMP4:%.*]] = insertelement <16 x i8> [[TMP7]], i8 [[X]], i64 9
36-
; CHECK-NEXT: [[TMP5:%.*]] = insertelement <16 x i8> [[TMP4]], i8 [[X]], i64 11
37-
; CHECK-NEXT: [[TMP6:%.*]] = insertelement <16 x i8> [[TMP5]], i8 [[X]], i64 13
38-
; CHECK-NEXT: [[TMP3:%.*]] = insertelement <16 x i8> [[TMP6]], i8 [[X]], i64 15
31+
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <8 x i8> poison, i8 [[X:%.*]], i32 0
32+
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i8> [[TMP0]], <8 x i8> poison, <8 x i32> zeroinitializer
33+
; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i8> [[TMP1]], <8 x i8> poison, <16 x i32> <i32 0, i32 poison, i32 1, i32 poison, i32 2, i32 poison, i32 3, i32 poison, i32 4, i32 poison, i32 5, i32 poison, i32 6, i32 poison, i32 7, i32 poison>
34+
; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <16 x i8> <i8 0, i8 poison, i8 1, i8 poison, i8 2, i8 poison, i8 3, i8 poison, i8 4, i8 poison, i8 5, i8 poison, i8 6, i8 poison, i8 7, i8 poison>, <16 x i8> [[TMP2]], <16 x i32> <i32 0, i32 16, i32 2, i32 18, i32 4, i32 20, i32 6, i32 22, i32 8, i32 24, i32 10, i32 26, i32 12, i32 28, i32 14, i32 30>
3935
; CHECK-NEXT: ret <16 x i8> [[TMP3]]
4036
;
4137
entry:

0 commit comments

Comments
 (0)