diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -2689,15 +2689,16 @@ const DataLayout &DL, const TargetLibraryInfo *TLI, const CallBase *Call) { - SmallVector Result(VTy->getNumElements()); - SmallVector Lane(Operands.size()); - Type *Ty = VTy->getElementType(); - // Do not iterate on scalable vector. The number of elements is unknown at // compile-time. if (isa(VTy)) return nullptr; + SmallVector Result( + cast(VTy)->getNumElements()); + SmallVector Lane(Operands.size()); + Type *Ty = VTy->getElementType(); + if (IntrinsicID == Intrinsic::masked_load) { auto *SrcPtr = Operands[0]; auto *Mask = Operands[2];