Instcombine X/-1 --> 0-X

llvm-svn: 13172
This commit is contained in:
Chris Lattner 2004-04-26 14:01:59 +00:00
parent e24003a261
commit e20c334e65
1 changed files with 5 additions and 1 deletions

View File

@ -849,11 +849,15 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
}
Instruction *InstCombiner::visitDiv(BinaryOperator &I) {
// div X, 1 == X
if (ConstantInt *RHS = dyn_cast<ConstantInt>(I.getOperand(1))) {
// div X, 1 == X
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))