diff options
author | Xing Xue <xingxue@outlook.com> | 2019-05-27 13:57:28 +0000 |
---|---|---|
committer | Xing Xue <xingxue@outlook.com> | 2019-05-27 13:57:28 +0000 |
commit | 3860aad6e7f0c261512ece251a6796dd71450e90 (patch) | |
tree | 7de382d99c7a8593bc076e38869d6db70ca56aea /llvm/lib/Analysis/MustExecute.cpp | |
parent | 441ad62531308e48599c97a2867d370a8fb4b417 (diff) | |
download | bcm5719-llvm-3860aad6e7f0c261512ece251a6796dd71450e90.tar.gz bcm5719-llvm-3860aad6e7f0c261512ece251a6796dd71450e90.zip |
[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
Diffstat (limited to 'llvm/lib/Analysis/MustExecute.cpp')
-rw-r--r-- | llvm/lib/Analysis/MustExecute.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp index e22831cd6a9..b616cd6f762 100644 --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -193,7 +193,8 @@ bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop, SmallPtrSet<const BasicBlock *, 4> Predecessors; collectTransitivePredecessors(CurLoop, BB, Predecessors); - // Make sure that all successors of all predecessors of BB are either: + // Make sure that all successors of, all predecessors of BB which are not + // dominated by BB, are either: // 1) BB, // 2) Also predecessors of BB, // 3) Exit blocks which are not taken on 1st iteration. @@ -203,6 +204,12 @@ bool LoopSafetyInfo::allLoopPathsLeadToBlock(const Loop *CurLoop, // Predecessor block may throw, so it has a side exit. if (blockMayThrow(Pred)) return false; + + // BB dominates Pred, so if Pred runs, BB must run. + // This is true when Pred is a loop latch. + if (DT->dominates(BB, Pred)) + continue; + for (auto *Succ : successors(Pred)) if (CheckedSuccessors.insert(Succ).second && Succ != BB && !Predecessors.count(Succ)) |