[LoopDeletion] Break backedge if we can prove that the loop is exited on 1st iteratio...
authorMax Kazantsev <mkazantsev@azul.com>
Fri, 18 Jun 2021 10:30:36 +0000 (17:30 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Fri, 18 Jun 2021 10:31:57 +0000 (17:31 +0700)
commitde92287cf8d1b07516b7e006a54529f174d4f5ef
treedeab33addbe02ef685dbc6b25d720db8bfd264e0
parent18c8c934d8584f706dfca9e633f0f89cefe3688e
[LoopDeletion] Break backedge if we can prove that the loop is exited on 1st iteration (try 3)

This patch handles one particular case of one-iteration loops for which SCEV
cannot straightforwardly prove BECount = 1. The idea of the optimization is to
symbolically execute conditional branches on the 1st iteration, moving in topoligical
order, and only visiting blocks that may be reached on the first iteration. If we find out
that we never reach header via the latch, then the backedge can be broken.

This implementation uses InstSimplify. SCEV version was rejected due to high
compile time impact.

Differential Revision: https://reviews.llvm.org/D102615
Reviewed By: nikic
llvm/lib/Transforms/Scalar/LoopDeletion.cpp
llvm/test/Transforms/LoopDeletion/eval_first_iteration.ll
llvm/test/Transforms/LoopDeletion/unreachable-loops.ll
llvm/test/Transforms/LoopDeletion/zero-btc.ll