diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -290,15 +290,17 @@ unsigned Offset = 0) { 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; - } - return None; + const auto *VT = dyn_cast(IE->getType()); + if (!VT) + return None; + const auto *CI = dyn_cast(IE->getOperand(2)); + if (!CI) + return None; + if (CI->getValue().uge(VT->getNumElements())) + return None; + Index *= VT->getNumElements(); + Index += CI->getZExtValue(); + return Index; } const auto *IV = cast(InsertInst);