jayfoad wrote: The general idea of doing this in SimplifyCFG seems reasonable to me. However I am not too familiar with the existing code in SimplifyCFG. https://github.com/llvm/llvm-project/pull/82795