llvm-project/llvm/lib/Transforms/InstCombine
Adrian Prantl 47ea6478ed Salvage debug info from instructions about to be deleted
[Reapplies r297971 and punting on finding a better API for findDbgValues()]

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

llvm-svn: 297994
2017-03-16 21:14:09 +00:00
..
CMakeLists.txt [CMake] NFC. Updating CMake dependency specifications 2016-11-17 04:36:50 +00:00
InstCombineAddSub.cpp [InstCombine] don't try SimplifyDemandedInstructionBits from add/sub because it's slow and unlikely to succeed 2017-02-22 23:01:12 +00:00
InstCombineAndOrXor.cpp [InstCombine] Fold ((C1 OP zext(X)) & C2) -> zext((C1 OP X) & C2) 2017-01-17 18:08:06 +00:00
InstCombineCalls.cpp AMDGPU: Fold icmp/fcmp into icmp intrinsic 2017-03-13 18:14:02 +00:00
InstCombineCasts.cpp [InstCombine] Liberate assert in InstCombiner::visitZExt 2017-03-16 13:22:01 +00:00
InstCombineCompares.cpp [InstCombine] Avoid faulty combines of select-cmp-br 2017-03-02 15:18:58 +00:00
InstCombineInternal.h Salvage debug info from instructions about to be deleted 2017-03-16 21:14:09 +00:00
InstCombineLoadStoreAlloca.cpp [InstCombine] Fix bug in pointer replacement 2017-02-24 20:27:25 +00:00
InstCombineMulDivRem.cpp [InstCombine] improve readability; NFCI 2017-03-14 17:27:27 +00:00
InstCombinePHI.cpp fix formatting; NFC 2017-01-31 17:25:42 +00:00
InstCombineSelect.cpp [InstCombine] avoid breaking up bitcasted vector min/max patterns (PR32306) 2017-03-16 20:42:45 +00:00
InstCombineShifts.cpp [InstCombine] allow (X * C2) << C1 --> X * (C2 << C1) for vectors 2017-02-09 23:13:04 +00:00
InstCombineSimplifyDemanded.cpp AMDGPU: Fix insertion point when reducing load intrinsics 2017-03-10 05:25:49 +00:00
InstCombineVectorOps.cpp InstCombine: fix extraction when performing vector/array punning 2017-02-17 07:36:03 +00:00
InstructionCombining.cpp [InstCombine] use dyn_cast instead of isa+cast; NFCI 2017-03-06 23:25:28 +00:00
LLVMBuild.txt