Move "A | ~(A & ?) -> -1" from InstCombine to InstructionSimplify.

llvm-svn: 126082
This commit is contained in:
Benjamin Kramer 2011-02-20 15:20:01 +00:00
parent d5d7f37beb
commit 5b7a4e0195
2 changed files with 18 additions and 16 deletions

View File

@ -1161,6 +1161,16 @@ static Value *SimplifyOrInst(Value *Op0, Value *Op1, const TargetData *TD,
(A == Op0 || B == Op0)) (A == Op0 || B == Op0))
return Op0; return Op0;
// ~(A & ?) | A = -1
if (match(Op0, m_Not(m_And(m_Value(A), m_Value(B)))) &&
(A == Op1 || B == Op1))
return Constant::getAllOnesValue(Op1->getType());
// A | ~(A & ?) = -1
if (match(Op1, m_Not(m_And(m_Value(A), m_Value(B)))) &&
(A == Op0 || B == Op0))
return Constant::getAllOnesValue(Op0->getType());
// Try some generic simplifications for associative operations. // Try some generic simplifications for associative operations.
if (Value *V = SimplifyAssociativeBinOp(Instruction::Or, Op0, Op1, TD, DT, if (Value *V = SimplifyAssociativeBinOp(Instruction::Or, Op0, Op1, TD, DT,
MaxRecurse)) MaxRecurse))

View File

@ -1919,24 +1919,16 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
// A | ~(A | B) -> A | ~B // A | ~(A | B) -> A | ~B
// A | ~(A ^ B) -> A | ~B // A | ~(A ^ B) -> A | ~B
// A | ~(A & B) -> -1
if (match(Op1, m_Not(m_Value(A)))) if (match(Op1, m_Not(m_Value(A))))
if (BinaryOperator *B = dyn_cast<BinaryOperator>(A)) if (BinaryOperator *B = dyn_cast<BinaryOperator>(A))
if (Op0 == B->getOperand(0) || Op0 == B->getOperand(1)) if ((Op0 == B->getOperand(0) || Op0 == B->getOperand(1)) &&
switch (B->getOpcode()) { Op1->hasOneUse() && (B->getOpcode() == Instruction::Or ||
default: break; B->getOpcode() == Instruction::Xor)) {
case Instruction::Or: Value *NotOp = Op0 == B->getOperand(0) ? B->getOperand(1) :
case Instruction::Xor: B->getOperand(0);
if (Op1->hasOneUse()) { Value *Not = Builder->CreateNot(NotOp, NotOp->getName()+".not");
Value *NotOp = Op0 == B->getOperand(0) ? B->getOperand(1) : return BinaryOperator::CreateOr(Not, Op0);
B->getOperand(0); }
Value *Not = Builder->CreateNot(NotOp, NotOp->getName()+".not");
return BinaryOperator::CreateOr(Not, Op0);
}
break;
case Instruction::And:
return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
}
if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1))) if (ICmpInst *RHS = dyn_cast<ICmpInst>(I.getOperand(1)))
if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0))) if (ICmpInst *LHS = dyn_cast<ICmpInst>(I.getOperand(0)))