aboutsummaryrefslogtreecommitdiff
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
commit83a2e6e4a1064677e66162837b019079a120b99e (patch)
tree25c9df679ed782d72d28f69b354f0a4e3b1dce50
parentdb05858ba10627be0b9fdfb5b3d377e0b1c629c4 (diff)
Instcombine X/-1 --> 0-X
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13172 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 52b861da15..e2607c0c1a 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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))