OSDN Git Service

[BDCE/DebugInfo] Preserve llvm.dbg.value's argument.
authorDavide Italiano <davide@freebsd.org>
Tue, 6 Dec 2016 21:52:47 +0000 (21:52 +0000)
committerDavide Italiano <davide@freebsd.org>
Tue, 6 Dec 2016 21:52:47 +0000 (21:52 +0000)
commit7f581f5e5f40c0ce306615980bf2497f3f8a4dfa
treeed2a99f83bda3577282b13a8924d05866985b156
parent4fae32e28baffebc13168be979af5397fed048bf
[BDCE/DebugInfo] Preserve llvm.dbg.value's argument.

BDCE has two phases:
1. It asks SimplifyDemandedBits if all the bits of an instruction are dead, and if so,
replaces all its uses with the constant zero.
2. Then, it asks SimplifyDemandedBits again if the instruction is really dead
(no side effects etc..) and if so, eliminates it.

Now, in 1) if all the bits of an instruction are dead, we may end up replacing a dbg use:
  %call = tail call i32 (...) @g() #4, !dbg !15
  tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !8, metadata !16), !dbg !17
->
  %call = tail call i32 (...) @g() #4, !dbg !15
  tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !8, metadata !16), !dbg !17

but not eliminating the call because it may have arbitrary side effects.
In other words, we lose some debug informations.
This patch fixes the problem making sure that BDCE does nothing with the instruction if
it has side effects and no non-dbg uses.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288851 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/BDCE.cpp
test/Transforms/BDCE/pr26587.ll [new file with mode: 0644]