- if (Val->getType() != IV->Start->getType())
- Val = InsertCast(Val, IV->Start->getType(),
- Header->begin()+InsertPos++);
-
- Val = BinaryOperator::create(Instruction::Add, Val, IV->Start, Name);
- // Insert the phi node at the end of the other phi nodes...
- Header->getInstList().insert(Header->begin()+InsertPos++, Val);
+ if (Val->getType() != IVTy)
+ Val = InsertCast(Val, IVTy, AfterPHIIt);
+ if (IV->Start->getType() != IVTy)
+ IV->Start = InsertCast(IV->Start, IVTy, AfterPHIIt);
+
+ // Insert the instruction after the phi nodes...
+ Val = BinaryOperator::create(Instruction::Add, Val, IV->Start,
+ IV->Phi->getName()+"-offset", AfterPHIIt);