aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/LoopIndexSplit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/Scalar/LoopIndexSplit.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopIndexSplit.cpp38
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp
index d31a589a78..683a038824 100644
--- a/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp
@@ -1392,6 +1392,11 @@ bool LoopIndexSplit::splitLoop(SplitInfo &SD) {
if (!Succ0->getSinglePredecessor() || !Succ1->getSinglePredecessor())
return false;
+ // If Exiting block includes loop variant instructions then this
+ // loop may not be split safely.
+ if (!safeExitingBlock(SD, ExitCondition->getParent()))
+ return false;
+
// After loop is cloned there are two loops.
//
// First loop, referred as ALoop, executes first part of loop's iteration
@@ -1616,8 +1621,8 @@ void LoopIndexSplit::moveExitCondition(BasicBlock *CondBB, BasicBlock *ActiveBB,
/// - ExitBB's single predecessor was Latch
/// - Latch's second successor was Header
/// Now
-/// - ExitBB's single predecessor was Header
-/// - Latch's one and only successor was Header
+/// - ExitBB's single predecessor is Header
+/// - Latch's one and only successor is Header
///
/// Update ExitBB PHINodes' to reflect this change.
void LoopIndexSplit::updatePHINodes(BasicBlock *ExitBB, BasicBlock *Latch,
@@ -1632,27 +1637,18 @@ void LoopIndexSplit::updatePHINodes(BasicBlock *ExitBB, BasicBlock *Latch,
Value *V = PN->getIncomingValueForBlock(Latch);
if (PHINode *PHV = dyn_cast<PHINode>(V)) {
- // PHV is in Latch. PHV has two uses, one use is in ExitBB PHINode
- // (i.e. PN :)).
- // The second use is in Header and it is new incoming value for PN.
- PHINode *U1 = NULL;
- PHINode *U2 = NULL;
+ // PHV is in Latch. PHV has one use is in ExitBB PHINode. And one use
+ // in Header which is new incoming value for PN.
Value *NewV = NULL;
for (Value::use_iterator UI = PHV->use_begin(), E = PHV->use_end();
- UI != E; ++UI) {
- if (!U1)
- U1 = cast<PHINode>(*UI);
- else if (!U2)
- U2 = cast<PHINode>(*UI);
- else
- assert ( 0 && "Unexpected third use of this PHINode");
- }
- assert (U1 && U2 && "Unable to find two uses");
-
- if (U1->getParent() == Header)
- NewV = U1;
- else
- NewV = U2;
+ UI != E; ++UI)
+ if (PHINode *U = dyn_cast<PHINode>(*UI))
+ if (U->getParent() == Header) {
+ NewV = U;
+ break;
+ }
+
+ assert (NewV && "Unable to find new incoming value for exit block PHI");
PN->addIncoming(NewV, Header);
} else if (Instruction *PHI = dyn_cast<Instruction>(V)) {