From ed02ca36988965f298e2effe901f0d077719224b Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Thu, 15 Feb 2018 22:26:18 +0000 Subject: [PATCH] [DCE] Salvage debug info from dead insts This results in small increases in the size of the .debug_loc section and the number of unique source variables in a stage2 build of opt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325301 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/DCE.cpp | 3 +++ test/Transforms/DCE/basic.ll | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index fa4806e884c..d8575b71a3c 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -50,6 +50,7 @@ namespace { for (BasicBlock::iterator DI = BB.begin(); DI != BB.end(); ) { Instruction *Inst = &*DI++; if (isInstructionTriviallyDead(Inst, TLI)) { + salvageDebugInfo(*Inst); Inst->eraseFromParent(); Changed = true; ++DIEEliminated; @@ -76,6 +77,8 @@ static bool DCEInstruction(Instruction *I, SmallSetVector &WorkList, const TargetLibraryInfo *TLI) { if (isInstructionTriviallyDead(I, TLI)) { + salvageDebugInfo(*I); + // Null out all of the instruction's operands to see if any operand becomes // dead as we go. for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) { diff --git a/test/Transforms/DCE/basic.ll b/test/Transforms/DCE/basic.ll index c2a56594c91..6282ac78e75 100644 --- a/test/Transforms/DCE/basic.ll +++ b/test/Transforms/DCE/basic.ll @@ -1,11 +1,15 @@ -; RUN: opt -dce -S < %s | FileCheck %s -; RUN: opt -passes=dce -S < %s | FileCheck %s +; RUN: opt -debugify -dce -S < %s | FileCheck %s +; RUN: opt -passes='module(debugify),function(dce)' -S < %s | FileCheck %s ; CHECK-LABEL: @test define void @test() { -; CHECK-NOT: add %add = add i32 1, 2 -; CHECK-NOT: sub +; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 1, metadata [[add:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 2, DW_OP_stack_value)) %sub = sub i32 %add, 1 +; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 1, metadata [[sub:![0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 2, DW_OP_constu, 1, DW_OP_minus, DW_OP_stack_value)) +; CHECK-NEXT: ret void ret void } + +; CHECK: [[add]] = !DILocalVariable +; CHECK: [[sub]] = !DILocalVariable -- 2.11.0