[llvm] f6fc3e2 - [InstCombine] refactor matching code for logical ands; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 21 08:28:51 PDT 2022
Author: Sanjay Patel
Date: 2022-10-21T11:28:38-04:00
New Revision: f6fc3e23b95ef0045d4453bd3fdddd765f29099b
URL: https://github.com/llvm/llvm-project/commit/f6fc3e23b95ef0045d4453bd3fdddd765f29099b
DIFF: https://github.com/llvm/llvm-project/commit/f6fc3e23b95ef0045d4453bd3fdddd765f29099b.diff
LOG: [InstCombine] refactor matching code for logical ands; NFCI
Separating the matches makes it easier
to enhance for commutative patterns.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 756bece653f9..0f564830149e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -2847,16 +2847,18 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
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);
}
}
More information about the llvm-commits
mailing list