aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopUtils.cpp
diff options
context:
space:
mode:
authorXin Tong <trent.xin.tong@gmail.com>2017-04-24 17:12:22 +0000
committerXin Tong <trent.xin.tong@gmail.com>2017-04-24 17:12:22 +0000
commita266923d5749d98464d662ba23149eb082eb01df (patch)
tree85c5574ec00ad47d7adeee5bbf8e310618e0f9ec /llvm/lib/Transforms/Utils/LoopUtils.cpp
parent9c661853150e304b9c6604df44a0181795ae633f (diff)
downloadllvm-a266923d5749d98464d662ba23149eb082eb01df.zip
llvm-a266923d5749d98464d662ba23149eb082eb01df.tar.gz
llvm-a266923d5749d98464d662ba23149eb082eb01df.tar.bz2
Compute safety information in a much finer granularity.
Summary: Instead of keeping a variable indicating whether there are early exits in the loop. We keep all the early exits. This improves LICM's ability to move instructions out of the loop based on is-guaranteed-to-execute. I am going to update compilation time as well soon. Reviewers: hfinkel, sanjoy, efriedma, mkuper Reviewed By: hfinkel Subscribers: llvm-commits, mzolotukhin Differential Revision: https://reviews.llvm.org/D32433 llvm-svn: 301196
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopUtils.cpp24
1 files changed, 8 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 175d013a..062432f 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1044,21 +1044,11 @@ bool llvm::isGuaranteedToExecute(const Instruction &Inst,
const DominatorTree *DT, const Loop *CurLoop,
const LoopSafetyInfo *SafetyInfo) {
// We have to check to make sure that the instruction dominates all
- // of the exit blocks. If it doesn't, then there is a path out of the loop
- // which does not execute this instruction, so we can't hoist it.
-
- // If the instruction is in the header block for the loop (which is very
- // common), it is always guaranteed to dominate the exit blocks. Since this
- // is a common case, and can save some work, check it now.
- if (Inst.getParent() == CurLoop->getHeader())
- // If there's a throw in the header block, we can't guarantee we'll reach
- // Inst.
- return !SafetyInfo->HeaderMayThrow;
-
- // Somewhere in this loop there is an instruction which may throw and make us
- // exit the loop.
- if (SafetyInfo->MayThrow)
- return false;
+ // of the exit points. If it doesn't, then there is a path out of the loop
+ // which does not execute this instruction and its not guaranteed to execute.
+ for (Instruction *ExitInst : SafetyInfo->EarlyExits)
+ if (!DT->dominates(&Inst, ExitInst))
+ return false;
// Get the exit blocks for the current loop.
SmallVector<BasicBlock *, 8> ExitBlocks;
@@ -1071,7 +1061,9 @@ bool llvm::isGuaranteedToExecute(const Instruction &Inst,
// As a degenerate case, if the loop is statically infinite then we haven't
// proven anything since there are no exit blocks.
- if (ExitBlocks.empty())
+ // However, we also special case instruction from the header as the header
+ // is always guaranteed to execute.
+ if (ExitBlocks.empty() && Inst.getParent() != CurLoop->getHeader())
return false;
// FIXME: In general, we have to prove that the loop isn't an infinite loop.