aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-08-12 16:37:02 +0000
committerDan Gohman <gohman@apple.com>2009-08-12 16:37:02 +0000
commit9ca9daad2175cd57776e7de7fb6f78eb96fc7445 (patch)
tree944d50d12cbc814a179260471312972297a06d3e /lib/Transforms/Scalar/InstructionCombining.cpp
parentfa94b948d9a0aaaad98901815e56b676803ad259 (diff)
Transform -X/C to X/-C, implementing a README.txt entry.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78812 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 669ef2d516..b875420e5b 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3077,6 +3077,14 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
RHS->getValue().exactLogBase2());
return BinaryOperator::CreateAShr(Op0, ShAmt, I.getName());
}
+
+ // -X/C --> X/-C provided the negation doesn't overflow.
+ if (SubOperator *Sub = dyn_cast<SubOperator>(Op0))
+ if (isa<Constant>(Sub->getOperand(0)) &&
+ cast<Constant>(Sub->getOperand(0))->isNullValue() &&
+ Sub->hasNoSignedOverflow())
+ return BinaryOperator::CreateSDiv(Sub->getOperand(1),
+ ConstantExpr::getNeg(RHS));
}
// If the sign bits of both operands are zero (i.e. we can prove they are