[MustExec][LICM] Handle latch being part of an inner cycle (PR57780)
authorNikita Popov <npopov@redhat.com>
Tue, 20 Sep 2022 11:04:27 +0000 (13:04 +0200)
committerNikita Popov <npopov@redhat.com>
Tue, 11 Oct 2022 07:30:13 +0000 (09:30 +0200)
commit884bb97dca257b90dbe6fd0faf09512858292151
tree98f8ccb0cd1175def614d969843fb9627ac91891
parent8d4ebd1a7c9e1f47a4a610aeb41d1613f822ee20
[MustExec][LICM] Handle latch being part of an inner cycle (PR57780)

The algorithm in allLoopPathsLeadToBlock() does not handle the case
where the loop latch is part of the predecessor set correctly: In
this case, we may take the backedge (escaping to a different loop
iteration) and not execute other latch successors. This can happen
if the latch is part of an inner cycle.

Fixes https://github.com/llvm/llvm-project/issues/57780.

Differential Revision: https://reviews.llvm.org/D134279
llvm/lib/Analysis/MustExecute.cpp
llvm/test/Analysis/MustExecute/pr57780.ll
llvm/test/Transforms/LICM/pr57780.ll