Instcombine: -(X sdiv C) -> (X sdiv -C), tested by sub.ll:test16

llvm-svn: 16769
This commit is contained in:
Chris Lattner 2004-10-06 15:08:25 +00:00
parent 52783ab1d8
commit 0aee4b7947
1 changed files with 8 additions and 0 deletions

View File

@ -746,6 +746,14 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
return BinaryOperator::createAnd(Op0, NewNot);
}
// -(X sdiv C) -> (X sdiv -C)
if (Op1I->getOpcode() == Instruction::Div)
if (ConstantSInt *CSI = dyn_cast<ConstantSInt>(Op0))
if (CSI->getValue() == 0)
if (Constant *DivRHS = dyn_cast<Constant>(Op1I->getOperand(1)))
return BinaryOperator::createDiv(Op1I->getOperand(0),
ConstantExpr::getNeg(DivRHS));
// X - X*C --> X * (1-C)
if (dyn_castFoldableMul(Op1I) == Op0) {
Constant *CP1 =