Skip to content

Commit f6fc3e2

Browse files
committed
[InstCombine] refactor matching code for logical ands; NFCI
Separating the matches makes it easier to enhance for commutative patterns.
1 parent 2c0d056 commit f6fc3e2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,16 +2847,18 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
28472847
return replaceOperand(SI, 0, A);
28482848
}
28492849

2850-
// (c && a) || (!c && b) --> sel c, a, b
2851-
// (!c && a) || (c && b) --> sel c, b, a
2852-
Value *C1, *C2;
2853-
if (match(CondVal, m_LogicalAnd(m_Value(C1), m_Value(A))) &&
2854-
match(TrueVal, m_One()) &&
2855-
match(FalseVal, m_LogicalAnd(m_Value(C2), m_Value(B)))) {
2856-
if (match(C2, m_Not(m_Specific(C1)))) // first case
2857-
return SelectInst::Create(C1, A, B);
2858-
else if (match(C1, m_Not(m_Specific(C2)))) // second case
2859-
return SelectInst::Create(C2, B, A);
2850+
if (match(TrueVal, m_One())) {
2851+
Value *C;
2852+
2853+
// (C && A) || (!C && B) --> sel C, A, B
2854+
if (match(FalseVal, m_LogicalAnd(m_Not(m_Value(C)), m_Value(B))) &&
2855+
match(CondVal, m_LogicalAnd(m_Specific(C), m_Value(A))))
2856+
return SelectInst::Create(C, A, B);
2857+
2858+
// (!C && A) || (C && B) --> sel C, B, A
2859+
if (match(CondVal, m_LogicalAnd(m_Not(m_Value(C)), m_Value(A))) &&
2860+
match(FalseVal, m_LogicalAnd(m_Specific(C), m_Value(B))))
2861+
return SelectInst::Create(C, B, A);
28602862
}
28612863
}
28622864

0 commit comments

Comments
 (0)