diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7903,6 +7903,12 @@ } case Instruction::ExtractValue: return TTI.getInstructionCost(I, TTI::TCK_RecipThroughput); + case Instruction::Alloca: + // We cannot easily widen alloca to a scalable alloca, as + // the result would need to be a vector of pointers. + if (VF.isScalable()) + return InstructionCost::getInvalid(); + LLVM_FALLTHROUGH; default: // This opcode is unknown. Assume that it is the same as 'mul'. return TTI.getArithmeticInstrCost(Instruction::Mul, VectorTy, CostKind); diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/scalable-alloca.ll b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-alloca.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/LoopVectorize/AArch64/scalable-alloca.ll @@ -0,0 +1,31 @@ +; RUN: opt -S -loop-vectorize -mattr=+sve -mtriple aarch64-unknown-linux-gnu -force-vector-width=2 -scalable-vectorization=preferred -pass-remarks-analysis=loop-vectorize -pass-remarks-missed=loop-vectorize < %s 2>%t | FileCheck %s +; RUN: FileCheck %s --check-prefix=CHECK-REMARKS < %t + +; CHECK-REMARKS: UserVF ignored because of invalid costs. +; CHECK-REMARKS: Instruction with invalid costs prevented vectorization at VF=(vscale x 1, vscale x 2): alloca +; CHECK-REMARKS: Instruction with invalid costs prevented vectorization at VF=(vscale x 1): store +define void @alloca(i32** %vla, i64 %N) { +; CHECK-LABEL: @alloca( +; CHECK-NOT: