It is possible to cause hangs in JumpThreading due to how the pass decides there is no more work to be done. An older attempt at fixing this problem was D3991 where removeUnreachableBlocks(F) is now called on the function before any JumpThreading is attempted. This has a few drawbacks though:
- It's an expensive transformation.
- It is a coarse tool: it does not comprehend or care about preserving Loops.
- It actually has nothing to do with the JumpThreading pass.
- It does more than just remove unrechable blocks, it changes reachable blocks too, especially Terminator Instructions.
This patch foregoes calling removeUnreachableBlocks and uses a SmallPtrSet using the initial DominatorTree to track unreachable blocks.