[LoopDeletion] Handle inner loops w/untaken backedges
authorPhilip Reames <listmail@philipreames.com>
Sat, 23 Jan 2021 00:31:29 +0000 (16:31 -0800)
committerPhilip Reames <listmail@philipreames.com>
Sat, 23 Jan 2021 00:31:29 +0000 (16:31 -0800)
commitef51eed37b7ed67b3c0e5f70fa61d681ba21787d
tree6bea7fcd5bceda22684f8e4aaec3f41d7c456b3b
parentba5628f2c2a9de049b80b3e276f7e05f481c49e7
[LoopDeletion] Handle inner loops w/untaken backedges

This builds on the restricted after initial revert form of D93906, and adds back support for breaking backedges of inner loops. It turns out the original invalidation logic wasn't quite right, specifically around the handling of LCSSA.

When breaking the backedge of an inner loop, we can cause blocks which were in the outer loop only because they were also included in a sub-loop to be removed from both loops. This results in the exit block set for our original parent loop changing, and thus a need for new LCSSA phi nodes.

This case happens when the inner loop has an exit block which is also an exit block of the parent, and there's a block in the child which reaches an exit to said block without also reaching an exit to the parent loop.

(I'm describing this in terms of the immediate parent, but the problem is general for any transitive parent in the nest.)

The approach implemented here involves a potentially expensive LCSSA rebuild.  Perf testing during review didn't show anything concerning, but we may end up needing to revert this if anyone encounters a practical compile time issue.

Differential Revision: https://reviews.llvm.org/D94378
llvm/lib/Transforms/Scalar/LoopDeletion.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/test/Transforms/IndVarSimplify/X86/pr45360.ll
llvm/test/Transforms/LoopDeletion/zero-btc.ll