This patch fixes a debug-info-changes-codegen problem, reported here:
https://github.com/llvm/llvm-project/issues/50525
Where the unreachableblockelim pass wouldn't delete an empty unreachable block due to the presence of debug-info instructions. The solution, as ever, is to ignore the debug-info instructions. This particular function is different, in that it steps through the block backwards, and so existing filter functions aren't suitable as they all expect forward iterators. Thus, a help lambda is required.
The most worry part here is replacing a line that is:
BB->getInsnlist().pop_back()
With Instruction::eraseFromParent on a non-back instruction. I think this is fine: it's just that over time, the set of helper functions that LLVM uses has changed, and this line hasn't been changed since at least 2008: https://github.com/llvm/llvm-project/commit/bcc904a67c2f77b6a619d8ec9370af02e3a5ce02