This patch handles two optimisations, TwoAddressInstruction and X86's FixupLEAs pass, both of which optimise by re-creating instructions. For LEAs, various bits of arithmetic are better represented as LEAs on X86, while TwoAddressInstruction sometimes converts instrs into three address instructions if it's profitable. Both of these require substitutions to be created -- test that an entry is made in the MIR output. (Handling of this in LiveDebugValues comes later).
Probably all of them; I'm aware of at least one other x86 pass that requires a similar action (x86-fixup-bw-insts) and MachineCSE will need it too. I haven't yet looked at non-x86 targets.
I don't think I wrote this down anywhere else, but I'd like this patch to be seen as a "proof of concept" that debug instruction-numbers can / should be transferred in this way. Comprehensively dealing with all the places this action is required is a large-ish problem, which I'd prefer to address in a different patch series if possible. That means that, were this series to land today, there would be some variable locations dropped; but the work is after all in an experimental state hidden behind a flag.
were this series to land today, there would be some variable locations dropped
To avoid this sounding like there's a huge loss: my current testing with this series and the llvm-locstats script on stage2 clang shows no reduction in the "total [variable] availability" number, and a 2% fall in "PC ranges covered", which I would characterise as "most locations preserved with some corner cases still to address".