return replaceOperand(SI, 0, A);
}
- // (c && a) || (!c && b) --> sel c, a, b
- // (!c && a) || (c && b) --> sel c, b, a
- Value *C1, *C2;
- if (match(CondVal, m_LogicalAnd(m_Value(C1), m_Value(A))) &&
- match(TrueVal, m_One()) &&
- match(FalseVal, m_LogicalAnd(m_Value(C2), m_Value(B)))) {
- if (match(C2, m_Not(m_Specific(C1)))) // first case
- return SelectInst::Create(C1, A, B);
- else if (match(C1, m_Not(m_Specific(C2)))) // second case
- return SelectInst::Create(C2, B, A);
+ if (match(TrueVal, m_One())) {
+ Value *C;
+
+ // (C && A) || (!C && B) --> sel C, A, B
+ if (match(FalseVal, m_LogicalAnd(m_Not(m_Value(C)), m_Value(B))) &&
+ match(CondVal, m_LogicalAnd(m_Specific(C), m_Value(A))))
+ return SelectInst::Create(C, A, B);
+
+ // (!C && A) || (C && B) --> sel C, B, A
+ if (match(CondVal, m_LogicalAnd(m_Not(m_Value(C)), m_Value(A))) &&
+ match(FalseVal, m_LogicalAnd(m_Specific(C), m_Value(B))))
+ return SelectInst::Create(C, B, A);
}
}