For the problem described in https://reviews.llvm.org/D67359, turns out the root cause is there are many duplicates in ExitBlocks so the algorithm complexity of hasDedicatedExits gets very high. If we remove the duplicates, the compile time issue is gone.
Thanks to Philip Reames for raising a good question and lead me to find the root cause.
But how to properly add a compile time test is still a question for me.
Please see: getUniqueExitBlocks on Loop.