mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-27 14:24:40 +00:00
InstCombine: Combine (add (and %a, %b) (or %a, %b)) to (add %a, %b)
What follows bellow is a correctness proof of the transform using CVC3. $ < t.cvc A, B : BITVECTOR(32); QUERY BVPLUS(32, A & B, A | B) = BVPLUS(32, A, B); $ cvc3 < t.cvc Valid. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215400 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1240,7 +1240,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for (x & y) + (x ^ y)
|
||||
// (add (xor A, B) (and A, B)) --> (or A, B)
|
||||
{
|
||||
Value *A = nullptr, *B = nullptr;
|
||||
if (match(RHS, m_Xor(m_Value(A), m_Value(B))) &&
|
||||
@ -1254,6 +1254,28 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
||||
return BinaryOperator::CreateOr(A, B);
|
||||
}
|
||||
|
||||
// (add (or A, B) (and A, B)) --> (add A, B)
|
||||
{
|
||||
Value *A = nullptr, *B = nullptr;
|
||||
if (match(RHS, m_Or(m_Value(A), m_Value(B))) &&
|
||||
(match(LHS, m_And(m_Specific(A), m_Specific(B))) ||
|
||||
match(LHS, m_And(m_Specific(B), m_Specific(A))))) {
|
||||
auto *New = BinaryOperator::CreateAdd(A, B);
|
||||
New->setHasNoSignedWrap(I.hasNoSignedWrap());
|
||||
New->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());
|
||||
return New;
|
||||
}
|
||||
|
||||
if (match(LHS, m_Or(m_Value(A), m_Value(B))) &&
|
||||
(match(RHS, m_And(m_Specific(A), m_Specific(B))) ||
|
||||
match(RHS, m_And(m_Specific(B), m_Specific(A))))) {
|
||||
auto *New = BinaryOperator::CreateAdd(A, B);
|
||||
New->setHasNoSignedWrap(I.hasNoSignedWrap());
|
||||
New->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());
|
||||
return New;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(jingyue): Consider WillNotOverflowSignedAdd and
|
||||
// WillNotOverflowUnsignedAdd to reduce the number of invocations of
|
||||
// computeKnownBits.
|
||||
|
Reference in New Issue
Block a user