Index: llvm/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/lib/Analysis/ValueTracking.cpp +++ llvm/lib/Analysis/ValueTracking.cpp @@ -1690,7 +1690,8 @@ Known.Zero.setBitsFrom(31); break; case Intrinsic::vscale: { - if (!II->getFunction()->hasFnAttribute(Attribute::VScaleRange)) + if (!II->getFunction() || + !II->getFunction()->hasFnAttribute(Attribute::VScaleRange)) break; auto VScaleRange = II->getFunction() Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -963,7 +963,8 @@ } if (match(Src, m_VScale(DL))) { - if (Trunc.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { + if (Trunc.getFunction() && + Trunc.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { unsigned MaxVScale = Trunc.getFunction() ->getFnAttribute(Attribute::VScaleRange) .getVScaleRangeArgs() @@ -1334,7 +1335,8 @@ } if (match(Src, m_VScale(DL))) { - if (CI.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { + if (CI.getFunction() && + CI.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { unsigned MaxVScale = CI.getFunction() ->getFnAttribute(Attribute::VScaleRange) .getVScaleRangeArgs() @@ -1604,7 +1606,8 @@ } if (match(Src, m_VScale(DL))) { - if (CI.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { + if (CI.getFunction() && + CI.getFunction()->hasFnAttribute(Attribute::VScaleRange)) { unsigned MaxVScale = CI.getFunction() ->getFnAttribute(Attribute::VScaleRange) .getVScaleRangeArgs()