[LoopDeletion] Break backedge of outermost loops when known not taken
authorPhilip Reames <listmail@philipreames.com>
Sun, 10 Jan 2021 23:57:25 +0000 (15:57 -0800)
committerPhilip Reames <listmail@philipreames.com>
Mon, 11 Jan 2021 00:02:33 +0000 (16:02 -0800)
commit4739dd67e7a08b715f1d23f71fb4af16007fe80a
tree7298efc3245cfd725e1ca1b5e03745626ce1bb22
parent02bc320545deb0212a43acae24fcf2383755d383
[LoopDeletion] Break backedge of outermost loops when known not taken

This is a resubmit of dd6bb367 (which was reverted due to stage2 build failures in 7c63aac), with the additional restriction added to the transform to only consider outer most loops.

As shown in the added test case, ensuring LCSSA is up to date when deleting an inner loop is tricky as we may actually need to remove blocks from any outer loops, thus changing the exit block set.   For the moment, just avoid transforming this case.  I plan to return to this case in a follow up patch and see if we can do better.

Original commit message follows...

The basic idea is that if SCEV can prove the backedge isn't taken, we can go ahead and get rid of the backedge (and thus the loop) while leaving the rest of the control in place. This nicely handles cases with dispatch between multiple exits and internal side effects.

Differential Revision: https://reviews.llvm.org/D93906
llvm/include/llvm/Transforms/Utils/LoopUtils.h
llvm/lib/Transforms/Scalar/LoopDeletion.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/test/Transforms/IndVarSimplify/exit_value_test2.ll
llvm/test/Transforms/LoopDeletion/update-scev.ll
llvm/test/Transforms/LoopDeletion/zero-btc.ll