diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -1191,8 +1191,6 @@ int AArch64TTIImpl::getShuffleCost(TTI::ShuffleKind Kind, VectorType *Tp, int Index, VectorType *SubTp) { - if (Kind == TTI::SK_Broadcast || Kind == TTI::SK_Transpose || - Kind == TTI::SK_Select || Kind == TTI::SK_PermuteSingleSrc) { static const CostTblEntry ShuffleTbl[] = { // Broadcast shuffle kinds can be performed with 'dup'. { TTI::SK_Broadcast, MVT::v8i8, 1 }, @@ -1234,10 +1232,25 @@ { TTI::SK_PermuteSingleSrc, MVT::v4f32, 3 }, // perfectshuffle worst case. { TTI::SK_PermuteSingleSrc, MVT::v2f64, 1 }, // mov. }; + + static const CostTblEntry ScalableShuffleTbl[] = { + {TTI::SK_Broadcast, MVT::nxv16i8, 1}, + {TTI::SK_Broadcast, MVT::nxv8i16, 1}, + {TTI::SK_Broadcast, MVT::nxv4i32, 1}, + {TTI::SK_Broadcast, MVT::nxv2i64, 1}, + {TTI::SK_Broadcast, MVT::nxv8f16, 1}, + {TTI::SK_Broadcast, MVT::nxv4f32, 1}, + {TTI::SK_Broadcast, MVT::nxv2f64, 1}, + }; + std::pair LT = TLI->getTypeLegalizationCost(DL, Tp); + if (const auto *Entry = CostTableLookup(ShuffleTbl, Kind, LT.second)) return LT.first * Entry->Cost; - } - return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); + if (const auto *Entry = + CostTableLookup(ScalableShuffleTbl, Kind, LT.second)) + return LT.first * Entry->Cost; + + return BaseT::getShuffleCost(Kind, Tp, Index, SubTp); } diff --git a/llvm/test/Analysis/CostModel/AArch64/sve-shuffle-broadcast.ll b/llvm/test/Analysis/CostModel/AArch64/sve-shuffle-broadcast.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CostModel/AArch64/sve-shuffle-broadcast.ll @@ -0,0 +1,134 @@ +; Check getShuffleCost for SK_BroadCast with scalable vector + +; RUN: opt -cost-model -analyze -mtriple=aarch64--linux-gnu -mattr=sve < %s 2>%t | FileCheck %s + +; RUN: FileCheck --check-prefix=WARN --allow-empty %s <%t + +; If this check fails please read test/CodeGen/AArch64/README for instructions on how to resolve it. +; WARN-NOT: warning + + +define @broadcast_v16i8( %v) { +; CHECK-LABEL: 'broadcast_v16i8': +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @broadcast_v32i8( %v) { +; CHECK-LABEL: 'broadcast_v32i8': +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @broadcast_v8i16( %v) { +; CHECK-LABEL: 'broadcast_v8i16': +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @broadcast_v16i16( %v) { +; CHECK-LABEL: 'broadcast_v16i16': +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @broadcast_v4i32( %v) { +; CHECK-LABEL: 'broadcast_v4i32': +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @broadcast_v8i32( %v) { +; CHECK-LABEL: 'broadcast_v8i32': +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @broadcast_v2i64( %v) { +; CHECK-LABEL: 'broadcast_v2i64': +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @broadcast_v4i64( %v) { +; CHECK-LABEL: 'broadcast_v4i64': +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @broadcast_v8f16( %v) { +; CHECK-LABEL: 'broadcast_v8f16': +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @broadcast_v16f16( %v) { +; CHECK-LABEL: 'broadcast_v16f16': +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @slapt_v4f32( %v){ +; CHECK-LABEL: 'slapt_v4f32': +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @slapt_v8f32( %v){ +; CHECK-LABEL: 'slapt_v8f32': +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} +define @slapt_v2f64( %v){ +; CHECK-LABEL: 'slapt_v2f64': +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +} + +define @slapt_v4f64( %v){ +; CHECK-LABEL: 'slapt_v4f64': +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %retval = shufflevector %v, poison, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret %retval + + %retval = shufflevector %v, poison, zeroinitializer + ret %retval +}