forked from OSchip/llvm-project
parent
e24003a261
commit
e20c334e65
|
@ -849,11 +849,15 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
|
Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
|
||||||
// div X, 1 == X
|
|
||||||
if (ConstantInt *RHS = dyn_cast<ConstantInt>(I.getOperand(1))) {
|
if (ConstantInt *RHS = dyn_cast<ConstantInt>(I.getOperand(1))) {
|
||||||
|
// div X, 1 == X
|
||||||
if (RHS->equalsInt(1))
|
if (RHS->equalsInt(1))
|
||||||
return ReplaceInstUsesWith(I, I.getOperand(0));
|
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,
|
// Check to see if this is an unsigned division with an exact power of 2,
|
||||||
// if so, convert to a right shift.
|
// if so, convert to a right shift.
|
||||||
if (ConstantUInt *C = dyn_cast<ConstantUInt>(RHS))
|
if (ConstantUInt *C = dyn_cast<ConstantUInt>(RHS))
|
||||||
|
|
Loading…
Reference in New Issue