I would really appreciate careful review on the analysis update logic in the newly added function.
PlaceSafepoints was previously using an inner pass manager to run an analysis pass *after* modifying the IR to remove unreachable blocks. In an effort to get rid of the inner pass manager (and the various dominator tree recalcs it implied), I switched to using the analysis infrastructure to actually get the various analysis needed and convert the inner pass manager stuff into a small non-pass helper class.
However, I couldn't figure out how to keep the analysis results up to date over a call to removeUnreachableBlocks. That routine freely modifies the CFG in non-trivial ways with no provisions for updating any of dominator tree, or loop info. Instead, I introduced a new helper function which *only* removes blocks which aren't reachable from the function entry according to the dominator tree. This version supports analysis updating for DT, LI, and (implicitly) SE.
After making the change for PlaceSafepoints, I noticed that RewriteSafepointsForGC had a related invalidation bug. If there was an unreachable statepoint, the analysis results were out of sync with the function being processed after unreachable code was removed.
I suspect - but have not investigated in great depth - that other callers of removeUnreachableBlocks might have similar invalidation bugs. In particular, I'm extremely suspicious of CodeGen/WinEHPrepare.
Can you please add an example on when differences between "removeBlocksNotReachableFromEntry" and "removeUnreachableBlocks" do matter?