This is a simple pass that flattens nested loops.
The intention is to optimise loop nests like this, which together
access an array linearly:
for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) f(A[i*M+j]);
into one loop:
for (int i = 0; i < (N*M); ++i) f(A[i]);
It can also flatten loops where the induction variables are not used
in the loop. This can help with codesize and runtime, especially on
simple cpus without advanced branch prediction.
This is only worth flattening if the induction variables are only used
in an expression like i*M+j. If they had any other uses, we would have
to insert a div/mod to reconstruct the original values, so this
wouldn't be profitable.
This pass was originally written by Oliver Stannard, but he had to
go do other super important things. This have been changed a little
since then. There is a patch to enable loop versioning that will
follow.
Why are these predicates valid and not any others?