Index: llvm/lib/Analysis/CodeMetrics.cpp =================================================================== --- llvm/lib/Analysis/CodeMetrics.cpp +++ llvm/lib/Analysis/CodeMetrics.cpp @@ -175,8 +175,10 @@ if (const InvokeInst *InvI = dyn_cast(&I)) if (InvI->cannotDuplicate()) notDuplicatable = true; - - NumInsts += TTI.getUserCost(&I, TargetTransformInfo::TCK_CodeSize); + InstructionCost NumInstsProxy = + TTI.getUserCost(&I, TargetTransformInfo::TCK_CodeSize); + // Make it expensive if it is Invalid. + NumInsts += NumInstsProxy.isValid() ? *NumInstsProxy.getValue() : 10; } if (isa(BB->getTerminator())) Index: llvm/test/Analysis/CostModel/AArch64/intrinsic-cost-crash.ll =================================================================== --- /dev/null +++ llvm/test/Analysis/CostModel/AArch64/intrinsic-cost-crash.ll @@ -0,0 +1,14 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -disable-output -S -mtriple=aarch64--linux-gnu -mattr=+sve -O3 < %s 2>&1 | FileCheck %s + +define void @nodef_intrinsic() { +entry: + br label %vector.body + +vector.body: + %next = call @llvm.nodef.nxv2i1( zeroinitializer) + br label %vector.body +} + +declare @llvm.nodef.nxv2i1() +