If a loop is not rotated (for example when optimizing for size), the latch is not the backedge. If we promote an expression to post-inc form, we not only increase register pressure and add a COPY for that IV expression but for all IVs!
Motivating testcase:
void f(float *a, float *b, float *c, int n) { while (n-- > 0) *c++ = *a++ + *b++; }
It's imperative that the pointer increments be located in the latch block and not the header block; if not, we cannot use post-increment loads and stores and we have to keep both the post-inc and pre-inc values around until the end of the latch which bloats register usage.
Brendan, this change makes the Hexagon test "hwloop-crit-edge.ll" fail. To me it looks like the HexagonLoopOptimizer is perhaps a little too rigid in what it expects? I think the change in output of LSR is good, as it reduces register pressure and should be producing one less COPY. Could you please take a look and see what you think?
Did you want to specifically handle this for a loop with only one exiting block? Why not doing this within the if statement below in line 2130 ?