[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Oct 6 08:08:36 PDT 2004



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.260 -> 1.261
---
Log message:

Instcombine: -(X sdiv C)  -> (X sdiv -C), tested by sub.ll:test16


---
Diffs of the changes:  (+8 -0)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.260 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.261
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.260	Wed Sep 29 16:21:14 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Wed Oct  6 10:08:25 2004
@@ -746,6 +746,14 @@
         return BinaryOperator::createAnd(Op0, NewNot);
       }
 
+      // -(X sdiv C)  -> (X sdiv -C)
+      if (Op1I->getOpcode() == Instruction::Div)
+        if (ConstantSInt *CSI = dyn_cast<ConstantSInt>(Op0))
+          if (CSI->getValue() == 0)
+            if (Constant *DivRHS = dyn_cast<Constant>(Op1I->getOperand(1)))
+              return BinaryOperator::createDiv(Op1I->getOperand(0), 
+                                               ConstantExpr::getNeg(DivRHS));
+
       // X - X*C --> X * (1-C)
       if (dyn_castFoldableMul(Op1I) == Op0) {
         Constant *CP1 =






More information about the llvm-commits mailing list