Fixes the bug: https://bugs.llvm.org/show_bug.cgi?id=39339
When basic blocks are killed, either due to being empty or to being an if.then or if.else block whose complement contains identical instructions, the debug intrinsics in that block are lost. This fix attempts to recover those intrinsics by either hoisting or sinking them if possible, or replacing them in the above block with Undef values to prevent debug info from falling out-of-date.
I had to squint at this for a while to figure out why it's sufficient. Could you clear this up by writing the loop as for (auto I : *BB), then asserting isa<DbgInfoIntrinsic>(&I) || I.isTerminator()?