diff options
author | Chris Lattner <sabre@nondot.org> | 2004-04-10 22:01:55 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-04-10 22:01:55 +0000 |
commit | 66331a4e3312af6cc07b8c583565cc53d5b1516a (patch) | |
tree | aec85846d16ebe6516d91644d2ab04f7f3a54108 /lib | |
parent | 770632451273658c49777392d4f8972a9a4be0cd (diff) | |
download | external_llvm-66331a4e3312af6cc07b8c583565cc53d5b1516a.zip external_llvm-66331a4e3312af6cc07b8c583565cc53d5b1516a.tar.gz external_llvm-66331a4e3312af6cc07b8c583565cc53d5b1516a.tar.bz2 |
Implement InstCombine/add.ll:test20
Canonicalize add of sign bit constant into a xor
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12819 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 944b83c..23d0f5f 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/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()) |