hfinkel added a comment. Do you have a test case? It looks like you're making this algorithm directly recursive with a worst-case recursion depth given only by the number of blocks. Is the right? Can we say something about the worst case here? https://reviews.llvm.org/D29966