Index: lib/IR/DebugInfo.cpp =================================================================== --- lib/IR/DebugInfo.cpp +++ lib/IR/DebugInfo.cpp @@ -380,6 +380,18 @@ if (GVMaterializer *Materializer = M.getMaterializer()) Materializer->setStripDebugInfo(); + StringRef DbgIntrinsics[4] = {"llvm.dbg.value", + "llvm.dbg.declare", + "llvm.dbg.addr", + "llvm.dbg.label"}; + for (StringRef FuncName : DbgIntrinsics) { + auto *F = M.getFunction(FuncName); + if (!F) + continue; + F->eraseFromParent(); + Changed = true; + } + return Changed; } Index: test/DebugInfo/strip-intrinsic-dbg.ll =================================================================== --- test/DebugInfo/strip-intrinsic-dbg.ll +++ test/DebugInfo/strip-intrinsic-dbg.ll @@ -0,0 +1,7 @@ +; RUN: opt -S -strip-debug <%s | FileCheck %s + +; CHECK-NOT: llvm.dbg. +declare void @llvm.dbg.declare(metadata, metadata, metadata) +declare void @llvm.dbg.value(metadata, metadata, metadata) +declare void @llvm.dbg.addr(metadata, metadata, metadata) +declare void @llvm.dbg.label(metadata, metadata, metadata) Index: tools/opt/opt.cpp =================================================================== --- tools/opt/opt.cpp +++ tools/opt/opt.cpp @@ -202,6 +202,10 @@ static cl::opt AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization")); +static cl::opt +StripDebugify("strip-debugify", + cl::desc("Strip debugify metadata in enable-debugify after check.")); + static cl::opt EnableDebugify( "enable-debugify", cl::desc( @@ -756,7 +760,7 @@ Passes.add(createVerifierPass()); if (AddOneTimeDebugifyPasses) - Passes.add(createCheckDebugifyModulePass(false)); + Passes.add(createCheckDebugifyModulePass(StripDebugify)); // In run twice mode, we want to make sure the output is bit-by-bit // equivalent if we run the pass manager again, so setup two buffers and