This patch modifies TryToSinkInstruction in the InstCombine pass, to prevent redundant debug intrinsics from being produced, and also prevent the intrinsics from being emitted in an incorrect order. It does this by ensuring that when this pass sinks an instruction and creates clones of the debug intrinsics that use that instruction, it inserts those debug intrinsics in their original order, and only inserts the last debug intrinsic for each variable in the Instruction's block.
This patch was created to deal with an issue found while testing another patch (D94631) in which repeated sinking of instructions across a very large number of basic blocks resulted in a cascading mass of debug intrinsics as each sink clones each previous intrinsic as well as any new ones in the current basic block. For one of the clang 3.4 source files, this resulted in an LL file 14gb in size after optimizations; this patch reduces the resulting file to 5mb. Although this is a very extreme case, it is quite likely that this problem is occuring on a smaller scale for other large source files - large switches seem particularly susceptible (in this generated by CodeEmitterGenerator using TableGen).
Note that as redundant debug intrinsics will not be emitted in the final debug info, this patch should not have any actual effect on the size of debug info produced; it should however improve correctness in cases where debug intrinsics were being emitted out-of-order (causing old debug values to overwrite new ones), and has a positive effect on compile time and memory usage in cases where this issue occurs.
If we already know SrcBlock before we do this sort, I think it would be clearer to the reader if you start out by filtering out all the users not in SrcBlock. Then this comment about other blocks is unnecessary.