Skip to content

Commit

Permalink
[InstCombine] move comments closer to relevant code; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Aug 13, 2022
1 parent f7e98ef commit 763b312
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2908,30 +2908,34 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
SwappedForXor = true;
}

// A | ( A ^ B) -> A | B
// A | (~A ^ B) -> A | ~B
// (A & B) | (A ^ B)
// ~A | (A ^ B) -> ~(A & B)
// The swap above should always make Op0 the 'not' for the last case.
if (match(Op1, m_Xor(m_Value(A), m_Value(B)))) {
// A | (A ^ B) --> A | B
// B | (A ^ B) --> A | B
if (Op0 == A || Op0 == B)
return BinaryOperator::CreateOr(A, B);

// (A & B) | (A ^ B) --> A | B
// (B & A) | (A ^ B) --> A | B
if (match(Op0, m_And(m_Specific(A), m_Specific(B))) ||
match(Op0, m_And(m_Specific(B), m_Specific(A))))
return BinaryOperator::CreateOr(A, B);

// ~A | (A ^ B) --> ~(A & B)
// ~B | (A ^ B) --> ~(A & B)
// The swap above should always make Op0 the 'not'.
if ((Op0->hasOneUse() || Op1->hasOneUse()) &&
(match(Op0, m_Not(m_Specific(A))) || match(Op0, m_Not(m_Specific(B)))))
return BinaryOperator::CreateNot(Builder.CreateAnd(A, B));

// A | (~A ^ B) --> ~B | A
// B | (A ^ ~B) --> ~A | B
if (Op1->hasOneUse() && match(A, m_Not(m_Specific(Op0)))) {
Value *Not = Builder.CreateNot(B, B->getName() + ".not");
return BinaryOperator::CreateOr(Not, Op0);
Value *NotB = Builder.CreateNot(B, B->getName() + ".not");
return BinaryOperator::CreateOr(NotB, Op0);
}
if (Op1->hasOneUse() && match(B, m_Not(m_Specific(Op0)))) {
Value *Not = Builder.CreateNot(A, A->getName() + ".not");
return BinaryOperator::CreateOr(Not, Op0);
Value *NotA = Builder.CreateNot(A, A->getName() + ".not");
return BinaryOperator::CreateOr(NotA, Op0);
}
}

Expand Down

0 comments on commit 763b312

Please sign in to comment.