OSDN Git Service

Salvage debug info from instructions about to be deleted
authorAdrian Prantl <aprantl@apple.com>
Thu, 16 Mar 2017 18:22:52 +0000 (18:22 +0000)
committerAdrian Prantl <aprantl@apple.com>
Thu, 16 Mar 2017 18:22:52 +0000 (18:22 +0000)
commit80bfdf1f49530ef68c5abbcd932c2c4b58917a71
tree1689ef19c5718482d15a1300d34081f24a0252cd
parentaad0d391c9c50d41d59045bb5a7e508bc4ecb140
Salvage debug info from instructions about to be deleted

This patch improves debug info quality in InstCombine by looking at
values that are about to be deleted, checking whether there are any
dbg.value instrinsics referring to them, and potentially encoding the
semantics of the deleted instruction into the dbg.value's
DIExpression.

In the example in the testcase (which was extracted from XNU) there is a sequence of

  %4 = load %struct.entry*, %struct.entry** %next2, align 8, !dbg !41
  %5 = bitcast %struct.entry* %4 to i8*, !dbg !42
  %add.ptr4 = getelementptr inbounds i8, i8* %5, i64 -8, !dbg !43
  %6 = bitcast i8* %add.ptr4 to %struct.entry*, !dbg !44
  call void @llvm.dbg.value(metadata %struct.entry* %6, i64 0, metadata !20, metadata !21), !dbg 34

When these instructions are eliminated by instcombine one after
another, we can still salvage the otherwise dead debug info:

- Bitcasts have no effect, so have the dbg.value point to operand(0)
- Loads can be expressed via a DW_OP_deref
- Constant gep instructions can be replaced by DWARF expression arithmetic

The API introduced by this patch is not specific to instcombine and
can be useful in other places, too.

rdar://problem/30725338

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297971 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Transforms/Utils/Local.h
lib/Transforms/InstCombine/InstCombineInternal.h
lib/Transforms/Utils/Local.cpp
test/Transforms/InstCombine/debuginfo-dce.ll [new file with mode: 0644]