OSDN Git Service

[GVN] Salvage debug info from dead insts
authorVedant Kumar <vsk@apple.com>
Tue, 13 Feb 2018 22:27:17 +0000 (22:27 +0000)
committerVedant Kumar <vsk@apple.com>
Tue, 13 Feb 2018 22:27:17 +0000 (22:27 +0000)
This preserves an additional 581 unique source variables in a stage2
build of clang (according to `llvm-dwarfdump --statistics`). It
increases the size of the .debug_loc section by 0.1% (or 87139 bytes).

Differential Revision: https://reviews.llvm.org/D43255

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325063 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVN.cpp
test/Transforms/GVN/PRE/phi-translate-2.ll
test/Transforms/GVN/fence.ll

index e2c1eaf..a910440 100644 (file)
@@ -2105,6 +2105,7 @@ bool GVN::processBlock(BasicBlock *BB) {
     for (auto *I : InstrsToErase) {
       assert(I->getParent() == BB && "Removing instruction from wrong block?");
       DEBUG(dbgs() << "GVN removed: " << *I << '\n');
+      salvageDebugInfo(*I);
       if (MD) MD->removeInstruction(I);
       DEBUG(verifyRemoved(I));
       if (MaybeFirstICF == I) {
@@ -2320,6 +2321,7 @@ bool GVN::performScalarPRE(Instruction *CurInst) {
   VN.eraseTranslateCacheEntry(ValNo, *CurrentBlock);
   addToLeaderTable(ValNo, Phi, CurrentBlock);
   Phi->setDebugLoc(CurInst->getDebugLoc());
+  salvageDebugInfo(*CurInst);
   CurInst->replaceAllUsesWith(Phi);
   if (MD && Phi->getType()->isPtrOrPtrVectorTy())
     MD->invalidateCachedPointerInfo(Phi);
index 8920db9..c941e04 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: opt < %s -gvn -S | FileCheck %s
+; RUN: opt < %s -debugify -gvn -S | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 
 @a = common global [100 x i64] zeroinitializer, align 16
@@ -142,6 +142,8 @@ critedge.loopexit:
 ; CHECK: if.end3:
 ; CHECK: %[[PREPHI:.*]] = phi i64 [ %sub.ptr.sub, %if.else ], [ %[[SUB]], %if.then2 ], [ %sub.ptr.sub, %entry ]
 ; CHECK: %[[DIV:.*]] = ashr exact i64 %[[PREPHI]], 2
+; CHECK: call void @llvm.dbg.value(metadata i32* %p.0, metadata [[var_p0:![0-9]+]], metadata !DIExpression())
+; CHECK: call void @llvm.dbg.value(metadata i32* %p.0, metadata [[var_sub_ptr:![0-9]+]], metadata !DIExpression())
 ; CHECK: ret i64 %[[DIV]]
 
 declare void @bar(...) local_unnamed_addr #1
@@ -174,3 +176,6 @@ if.end3:                                          ; preds = %if.then2, %if.else,
   %sub.ptr.div7 = ashr exact i64 %sub.ptr.sub6, 2
   ret i64 %sub.ptr.div7
 }
+
+; CHECK: [[var_p0]] = !DILocalVariable
+; CHECK: [[var_sub_ptr]] = !DILocalVariable
index a2d98e1..273c3b6 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: opt -S -basicaa -gvn < %s | FileCheck %s
+; RUN: opt -S -debugify -basicaa -gvn < %s | FileCheck %s
 
 @a = external constant i32
 ; We can value forward across the fence since we can (semantically) 
@@ -19,6 +19,8 @@ define i32 @test(i32* %addr.i) {
 define i32 @test2(i32* %addr.i) {
 ; CHECK-LABEL: @test2
 ; CHECK-NEXT: fence
+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %addr.i, metadata [[var_a:![0-9]+]], metadata !DIExpression(DW_OP_deref))
+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32* %addr.i, metadata [[var_a2:![0-9]+]], metadata !DIExpression(DW_OP_deref))
 ; CHECK-NOT: load
 ; CHECK: ret
   %a = load i32, i32* %addr.i, align 4
@@ -87,3 +89,5 @@ define i32 @test4(i32* %addr) {
 ; Given we chose to forward across the release fence, we clearly can't forward
 ; across the acquire fence as well.
 
+; CHECK: [[var_a]] = !DILocalVariable
+; CHECK-NEXT: [[var_a2]] = !DILocalVariable