Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -291,12 +291,13 @@ int Index = Offset; if (const auto *IE = dyn_cast(InsertInst)) { if (const auto *CI = dyn_cast(IE->getOperand(2))) { - auto *VT = cast(IE->getType()); - if (CI->getValue().uge(VT->getNumElements())) - return None; - Index *= VT->getNumElements(); - Index += CI->getZExtValue(); - return Index; + if (const auto *VT = dyn_cast(IE->getType())) { + if (CI->getValue().uge(VT->getNumElements())) + return None; + Index *= VT->getNumElements(); + Index += CI->getZExtValue(); + return Index; + } } return None; }