Implement InstCombine/add.ll:test17 & 18

llvm-svn: 8817
This commit is contained in:
Chris Lattner 2003-10-02 15:11:26 +00:00
parent d15f273512
commit b9cde76e60
1 changed files with 16 additions and 0 deletions

View File

@ -437,6 +437,22 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
if (Constant *C2 = dyn_castMaskingAnd(RHS))
if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2))) return R;
if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
if (Instruction *ILHS = dyn_cast<Instruction>(LHS)) {
switch (ILHS->getOpcode()) {
case Instruction::Xor:
// ~X + C --> (C-1) - X
if (ConstantInt *XorRHS = dyn_cast<ConstantInt>(ILHS->getOperand(1)))
if (XorRHS->isAllOnesValue())
return BinaryOperator::create(Instruction::Sub,
*CRHS - *ConstantInt::get(I.getType(), 1),
ILHS->getOperand(0));
break;
default: break;
}
}
}
return Changed ? &I : 0;
}