As part of loop canonicalization we can canonicalize backedges such that the backedge is unique and always jumps to the loop header. This gives a place in the loop to insert IR we only want inserted when we know we are going for another iteration of the loop. As an example this is the only reliable way to guarantee that strength reduction can create IR to compute an IV it wants to create and use at all potential points within the loop.
https://github.com/jakobbotsch/runtime/pull/new/canonicalize-backedges has an implementation of this, but it has large regressions. It seems it can break loop cloning/unrolling and probably other optimizations, so we'll need to generalize them first.
As part of loop canonicalization we can canonicalize backedges such that the backedge is unique and always jumps to the loop header. This gives a place in the loop to insert IR we only want inserted when we know we are going for another iteration of the loop. As an example this is the only reliable way to guarantee that strength reduction can create IR to compute an IV it wants to create and use at all potential points within the loop.
https://github.com/jakobbotsch/runtime/pull/new/canonicalize-backedges has an implementation of this, but it has large regressions. It seems it can break loop cloning/unrolling and probably other optimizations, so we'll need to generalize them first.