[LoopInterchange] Properly move condition, induction increment and ops to latch.
authorFlorian Hahn <flo@fhahn.com>
Wed, 11 Sep 2019 08:23:23 +0000 (08:23 +0000)
committerFlorian Hahn <flo@fhahn.com>
Wed, 11 Sep 2019 08:23:23 +0000 (08:23 +0000)
commite4961218fd5b9bb36810b8dc05481f29068dbbdd
tree65d82737ebc53555ba1f3e6cc22ded34a24ee156
parent17ea9b463c66a6a9e978e87b9363c24e8e7e6e42
[LoopInterchange] Properly move condition, induction increment and ops to latch.

Currently we only rely on the induction increment to come before the
condition to ensure the required instructions get moved to the new
latch.

This patch duplicates and moves the required instructions to the
newly created latch. We move the condition to the end of the new block,
then process its operands. We stop at operands that are defined
outside the loop, or are the induction PHI.

We duplicate the instructions and update the uses in the moved
instructions, to ensure other users remain intact. See the added
test2 for such an example.

Reviewers: efriedma, mcrosier

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D67367

llvm-svn: 371595
llvm/lib/Transforms/Scalar/LoopInterchange.cpp
llvm/test/Transforms/LoopInterchange/interchangeable.ll
llvm/test/Transforms/LoopInterchange/perserve-lcssa.ll
llvm/test/Transforms/LoopInterchange/phi-ordering.ll
llvm/test/Transforms/LoopInterchange/pr43176-move-to-new-latch.ll [new file with mode: 0644]
llvm/test/Transforms/LoopInterchange/reductions-across-inner-and-outer-loop.ll