This patch fixes the problems reported in https://reviews.llvm.org/D107219.
Two crashed cases are mentioned there:
- LNICM tries to sink an instruction whose users are used in the current loop, and crash.
- LNICM tries to sink an instruction whose (PHI) user prevents from sinking for some reasons, and crash.
it would be good to check for something other than just the return code in this test. Also, can you clean up the basic block names and maybe get rid of the unreachable?