InstCombine: Optimize x/INT_MIN to x==INT_MIN

The result of x/INT_MIN is either 0 or 1, we can just use an icmp
instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212167 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer
2014-07-02 06:42:13 +00:00
parent 5f8c844dc8
commit 3e01ae9f8f
2 changed files with 10 additions and 6 deletions

View File

@@ -993,6 +993,10 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
}
if (Constant *RHS = dyn_cast<Constant>(Op1)) {
// X/INT_MIN -> X == INT_MIN
if (RHS->isMinSignedValue())
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())