diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h --- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h +++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h @@ -875,6 +875,8 @@ switch (improveShuffleKindFromMask(Kind, Mask)) { case TTI::SK_Broadcast: + if (!isa(Tp)) + return InstructionCost::getInvalid(); return getBroadcastShuffleOverhead(cast(Tp)); case TTI::SK_Select: case TTI::SK_Splice: @@ -882,11 +884,17 @@ case TTI::SK_Transpose: case TTI::SK_PermuteSingleSrc: case TTI::SK_PermuteTwoSrc: + if (!isa(Tp)) + return InstructionCost::getInvalid(); return getPermuteShuffleOverhead(cast(Tp)); case TTI::SK_ExtractSubvector: + if (!isa(SubTp)) + return InstructionCost::getInvalid(); return getExtractSubvectorOverhead(Tp, Index, cast(SubTp)); case TTI::SK_InsertSubvector: + if (!isa(SubTp)) + return InstructionCost::getInvalid(); return getInsertSubvectorOverhead(Tp, Index, cast(SubTp)); } diff --git a/llvm/test/Analysis/CostModel/RISCV/rvv-shuffle-broadcast.ll b/llvm/test/Analysis/CostModel/RISCV/rvv-shuffle-broadcast.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CostModel/RISCV/rvv-shuffle-broadcast.ll @@ -0,0 +1,36 @@ +; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py +; Check getShuffleCost for SK_BroadCast with scalable vector + +; RUN: opt -cost-model -analyze -mtriple=riscv64 -mattr=+m,+experimental-v -scalable-vectorization=on < %s | FileCheck %s + +define void @broadcast() { +; CHECK-LABEL: 'broadcast' +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %zero = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %1 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %2 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %3 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %4 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %5 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %6 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %7 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %8 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %9 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %10 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Invalid cost for instruction: %11 = shufflevector undef, undef, zeroinitializer +; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void +; + %zero = shufflevector undef, undef, zeroinitializer + %1 = shufflevector undef, undef, zeroinitializer + %2 = shufflevector undef, undef, zeroinitializer + %3 = shufflevector undef, undef, zeroinitializer + %4 = shufflevector undef, undef, zeroinitializer + %5 = shufflevector undef, undef, zeroinitializer + %6 = shufflevector undef, undef, zeroinitializer + %7 = shufflevector undef, undef, zeroinitializer + %8 = shufflevector undef, undef, zeroinitializer + %9 = shufflevector undef, undef, zeroinitializer + %10 = shufflevector undef, undef, zeroinitializer + %11 = shufflevector undef, undef, zeroinitializer + ret void +} +