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

Chris Lattner lattner at cs.uiuc.edu
Mon Oct 11 12:40:18 PDT 2004



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.265 -> 1.266
---
Log message:

Reenable the transform, turning X/-10 < 1 into X > -10



---
Diffs of the changes:  (+5 -5)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.265 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.266
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.265	Fri Oct  8 21:50:40 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Mon Oct 11 14:40:04 2004
@@ -2116,6 +2116,8 @@
           ConstantInt *Prod;
           bool ProdOV = MulWithOverflow(Prod, CI, DivRHS);
 
+          Instruction::BinaryOps Opcode = I.getOpcode();
+
           if (DivRHS->isNullValue()) {  // Don't hack on divide by zeros.
           } else if (LHSI->getType()->isUnsigned()) {  // udiv
             LoBound = Prod;
@@ -2152,15 +2154,13 @@
               HiBound = cast<ConstantInt>(ConstantExpr::getSub(Prod, DivRHS));
             }
 
-            /// FIXME: This code is disabled, because we do not compile the
-            /// divisor case < 0 correctly.  For example, this code is incorrect
-            /// in the case of "X/-10 < 1".
-            LoBound = 0;
+            // Dividing by a negate swaps the condition.
+            Opcode = SetCondInst::getSwappedCondition(Opcode);
           }
 
           if (LoBound) {
             Value *X = LHSI->getOperand(0);
-            switch (I.getOpcode()) {
+            switch (Opcode) {
             default: assert(0 && "Unhandled setcc opcode!");
             case Instruction::SetEQ:
               if (LoOverflow && HiOverflow)






More information about the llvm-commits mailing list