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

Chris Lattner lattner at cs.uiuc.edu
Thu Oct 2 10:12:14 PDT 2003


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.123 -> 1.124

---
Log message:

Implement InstCombine/add.ll:test17 & 18


---
Diffs of the changes:

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.123 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.124
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.123	Mon Sep 22 15:33:21 2003
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Thu Oct  2 10:11:26 2003
@@ -437,6 +437,22 @@
   if (Constant *C2 = dyn_castMaskingAnd(RHS))
     if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2))) return R;
 
+  if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
+    if (Instruction *ILHS = dyn_cast<Instruction>(LHS)) {
+      switch (ILHS->getOpcode()) {
+      case Instruction::Xor:
+        // ~X + C --> (C-1) - X
+        if (ConstantInt *XorRHS = dyn_cast<ConstantInt>(ILHS->getOperand(1)))
+          if (XorRHS->isAllOnesValue())
+            return BinaryOperator::create(Instruction::Sub,
+                                     *CRHS - *ConstantInt::get(I.getType(), 1),
+                                          ILHS->getOperand(0));
+        break;
+      default: break;
+      }
+    }
+  }
+
   return Changed ? &I : 0;
 }
 





More information about the llvm-commits mailing list