[MustExecute] Improve MustExecute to correctly handle loop nest
LI <loop invariant load instruction>
br for.inner, for.outer.latch
br for.outer, for.outer.exit
LI is a loop invariant load instruction that post dominate for.outer, so LI should be able to move out of the loop nest. However, there is a bug in allLoopPathsLeadToBlock().
Current algorithm of allLoopPathsLeadToBlock()
- get all the transitive predecessors of the basic block LI belongs to (for.inner) ==> for.outer, for.inner.latch
- if any successors of any of the predecessors are not for.inner or for.inner's predecessors, then return false
- return true
Although for.inner.latch is for.inner's predecessor, but for.inner dominates for.inner.latch, which means if for.inner.latch is ever executed, for.inner should be as well. It should not return false for cases like this.
Author: Whitney (committed by xingxue)
Reviewers: kbarton, jdoerfert, Meinersbur, hfinkel, fhahn
Reviewed By: jdoerfert
Subscribers: hiraditya, jsji, llvm-commits, etiotto, bmahjour
Differential Revision: https://reviews.llvm.org/D62418