[llvm] [InstCombine] Fold `(X==Z || Y==Z) ? (X==Z && Y==Z) : X==Y --> X==Y` (PR #108619)
Marina Taylor via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 09:05:20 PDT 2024
================
@@ -1406,6 +1406,46 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel,
return nullptr;
}
+/// Fold the following code sequence:
+/// \code
+/// %XEq = icmp eq i64 %X, %Z
+/// %YEq = icmp eq i64 %Y, %Z
+/// %either = select i1 %XEq, i1 true, i1 %YEq
+/// %both = select i1 %XEq, i1 %YEq, i1 false
+/// %cmp = icmp eq i64 %X, %Y
+/// %equal = select i1 %either, i1 %both, i1 %cmp
+/// \code
+///
+/// into:
+/// %equal = icmp eq i64 %X, %Y
+///
+/// Equivalently:
+/// (X==Z || Y==Z) ? (X==Z && Y==Z) : X==Y --> X==Y
+Instruction *InstCombinerImpl::foldSelectEqualityTest(SelectInst &Sel) {
+ Value *X, *Y, *Z, *XEq, *YEq;
+ Value *Either = Sel.getCondition(), *Both = Sel.getTrueValue(),
+ *Cmp = Sel.getFalseValue();
+
+ if (!match(Either, m_Select(m_Value(XEq), m_One(), m_Value(YEq))))
----------------
citymarina wrote:
Thanks, I didn't know about these.
https://github.com/llvm/llvm-project/pull/108619
More information about the llvm-commits
mailing list