diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -2137,6 +2137,12 @@ static bool isIdentityMask(ArrayRef Mask); static bool isIdentityMask(const Constant *Mask) { assert(Mask->getType()->isVectorTy() && "Shuffle needs vector constant."); + + // Not possible to express a shuffle mask for a scalable vector for this + // case. + if (isa(Mask->getType())) + return false; + SmallVector MaskAsInts; getShuffleMask(Mask, MaskAsInts); return isIdentityMask(MaskAsInts); @@ -2147,6 +2153,11 @@ /// from its input vectors. /// Example: shufflevector <4 x n> A, <4 x n> B, <4,undef,6,undef> bool isIdentity() const { + // Not possible to express a shuffle mask for a scalable vector for this + // case. + if (isa(getType())) + return false; + return !changesLength() && isIdentityMask(ShuffleMask); } diff --git a/llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll b/llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll --- a/llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll +++ b/llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll @@ -11,7 +11,7 @@ ; 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: %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