Move optimization to avoid redundant matching.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108140 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2010-07-12 13:34:22 +00:00
parent 0cc4ed1ca5
commit ad854f0764

View File

@ -1584,6 +1584,19 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
if ((match(A, m_Not(m_Specific(B))) &&
match(D, m_Not(m_Specific(C)))))
return BinaryOperator::CreateXor(C, B);
// ((A|B)&1)|(B&-2) -> (A&1) | B
if (match(A, m_Or(m_Value(V1), m_Specific(B))) ||
match(A, m_Or(m_Specific(B), m_Value(V1)))) {
Instruction *Ret = FoldOrWithConstants(I, Op1, V1, B, C);
if (Ret) return Ret;
}
// (B&-2)|((A|B)&1) -> (A&1) | B
if (match(B, m_Or(m_Specific(A), m_Value(V1))) ||
match(B, m_Or(m_Value(V1), m_Specific(A)))) {
Instruction *Ret = FoldOrWithConstants(I, Op0, A, V1, D);
if (Ret) return Ret;
}
}
// (X >> Z) | (Y >> Z) -> (X|Y) >> Z for all shifts.
@ -1599,19 +1612,6 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
}
}
// ((A|B)&1)|(B&-2) -> (A&1) | B
if (match(Op0, m_And(m_Or(m_Value(A), m_Value(B)), m_Value(C))) ||
match(Op0, m_And(m_Value(C), m_Or(m_Value(A), m_Value(B))))) {
Instruction *Ret = FoldOrWithConstants(I, Op1, A, B, C);
if (Ret) return Ret;
}
// (B&-2)|((A|B)&1) -> (A&1) | B
if (match(Op1, m_And(m_Or(m_Value(A), m_Value(B)), m_Value(C))) ||
match(Op1, m_And(m_Value(C), m_Or(m_Value(A), m_Value(B))))) {
Instruction *Ret = FoldOrWithConstants(I, Op0, A, B, C);
if (Ret) return Ret;
}
// (~A | ~B) == (~(A & B)) - De Morgan's Law
if (Value *Op0NotVal = dyn_castNotVal(Op0))
if (Value *Op1NotVal = dyn_castNotVal(Op1))