diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 280a13ff115341..0ebc6a5919e819 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -2400,6 +2400,11 @@ static Constant *ConstantFoldVectorCall(StringRef Name, SmallVector Lane(Operands.size()); Type *Ty = VTy->getElementType(); + // Do not iterate on scalable vector. The number of elements is unknown at + // compile-time. + if (VTy->getVectorIsScalable()) + return nullptr; + if (IntrinsicID == Intrinsic::masked_load) { auto *SrcPtr = Operands[0]; auto *Mask = Operands[2]; diff --git a/llvm/test/Analysis/ConstantFolding/vscale.ll b/llvm/test/Analysis/ConstantFolding/vscale.ll index 2491308910dfb2..3a3d6a16c7d664 100644 --- a/llvm/test/Analysis/ConstantFolding/vscale.ll +++ b/llvm/test/Analysis/ConstantFolding/vscale.ll @@ -210,3 +210,14 @@ define @select() { %r = select undef, zeroinitializer, undef ret %r } + +declare @llvm.sadd.sat.nxv16i8(, ) + +define @call() { +; CHECK-LABEL: @call( +; CHECK-NEXT: [[R:%.*]] = call @llvm.sadd.sat.nxv16i8( undef, undef) +; CHECK-NEXT: ret [[R]] +; + %r = call @llvm.sadd.sat.nxv16i8( undef, undef) + ret %r +}