Fix PR1692
[oota-llvm.git] / lib / Transforms / Scalar / LoopIndexSplit.cpp
index 9e2f11bb6dea4aa7ce466bbb21fa1c6833988e21..afb7339093a0ac13571273b833c2458dcdea8fc1 100644 (file)
@@ -1181,15 +1181,17 @@ void LoopIndexSplit::calculateLoopBounds(SplitInfo &SD) {
   // values in original loop's preheader.
   //      A_ExitValue = min(SplitValue, OrignalLoopExitValue)
   //      B_StartValue = max(SplitValue, OriginalLoopStartValue)
+  Instruction *InsertPt = L->getHeader()->getFirstNonPHI();
   Value *C1 = new ICmpInst(Sign ?
                            ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
                            AEV,
                            ExitCondition->getOperand(ExitValueNum), 
-                           "lsplit.ev", PHTerminator);
+                           "lsplit.ev", InsertPt);
+
   SD.A_ExitValue = new SelectInst(C1, AEV,
                                   ExitCondition->getOperand(ExitValueNum), 
-                                  "lsplit.ev", PHTerminator);
-  
+                                  "lsplit.ev", InsertPt);
+
   Value *C2 = new ICmpInst(Sign ?
                            ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
                            BSV, StartValue, "lsplit.sv",