[llvm] [InstCombine] Select of Symmetric Selects (PR #99245)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 23:52:56 PDT 2024


================
@@ -3012,6 +3012,28 @@ struct DecomposedSelect {
 };
 } // namespace
 
+/// Folds patterns like:
+///   select c2 (select c1 a b) (select c1 b a)
+/// into:
+///   select (xor c1 c2) b a
+static Instruction *
+foldSelectOfSymmetricSelect(SelectInst &OuterSelVal,
+                            InstCombiner::BuilderTy &Builder) {
+
+  DecomposedSelect OuterSel, InnerSel;
+  if (!match(&OuterSelVal, m_Select(m_Value(OuterSel.Cond),
+                                    m_Select(m_Value(InnerSel.Cond),
+                                             m_Value(InnerSel.TrueVal),
+                                             m_Value(InnerSel.FalseVal)),
+                                    m_Select(m_Deferred(InnerSel.Cond),
+                                             m_Deferred(InnerSel.FalseVal),
+                                             m_Deferred(InnerSel.TrueVal)))))
----------------
goldsteinn wrote:

Any value in handling `select c2 (select c1 a b), (select ~c1, a, b)` with `isKnownInversion`?

https://github.com/llvm/llvm-project/pull/99245


More information about the llvm-commits mailing list