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

Chris Lattner lattner at cs.uiuc.edu
Tue Jul 6 02:02:01 PDT 2004


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.217 -> 1.218

---
Log message:

Implement InstCombine/sub.ll:test15:  X % -Y === X % Y

Also, remove X % -1 = 0, because it's not true for unsigneds, and the 
signed case is superceeded by this new handling.


---
Diffs of the changes:  (+9 -2)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.217 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.218
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.217	Fri Jul  2 19:26:11 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Tue Jul  6 02:01:22 2004
@@ -844,11 +844,18 @@
 
 
 Instruction *InstCombiner::visitRem(BinaryOperator &I) {
+  if (I.getType()->isSigned())
+    if (Value *RHSNeg = dyn_castNegVal(I.getOperand(1)))
+      if (RHSNeg != I.getOperand(1)) {           // Avoid problems with MININT
+        // X % -Y -> X % Y
+        AddUsesToWorkList(I);
+        I.setOperand(1, RHSNeg);
+        return &I;
+      }
+
   if (ConstantInt *RHS = dyn_cast<ConstantInt>(I.getOperand(1))) {
     if (RHS->equalsInt(1))  // X % 1 == 0
       return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
-    if (RHS->isAllOnesValue())  // X % -1 == 0
-      return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
 
     // Check to see if this is an unsigned remainder with an exact power of 2,
     // if so, convert to a bitwise and.





More information about the llvm-commits mailing list