Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.520.2.2 -> 1.520.2.3 --- Log message: Initial patch for DIV -> SDIV/UDIV --- Diffs of the changes: (+13 -10) InstructionCombining.cpp | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-) Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.520.2.2 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.520.2.3 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.520.2.2 Thu Oct 19 19:34:44 2006 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu Oct 19 23:27:17 2006 @@ -1975,11 +1975,11 @@ } // 0 - (X sdiv C) -> (X sdiv -C) - if (Op1I->getOpcode() == Instruction::Div) + if (Op1I->getOpcode() == Instruction::SDiv) if (ConstantInt *CSI = dyn_cast<ConstantInt>(Op0)) - if (CSI->getType()->isSigned() && CSI->isNullValue()) + if (CSI->isNullValue()) if (Constant *DivRHS = dyn_cast<Constant>(Op1I->getOperand(1))) - return BinaryOperator::createDiv(Op1I->getOperand(0), + return BinaryOperator::createSDiv(Op1I->getOperand(0), ConstantExpr::getNeg(DivRHS)); // X - X*C --> X * (1-C) @@ -2174,11 +2174,13 @@ return BinaryOperator::createNeg(Op0); if (Instruction *LHS = dyn_cast<Instruction>(Op0)) - if (LHS->getOpcode() == Instruction::Div) + if (LHS->getOpcode() == Instruction::SDiv || + LHS->getOpcode()==Instruction::UDiv) if (ConstantInt *LHSRHS = dyn_cast<ConstantInt>(LHS->getOperand(1))) { // (X / C1) / C2 -> X / (C1*C2) - return BinaryOperator::createDiv(LHS->getOperand(0), - ConstantExpr::getMul(RHS, LHSRHS)); + return BinaryOperator::create( + Instruction::BinaryOps(LHS->getOpcode()), LHS->getOperand(0), + ConstantExpr::getMul(RHS, LHSRHS),""); } // Check to see if this is an unsigned division with an exact power of 2, @@ -2195,7 +2197,7 @@ // -X/C -> X/-C if (RHS->getType()->isSigned()) if (Value *LHSNeg = dyn_castNegVal(Op0)) - return BinaryOperator::createDiv(LHSNeg, ConstantExpr::getNeg(RHS)); + return BinaryOperator::createSDiv(LHSNeg, ConstantExpr::getNeg(RHS)); if (!RHS->isNullValue()) { if (SelectInst *SI = dyn_cast<SelectInst>(Op0)) @@ -2279,7 +2281,7 @@ RHS = ConstantExpr::getCast(R, NTy); else RHS = InsertNewInstBefore(new CastInst(Op1, NTy, Op1->getName()), I); - Instruction *Div = BinaryOperator::createDiv(LHS, RHS, I.getName()); + Instruction *Div = BinaryOperator::createUDiv(LHS, RHS, I.getName()); InsertNewInstBefore(Div, I); return new CastInst(Div, I.getType()); } @@ -3722,7 +3724,7 @@ static bool MulWithOverflow(ConstantInt *&Result, ConstantInt *In1, ConstantInt *In2) { Result = cast<ConstantInt>(ConstantExpr::getMul(In1, In2)); - return !In2->isNullValue() && ConstantExpr::getDiv(Result, In2) != In1; + return !In2->isNullValue() && ConstantExpr::getUDiv(Result, In2) != In1; } static bool isPositive(ConstantInt *C) { @@ -4379,7 +4381,8 @@ } break; - case Instruction::Div: + case Instruction::SDiv: + case Instruction::UDiv: // Fold: (div X, C1) op C2 -> range check if (ConstantInt *DivRHS = dyn_cast<ConstantInt>(LHSI->getOperand(1))) { // Fold this div into the comparison, producing a range check. _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits