diff --git a/test/CodeGen/X86/deopt-intrinsic-cconv.ll b/test/CodeGen/X86/deopt-intrinsic-cconv.ll index edf9d0e0344..903378416ce 100644 --- a/test/CodeGen/X86/deopt-intrinsic-cconv.ll +++ b/test/CodeGen/X86/deopt-intrinsic-cconv.ll @@ -1,5 +1,6 @@ ; RUN: llc < %s | FileCheck %s ; RUN: llc -debug-only=stackmaps < %s 2>&1 | FileCheck --check-prefix=STACKMAPS %s +; RUN: opt -disable-output -debugify < %s ; REQUIRES: asserts target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" diff --git a/tools/opt/Debugify.cpp b/tools/opt/Debugify.cpp index aa967a72aa0..f12eabfa895 100644 --- a/tools/opt/Debugify.cpp +++ b/tools/opt/Debugify.cpp @@ -39,6 +39,19 @@ bool isFunctionSkipped(Function &F) { return F.isDeclaration() || !F.hasExactDefinition(); } +/// Find a suitable insertion point for debug values intrinsics. +/// +/// These must be inserted before the terminator. Special care is needed to +/// handle musttail and deopt calls, as these behave like (but are in fact not) +/// terminators. +Instruction *findDebugValueInsertionPoint(BasicBlock &BB) { + if (auto *I = BB.getTerminatingMustTailCall()) + return I; + if (auto *I = BB.getTerminatingDeoptimizeCall()) + return I; + return BB.getTerminator(); +} + bool applyDebugifyMetadata(Module &M, iterator_range Functions, StringRef Banner) { @@ -91,11 +104,7 @@ bool applyDebugifyMetadata(Module &M, if (BB.isEHPad()) continue; - // Debug values must be inserted before a musttail call (if one is - // present), or before the block terminator otherwise. - Instruction *LastInst = BB.getTerminatingMustTailCall(); - if (!LastInst) - LastInst = BB.getTerminator(); + Instruction *LastInst = findDebugValueInsertionPoint(BB); // Attach debug values. for (auto It = BB.begin(), End = LastInst->getIterator(); It != End;