[PATCH] D158983: [InstCombine] Fold two select patterns into or-and

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 19:29:23 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:3093
+  // select (c & ~b), a, b -> select b, true, (select c, a, false)
+  if (match(CondVal, m_c_And(m_Value(C), m_Not(m_Specific(FalseVal)))) &&
+      CondVal->hasOneUse()) {
----------------
nikic wrote:
> goldstein.w.n wrote:
> > Instead of matching `m_Not` imo should match `m_Specific` and then check `isFreeToInvert` and generate `CreateNot` if that is the case.
> I don't get what you're suggesting here. isFreeToInvert doesn't tell you how inverted values are related, which is important here. (We need ~b and b, just being invertible is not enough.)
err doesn't work for the FalseVal one, but for the true case you can do:
`match(CondVal, m_c_Or(m_Specific(TrueVal), m_Value(C)) && CondVal->hasOneUse() && IsFreeToInvert(C) { C = Builder.CreateNot(C); ...}`. That gets more patterns.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158983/new/

https://reviews.llvm.org/D158983



More information about the llvm-commits mailing list