+ } else if (I->getOpcode() == Instruction::Sub &&
+ I->getOperand(0) == Phi) {
+ // If the incoming value is a constant, just form a constant negative
+ // step. Otherwise, negate the step outside of the loop and use it.
+ Value *V = I->getOperand(1);
+ Constant *Zero = Constant::getNullValue(V->getType());
+ if (Constant *CV = dyn_cast<Constant>(V))
+ Step = ConstantExpr::get(Instruction::Sub, Zero, CV);
+ else if (Instruction *I = dyn_cast<Instruction>(V)) {
+ Step = BinaryOperator::create(Instruction::Sub, Zero, V,
+ V->getName()+".neg", I->getNext());
+
+ } else {
+ Step = BinaryOperator::create(Instruction::Sub, Zero, V,
+ V->getName()+".neg",
+ Phi->getParent()->getParent()->begin()->begin());
+ }