aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/MustExecute.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-08-20 20:50:12 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-08-20 20:50:12 +0000
commite6d1592492a3a379186bfb02bd0f4eda0669c0d5 (patch)
tree599ab169a01f1c86eda9adc774edaedde2f2db5b /lib/Analysis/MustExecute.cpp
parent1a56a5ead7a2e84bee8240f5f6b033b5f1707154 (diff)
Notes
Diffstat (limited to 'lib/Analysis/MustExecute.cpp')
-rw-r--r--lib/Analysis/MustExecute.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/Analysis/MustExecute.cpp b/lib/Analysis/MustExecute.cpp
index 180c38ddacc2..b616cd6f762b 100644
--- a/lib/Analysis/MustExecute.cpp
+++ b/lib/Analysis/MustExecute.cpp
@@ -1,9 +1,8 @@
//===- MustExecute.cpp - Printer for isGuaranteedToExecute ----------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -194,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.
@@ -204,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))