mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-05 19:29:54 +00:00
[InstCombine] use m_Neg() to reduce code; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315762 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
94aa10e94b
commit
bfa0442391
@ -1098,22 +1098,19 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
||||
return Shl;
|
||||
}
|
||||
|
||||
// -A + B --> B - A
|
||||
// -A + -B --> -(A + B)
|
||||
if (Value *LHSV = dyn_castNegVal(LHS)) {
|
||||
if (!isa<Constant>(RHS))
|
||||
if (Value *RHSV = dyn_castNegVal(RHS)) {
|
||||
Value *NewAdd = Builder.CreateAdd(LHSV, RHSV, "sum");
|
||||
return BinaryOperator::CreateNeg(NewAdd);
|
||||
}
|
||||
Value *A, *B;
|
||||
if (match(LHS, m_Neg(m_Value(A)))) {
|
||||
// -A + -B --> -(A + B)
|
||||
if (match(RHS, m_Neg(m_Value(B))))
|
||||
return BinaryOperator::CreateNeg(Builder.CreateAdd(A, B));
|
||||
|
||||
return BinaryOperator::CreateSub(RHS, LHSV);
|
||||
// -A + B --> B - A
|
||||
return BinaryOperator::CreateSub(RHS, A);
|
||||
}
|
||||
|
||||
// A + -B --> A - B
|
||||
if (!isa<Constant>(RHS))
|
||||
if (Value *V = dyn_castNegVal(RHS))
|
||||
return BinaryOperator::CreateSub(LHS, V);
|
||||
if (match(RHS, m_Neg(m_Value(B))))
|
||||
return BinaryOperator::CreateSub(LHS, B);
|
||||
|
||||
if (Value *V = checkForNegativeOperand(I, Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
@ -1247,7 +1244,6 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
||||
}
|
||||
}
|
||||
|
||||
Value *A, *B;
|
||||
// (add (xor A, B) (and A, B)) --> (or A, B)
|
||||
if (match(LHS, m_Xor(m_Value(A), m_Value(B))) &&
|
||||
match(RHS, m_c_And(m_Specific(A), m_Specific(B))))
|
||||
|
Loading…
Reference in New Issue
Block a user