[PATCH] D43255: [GVN] Salvage debug info from dead insts

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 13 13:43:52 PST 2018


vsk created this revision.
vsk added reviewers: mkazantsev, anemet.
vsk added a project: debug-info.
Herald added subscribers: JDevlieghere, aprantl.

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).


https://reviews.llvm.org/D43255

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


Index: test/Transforms/GVN/fence.ll
===================================================================
--- test/Transforms/GVN/fence.ll
+++ test/Transforms/GVN/fence.ll
@@ -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 @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 @@
 ; 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
Index: test/Transforms/GVN/PRE/phi-translate-2.ll
===================================================================
--- test/Transforms/GVN/PRE/phi-translate-2.ll
+++ test/Transforms/GVN/PRE/phi-translate-2.ll
@@ -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 @@
 ; 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 @@
   %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: lib/Transforms/Scalar/GVN.cpp
===================================================================
--- lib/Transforms/Scalar/GVN.cpp
+++ lib/Transforms/Scalar/GVN.cpp
@@ -2105,6 +2105,7 @@
     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 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43255.134109.patch
Type: text/x-patch
Size: 3010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180213/8c595170/attachment.bin>


More information about the llvm-commits mailing list