Operations cannot be moved in the middle of function walk.
Seems like you'd rather want to record the ops during the walk and then process them so that you don't have the issue?
The current change seems intrusive as the reordering may have non-trivial implications?
Putting a blocker for now.
I can record the ops by breaking down moveLoopInvariantCode so that it just returns the ops to hoist without doing it but I don't fully understand how this is better?
Is your concern that the hoisting of transfer op may expose more loop invariant code which could create more opportunity? If that the case we can just move the code doing the loop invariant code motion within the while loop and this should handle all the cases.
Yes, the latter is my concern, moving the code a few lines below under the while but outside of the walk seems good to me.
I don't have data that this will be better, just an intuition.