summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-04-26 14:01:59 +0000
committerChris Lattner <sabre@nondot.org>2004-04-26 14:01:59 +0000
commite20c334e6546a54e3e53fe54acac47e199eb0cd8 (patch)
treeb93490e6ea4b10d541c5bb0a6ce49bceaf8c5b2b /llvm/lib/Transforms
parente24003a26150be8f109f6e9ebbfd1955fb2edafd (diff)
downloadbcm5719-llvm-e20c334e6546a54e3e53fe54acac47e199eb0cd8.tar.gz
bcm5719-llvm-e20c334e6546a54e3e53fe54acac47e199eb0cd8.zip
Instcombine X/-1 --> 0-X
llvm-svn: 13172
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 52b861da156..e2607c0c1a8 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -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))
OpenPOWER on IntegriCloud