OSDN Git Service

[DCE] Salvage debug info from dead insts
authorVedant Kumar <vsk@apple.com>
Thu, 15 Feb 2018 22:26:18 +0000 (22:26 +0000)
committerVedant Kumar <vsk@apple.com>
Thu, 15 Feb 2018 22:26:18 +0000 (22:26 +0000)
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
test/Transforms/DCE/basic.ll

index fa4806e..d8575b7 100644 (file)
@@ -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<Instruction *, 16> &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) {
index c2a5659..6282ac7 100644 (file)
@@ -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