This fixes PR37229.
Basically, we don't want to transform a loop to a CTR loop if the decrement-and-branch instruction would end up in an exiting block that is also part of another nested loop. Previously this couldn't happen because of how SCEV computed the trip count. However, the check is fundamentally needed.
By definition, loop header dominates all blocks of this loop. So once you've checked that LI->getLoop(*I) is L, it will automatically give you the second part of the check. I think you can assert that DT->dominates(L->getHeader(), *I)) if the first part is true.