HomePhabricator

[MustExecute] Improve MustExecute to correctly handle loop nest

Authored by xingxue on May 27 2019, 6:57 AM.

Description

[MustExecute] Improve MustExecute to correctly handle loop nest

Summary:
for.outer:

br for.inner

for.inner:

LI <loop invariant load instruction>

for.inner.latch:

br for.inner, for.outer.latch

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()

  1. get all the transitive predecessors of the basic block LI belongs to (for.inner) ==> for.outer, for.inner.latch
  2. if any successors of any of the predecessors are not for.inner or for.inner's predecessors, then return false
  3. 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

Tags: #LLVM

Differential Revision: https://reviews.llvm.org/D62418

llvm-svn: 361762

Details

Committed
xingxueMay 27 2019, 6:57 AM
Reviewer
jdoerfert
Differential Revision
D62418: [MustExecute] Improve MustExecute to correctly handle loop nest
Parents
rG441ad6253130: Test commit (NFC)
Branches
Unknown
Tags
Unknown