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

Chris Lattner sabre at nondot.org
Thu Jan 4 18:18:02 PST 2007



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.578 -> 1.579
---
Log message:

Compile X + ~X to -1.  This implements Instcombine/add.ll:test34



---
Diffs of the changes:  (+7 -1)

 InstructionCombining.cpp |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.578 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.579
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.578	Wed Jan  3 23:23:51 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Thu Jan  4 20:17:46 2007
@@ -1871,10 +1871,16 @@
   if (dyn_castFoldableMul(RHS, C2) == LHS)
     return BinaryOperator::createMul(LHS, AddOne(C2));
 
+  // X + ~X --> -1   since   ~X = -X-1
+  if (dyn_castNotVal(LHS) == RHS ||
+      dyn_castNotVal(RHS) == LHS)
+    return ReplaceInstUsesWith(I, ConstantInt::getAllOnesValue(I.getType()));
+  
 
   // (A & C1)+(B & C2) --> (A & C1)|(B & C2) iff C1&C2 == 0
   if (match(RHS, m_And(m_Value(), m_ConstantInt(C2))))
-    if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2))) return R;
+    if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2)))
+      return R;
 
   if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
     Value *X = 0;






More information about the llvm-commits mailing list