[LoopSimplifyCFG] Check predecessors of exits before marking them dead.
authorFlorian Hahn <flo@fhahn.com>
Fri, 18 Mar 2022 08:54:44 +0000 (08:54 +0000)
committerFlorian Hahn <flo@fhahn.com>
Fri, 18 Mar 2022 08:54:44 +0000 (08:54 +0000)
commit4a699ae9c6a6fde93ec4714d79025df58eb62a72
treeebef02bdcaca97f2242bbd1476220a05af0f7567
parent42e8e00189be787b4d916c6d297a8315998c7687
[LoopSimplifyCFG] Check predecessors of exits before marking them dead.

LoopSimplifyCFG may process loops that are not in
loop-simplify/canonical form. For loops not in canonical form, exit
blocks may be reachable from non-loop blocks and we cannot consider them
as dead if they only are not reachable from the loop itself.

Unfortunately the smallest test I could come up with requires running
multiple passes:
    -passes='loop-mssa(loop-instsimplify,loop-simplifycfg,simple-loop-unswitch)'

The reason is that loops are canonicalized at the beginning of loop
pipelines, so a later transform has to break canonical form in a way
that breaks LoopSimplifyCFG's dead-exit analysis.

Alternatively we could try to require all loop passes to maintain
canonical form. That in turn would also require additional verification.

Fixes #54023, #49931.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D121925
llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
llvm/test/Transforms/LoopSimplifyCFG/loop-not-in-simplify-form.ll