mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-01 00:33:09 +00:00
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
This commit is contained in:
parent
7706324512
commit
66331a4e33
@ -540,10 +540,20 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
|||||||
bool Changed = SimplifyCommutative(I);
|
bool Changed = SimplifyCommutative(I);
|
||||||
Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
|
Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
|
||||||
|
|
||||||
// X + 0 --> X
|
if (Constant *RHSC = dyn_cast<Constant>(RHS)) {
|
||||||
if (!I.getType()->isFloatingPoint() && // -0 + +0 = +0, so it's not a noop
|
// X + 0 --> X
|
||||||
RHS == Constant::getNullValue(I.getType()))
|
if (!I.getType()->isFloatingPoint() && // -0 + +0 = +0, so it's not a noop
|
||||||
return ReplaceInstUsesWith(I, LHS);
|
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
|
// X + X --> X << 1
|
||||||
if (I.getType()->isInteger())
|
if (I.getType()->isInteger())
|
||||||
|
Loading…
Reference in New Issue
Block a user