LoopFlatten wasn't triggering on this motivating case after IV widening:
void foo(int *A, int N, int M) { for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) f(A[i*M+j]); }
The reason was that the old induction phi nodes were getting in the way. These narrow and dead induction phis are not always trivially dead, and having both the narrow and wide IVs confused the analysis and caused it to bail. This adds some extra bookkeeping for these old phis, so we can filter them out when checks on phi nodes are performed. Other clean up passes will get rid of these old phis and increment instructions.
As this was one of the motivating examples from the beginning, it was surprising this wasn't triggering from C/C++ code. It looks like the IR and CFG is just slightly different.
Do we know this is always valid? For any sext? Or do we need to check the types match the new IV?