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

Chris Lattner lattner at cs.uiuc.edu
Sat Apr 10 17:02:35 PDT 2004


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.186 -> 1.187

---
Log message:

Implement InstCombine/add.ll:test20
Canonicalize add of sign bit constant into a xor



---
Diffs of the changes:  (+14 -4)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.186 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.187
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.186	Sat Apr 10 14:15:56 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sat Apr 10 17:01:55 2004
@@ -540,10 +540,20 @@
   bool Changed = SimplifyCommutative(I);
   Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
 
-  // X + 0 --> X
-  if (!I.getType()->isFloatingPoint() &&    // -0 + +0 = +0, so it's not a noop
-      RHS == Constant::getNullValue(I.getType()))
-    return ReplaceInstUsesWith(I, LHS);
+  if (Constant *RHSC = dyn_cast<Constant>(RHS)) {
+    // X + 0 --> X
+    if (!I.getType()->isFloatingPoint() && // -0 + +0 = +0, so it's not a noop
+        RHSC->isNullValue())
+      return ReplaceInstUsesWith(I, LHS);
+    
+    // X + (signbit) --> X ^ signbit
+    if (ConstantInt *CI = dyn_cast<ConstantInt>(RHSC)) {
+      unsigned NumBits = CI->getType()->getPrimitiveSize()*8;
+      uint64_t Val = CI->getRawValue() & (1ULL << NumBits)-1;
+      if (Val == (1ULL << NumBits-1))
+        return BinaryOperator::create(Instruction::Xor, LHS, RHS);
+    }
+  }
 
   // X + X --> X << 1
   if (I.getType()->isInteger())





More information about the llvm-commits mailing list