InstCombine: Propagate exact for (sdiv -X, C) -> (sdiv X, -C)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222623 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer
2014-11-22 20:00:34 +00:00
parent 53a43d38df
commit 91349eecb0
2 changed files with 15 additions and 4 deletions

View File

@@ -1082,10 +1082,12 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
return new ZExtInst(Builder->CreateICmpEQ(Op0, Op1), I.getType());
// -X/C --> X/-C provided the negation doesn't overflow.
if (SubOperator *Sub = dyn_cast<SubOperator>(Op0))
if (match(Sub->getOperand(0), m_Zero()) && Sub->hasNoSignedWrap())
return BinaryOperator::CreateSDiv(Sub->getOperand(1),
ConstantExpr::getNeg(RHS));
Value *X;
if (match(Op0, m_NSWSub(m_Zero(), m_Value(X)))) {
auto *BO = BinaryOperator::CreateSDiv(X, ConstantExpr::getNeg(RHS));
BO->setIsExact(I.isExact());
return BO;
}
}
// If the sign bits of both operands are zero (i.e. we can prove they are