[MachineCombiner] Preserve debug instruction number
authorFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Fri, 10 Mar 2023 03:22:50 +0000 (22:22 -0500)
committerFelipe de Azevedo Piovezan <fpiovezan@apple.com>
Mon, 13 Mar 2023 13:29:30 +0000 (09:29 -0400)
commit6e861d818ae428dd8d2915ce37206a60533cd2d4
tree3a7f7172ad822c43503ef11b6cb3cd7737406c75
parent554e40d6ba1cdeef1c0b82469bce3978fabc84a9
[MachineCombiner] Preserve debug instruction number

Each target's `TargetInstrInfo` is responsible for announcing which code
patterns it is able to transform during the MachineCombiner pass.
Currently, these patterns are applied without preserving the debug
instruction number required by the InstrRef implementation of
LiveDebugValues. As such, we've seen a number of examples where debug
information is dropped for variables in InstrRef mode that were
otherwise available in VarLoc mode. This has been observed both in X86
and AArch examples.

This commit is an initial attempt at preserving said numbers by changing
the general (target agnostic) implementation of TargetInstrInfo: the
reassociation pattern must keep the debug number of the "top level"
instruction, i.e., the instruction whose value represents the final
value of the arithmetic expression. Intermediate values must have their
debug number dropped, as they have no equivalent value in the
unoptimized code.

Future work is required to update each target's
`TargetInstrInfo::genAlternativeCodeSequence` method.

Differential Revision: https://reviews.llvm.org/D145759
llvm/lib/CodeGen/TargetInstrInfo.cpp
llvm/test/CodeGen/X86/machine-combiner-dbg.mir [new file with mode: 0644]