OSDN Git Service

[DebugInfo] Avoid register coalesing unsoundly changing DBG_VALUE locations
authorJeremy Morse <jeremy.morse.llvm@gmail.com>
Thu, 27 Jun 2019 10:20:27 +0000 (10:20 +0000)
committerJeremy Morse <jeremy.morse.llvm@gmail.com>
Thu, 27 Jun 2019 10:20:27 +0000 (10:20 +0000)
commit4a65564b265163cf8bf9a7b6b09325c673066673
tree42ab467766b19c4aecd22d32d078b7726c2abc2b
parent419fa631cdc4558acabc006ad6c006d236971508
[DebugInfo] Avoid register coalesing unsoundly changing DBG_VALUE locations

Once MIR code leaves SSA form and the liveness of a vreg is considered,
DBG_VALUE insts are able to refer to non-live vregs, because their
debug-uses do not contribute to liveness. This non-liveness becomes
problematic for optimizations like register coalescing, as they can't
``see'' the debug uses in the liveness analyses.

As a result registers get coalesced regardless of debug uses, and that can
lead to invalid variable locations containing unexpected values. In the
added test case, the first vreg operand of ADD32rr is merged with various
copies of the vreg (great for performance), but a DBG_VALUE of the
unmodified operand is blindly updated to the modified operand. This changes
what value the variable will appear to have in a debugger.

Fix this by changing any DBG_VALUE whose operand will be resurrected by
register coalescing to be a $noreg DBG_VALUE, i.e. give the variable no
location. This is an overapproximation as some coalesced locations are
safe (others are not) -- an extra domination analysis would be required to
work out which, and it would be better if we just don't generate non-live
DBG_VALUEs.

This fixes PR40010.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364515 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/RegisterCoalescer.cpp
test/DebugInfo/MIR/X86/regcoalescing-clears-dead-dbgvals.mir [new file with mode: 0644]