From 2deae0baf7c01bb87e4271dbe06537f585cf8545 Mon Sep 17 00:00:00 2001 From: ChaseYalon <149000633+ChaseYalon@users.noreply.github.com> Date: Sat, 24 Jan 2026 10:13:45 -0500 Subject: [PATCH] X86: Fix VSCALE insert element crash in codegen (#177705) When inserting elements into scalable vectors, the X86 backend now returns InstructionCost::getInvalid() instead of panicking. Fixes #176823 --- llvm/lib/Target/X86/X86TargetTransformInfo.cpp | 4 ++++ .../CostModel/X86/vscale-insertelement-crash.ll | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 llvm/test/Analysis/CostModel/X86/vscale-insertelement-crash.ll diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp index 608727b74592..2a5e761a92aa 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -4815,6 +4815,10 @@ InstructionCost X86TTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val, }; assert(Val->isVectorTy() && "This must be a vector type"); + auto *VT = cast(Val); + if (VT->isScalableTy()) + return InstructionCost::getInvalid(); + Type *ScalarType = Val->getScalarType(); InstructionCost RegisterFileMoveCost = 0; diff --git a/llvm/test/Analysis/CostModel/X86/vscale-insertelement-crash.ll b/llvm/test/Analysis/CostModel/X86/vscale-insertelement-crash.ll new file mode 100644 index 000000000000..77e68c582269 --- /dev/null +++ b/llvm/test/Analysis/CostModel/X86/vscale-insertelement-crash.ll @@ -0,0 +1,10 @@ +; RUN: opt -passes=print -disable-output < %s +; This test triggers a crash in X86 TTI with scalable vectors + +target triple = "x86_64-unknown-linux-gnu" + +define @test(i64 %x) { +entry: + %v = insertelement poison, i64 %x, i64 0 + ret %v +}