[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)
commit043e66137c01de5d9f9bf49b471036959018d7d8
tree0160254f7195a31744513b58884add8555e44198
parentb792e0694b678e08832d5cfcb52d800c6f1a01aa
[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

llvm-svn: 288851
llvm/lib/Transforms/Scalar/BDCE.cpp
llvm/test/Transforms/BDCE/pr26587.ll [new file with mode: 0644]