<div dir="ltr">One of the things I'm trying to do is perform high-level optimizations on loops, which requires first identifying them. For a simple case, suppose you have something like<br><br>for (size_t i = 0; i != n; ++i)<br>  ++a[i];<br><br>If a is a simple array, that will compile to a single basic block, which is easy enough to identify.<br><br>But the body doesn't need to be a single basic block. It could contain complex conditions, nested loops, whatever, and for some purposes, it's still valid to think of it as a single loop that does something to every element of a.<br><br>However, if there are branches into and out of the loop, that's no longer valid; it might do something to half the elements of the array and leave the other half untouched, for example.<br><br>I don't know what the concept I'm looking for - a loop that is guaranteed to proceed from beginning to end, with no branches in or out - is usually called; for the title of this post, I've called it a 'contained' loop.<br><br>I can figure out how to identify such, but I'd like to check whether this has already been done. Are there any existing passes or whatever that use this concept or identify such loops?<br></div>