llvm.org GIT mirror llvm / 38f7f66
Move "A | ~(A & ?) -> -1" from InstCombine to InstructionSimplify. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126082 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 9 years ago
2 changed file(s) with 18 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
11591159 if (match(Op1, m_And(m_Value(A), m_Value(B))) &&
11601160 (A == Op0 || B == Op0))
11611161 return Op0;
1162
1163 // ~(A & ?) | A = -1
1164 if (match(Op0, m_Not(m_And(m_Value(A), m_Value(B)))) &&
1165 (A == Op1 || B == Op1))
1166 return Constant::getAllOnesValue(Op1->getType());
1167
1168 // A | ~(A & ?) = -1
1169 if (match(Op1, m_Not(m_And(m_Value(A), m_Value(B)))) &&
1170 (A == Op0 || B == Op0))
1171 return Constant::getAllOnesValue(Op0->getType());
11621172
11631173 // Try some generic simplifications for associative operations.
11641174 if (Value *V = SimplifyAssociativeBinOp(Instruction::Or, Op0, Op1, TD, DT,
19181918
19191919 // A | ~(A | B) -> A | ~B
19201920 // A | ~(A ^ B) -> A | ~B
1921 // A | ~(A & B) -> -1
19221921 if (match(Op1, m_Not(m_Value(A))))
19231922 if (BinaryOperator *B = dyn_cast(A))
1924 if (Op0 == B->getOperand(0) || Op0 == B->getOperand(1))
1925 switch (B->getOpcode()) {
1926 default: break;
1927 case Instruction::Or:
1928 case Instruction::Xor:
1929 if (Op1->hasOneUse()) {
1930 Value *NotOp = Op0 == B->getOperand(0) ? B->getOperand(1) :
1931 B->getOperand(0);
1932 Value *Not = Builder->CreateNot(NotOp, NotOp->getName()+".not");
1933 return BinaryOperator::CreateOr(Not, Op0);
1934 }
1935 break;
1936 case Instruction::And:
1937 return ReplaceInstUsesWith(I, Constant::getAllOnesValue(I.getType()));
1938 }
1923 if ((Op0 == B->getOperand(0) || Op0 == B->getOperand(1)) &&
1924 Op1->hasOneUse() && (B->getOpcode() == Instruction::Or ||
1925 B->getOpcode() == Instruction::Xor)) {
1926 Value *NotOp = Op0 == B->getOperand(0) ? B->getOperand(1) :
1927 B->getOperand(0);
1928 Value *Not = Builder->CreateNot(NotOp, NotOp->getName()+".not");
1929 return BinaryOperator::CreateOr(Not, Op0);
1930 }
19391931
19401932 if (ICmpInst *RHS = dyn_cast(I.getOperand(1)))
19411933 if (ICmpInst *LHS = dyn_cast(I.getOperand(0)))