aboutsummaryrefslogtreecommitdiffstats
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.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp
index 5064063..138e50d 100644
--- a/lib/Transforms/Scalar/LoopIndexSplit.cpp
+++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp
@@ -1330,6 +1330,23 @@ void LoopIndexSplit::calculateLoopBounds(SplitInfo &SD) {
// A_ExitValue = min(SplitValue, OrignalLoopExitValue)
// B_StartValue = max(SplitValue, OriginalLoopStartValue)
Instruction *InsertPt = L->getHeader()->getFirstNonPHI();
+
+ // If ExitValue operand is also defined in Loop header then
+ // insert new ExitValue after this operand definition.
+ if (Instruction *EVN =
+ dyn_cast<Instruction>(ExitCondition->getOperand(ExitValueNum))) {
+ if (!isa<PHINode>(EVN))
+ if (InsertPt->getParent() == EVN->getParent()) {
+ BasicBlock::iterator LHBI = L->getHeader()->begin();
+ BasicBlock::iterator LHBE = L->getHeader()->end();
+ for(;LHBI != LHBE; ++LHBI) {
+ Instruction *I = LHBI;
+ if (I == EVN)
+ break;
+ }
+ InsertPt = ++LHBI;
+ }
+ }
Value *C1 = new ICmpInst(Sign ?
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
AEV,