Instcombine X/-1 --> 0-X
authorChris Lattner <sabre@nondot.org>
Mon, 26 Apr 2004 14:01:59 +0000 (14:01 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 26 Apr 2004 14:01:59 +0000 (14:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13172 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 52b861da15665b347a9a5a040d20314f7112afb6..e2607c0c1a89cad4e551b9c9d411c6969cdacc19 100644 (file)
@@ -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))