[DebugInfo][InstrRef] Avoid crash when values optimised out late in sdag
authorJeremy Morse <jeremy.morse@sony.com>
Wed, 24 Nov 2021 10:20:03 +0000 (10:20 +0000)
committerJeremy Morse <jeremy.morse@sony.com>
Wed, 24 Nov 2021 10:34:48 +0000 (10:34 +0000)
commitb8f68ad9cdb11d585acc6c38ad124b32efb6178a
treed4e46b155017a6233311b423d64a0eb389d0190f
parentd9af9c2c5a53c9ba6aa0255240a2a40e8bea27aa
[DebugInfo][InstrRef] Avoid crash when values optimised out late in sdag

It appears that we can emit all the instructions for a function, including
debug instructions, and then optimise some of the values out late.
Specifically, in the attached test case, an argument gets optimised out
after DBG_VALUE / DBG_INSTR_REFs are created. This confuses
MachineFunction::finalizeDebugInstrRefs, which expects to be able to find a
defining instruction, and crashes instead.

Fix this by identifying when there's no defining instruction, and
translating that instead into a DBG_VALUE $noreg.

Differential Revision: https://reviews.llvm.org/D114476
llvm/lib/CodeGen/MachineFunction.cpp
llvm/test/DebugInfo/X86/instr-ref-sdag-empty-vreg.ll [new file with mode: 0644]