}
Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
}
Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(I.getOperand(1))) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(I.getOperand(1))) {
if (RHS->equalsInt(1))
return ReplaceInstUsesWith(I, I.getOperand(0));
if (RHS->equalsInt(1))
return ReplaceInstUsesWith(I, I.getOperand(0));
+ // div X, -1 == -X
+ if (RHS->isAllOnesValue())
+ return BinaryOperator::createNeg(I.getOperand(0));
+
// Check to see if this is an unsigned division with an exact power of 2,
// if so, convert to a right shift.
if (ConstantUInt *C = dyn_cast<ConstantUInt>(RHS))
// Check to see if this is an unsigned division with an exact power of 2,
// if so, convert to a right shift.
if (ConstantUInt *C = dyn_cast<ConstantUInt>(RHS))