summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/LICM.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index f07158a6cb1..e145981846d 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -120,6 +120,7 @@ namespace {
bool MayThrow; // The current loop contains an instruction which
// may throw, thus preventing code motion of
// instructions with side effects.
+ bool HeaderMayThrow; // Same as previous, but specific to loop header
DenseMap<Loop*, AliasSetTracker*> LoopToAliasSetMap;
/// cloneBasicBlockAnalysis - Simple Analysis hook. Clone alias set info.
@@ -273,7 +274,12 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
CurAST->add(*BB); // Incorporate the specified basic block
}
- MayThrow = false;
+ HeaderMayThrow = false;
+ BasicBlock *Header = L->getHeader();
+ for (BasicBlock::iterator I = Header->begin(), E = Header->end();
+ (I != E) && !HeaderMayThrow; ++I)
+ HeaderMayThrow |= I->mayThrow();
+ MayThrow = HeaderMayThrow;
// TODO: We've already searched for instructions which may throw in subloops.
// We may want to reuse this information.
for (Loop::block_iterator BB = L->block_begin(), BBE = L->block_end();
@@ -659,12 +665,7 @@ bool LICM::isSafeToExecuteUnconditionally(Instruction &Inst) {
bool LICM::isGuaranteedToExecute(Instruction &Inst) {
- // Somewhere in this loop there is an instruction which may throw and make us
- // exit the loop.
- if (MayThrow)
- return false;
-
- // Otherwise we have to check to make sure that the instruction dominates all
+ // 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.
@@ -672,7 +673,14 @@ bool LICM::isGuaranteedToExecute(Instruction &Inst) {
// 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())
- return true;
+ // If there's a throw in the header block, we can't guarantee we'll reach
+ // Inst.
+ return !HeaderMayThrow;
+
+ // Somewhere in this loop there is an instruction which may throw and make us
+ // exit the loop.
+ if (MayThrow)
+ return false;
// Get the exit blocks for the current loop.
SmallVector<BasicBlock*, 8> ExitBlocks;
OpenPOWER on IntegriCloud