[DebugInfo] Nerf placeDbgValues, with prejudice
authorJeremy Morse <jeremy.morse@sony.com>
Mon, 9 Dec 2019 11:26:44 +0000 (11:26 +0000)
committerJeremy Morse <jeremy.morse@sony.com>
Mon, 9 Dec 2019 12:52:10 +0000 (12:52 +0000)
commit00e238896cd8ad3a7d715b8fb5f12a2e60af8a6f
tree9ce06a5c2475b3797fc3bc259f64fe00af4bbd08
parentf7e7a5f1b6dd318d39627445c6a9ca7568d8cd61
[DebugInfo] Nerf placeDbgValues, with prejudice

CodeGenPrepare::placeDebugValues moves variable location intrinsics to be
immediately after the Value they refer to. This makes tracking of locations
very easy; but it changes the order in which assignments appear to the
debugger, from the source programs order to the order in which the
optimised program computes values. This then leads to PR43986 and PR38754,
where variable locations that were in a conditional block are made
unconditional, which is highly misleading.

This patch adjusts placeDbgValues to only re-order variable location
intrinsics if they use a Value before it is defined, significantly reducing
the damage that it does. This is still not 100% safe, but the rest of
CodeGenPrepare needs polishing to correctly update debug info when
optimisations are performed to fully fix this.

This will probably break downstream debuginfo tests -- if the
instruction-stream position of variable location changes isn't the focus of
the test, an easy fix should be to manually apply placeDbgValues' behaviour
to the failing tests, moving dbg.value intrinsics next to SSA variable
definitions thus:

  %foo = inst1
  %bar = ...
  %baz = ...
  void call @llvm.dbg.value(metadata i32 %foo, ...

to

  %foo = inst1
  void call @llvm.dbg.value(metadata i32 %foo, ...
  %bar = ...
  %baz = ...

This should return your test to exercising whatever it was testing before.

Differential Revision: https://reviews.llvm.org/D58453
llvm/include/llvm/CodeGen/MachineInstr.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/test/DebugInfo/COFF/register-variables.ll
llvm/test/DebugInfo/NVPTX/debug-info.ll
llvm/test/DebugInfo/X86/DW_AT_location-reference.ll
llvm/test/DebugInfo/X86/PR37234.ll
llvm/test/DebugInfo/X86/codegenprep-addrsink.ll
llvm/test/tools/llvm-locstats/locstats.ll