summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-04-10 22:01:55 +0000
committerChris Lattner <sabre@nondot.org>2004-04-10 22:01:55 +0000
commitcf4a996cba567d90cbc29cffa0a9de76ddf6cc98 (patch)
treebc273470a93b2e1ca660b0f189ef6c9bc71798bd
parent825a00195d3f88f77db40d49925e637084950f20 (diff)
downloadbcm5719-llvm-cf4a996cba567d90cbc29cffa0a9de76ddf6cc98.tar.gz
bcm5719-llvm-cf4a996cba567d90cbc29cffa0a9de76ddf6cc98.zip
Implement InstCombine/add.ll:test20
Canonicalize add of sign bit constant into a xor llvm-svn: 12819
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 944b83c520a..23d0f5ffcc7 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -540,10 +540,20 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
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())
OpenPOWER on IntegriCloud