Skip to content

Commit

Permalink
[GVN] Salvage debug info from dead insts
Browse files Browse the repository at this point in the history
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

llvm-svn: 325063
  • Loading branch information
vedantk committed Feb 13, 2018
1 parent 7558d86 commit 1d5d31b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion llvm/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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 5 additions & 1 deletion llvm/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)
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 1d5d31b

Please sign in to comment.