[PATCH] D150360: [InstCombine] Optimize compares with multiple selects as operands

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 25 01:32:08 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:6597
+        match(Op1, m_Select(m_Specific(Cond), m_Value(C), m_Value(D))) &&
+        Op0->hasOneUse() && Op1->hasOneUse()) {
+      // Check whether comparison of TrueValues can be simplified
----------------
tejas wrote:
> nikic wrote:
> > There are two ways the one-use checks could be relaxed:
> > 1. It should be fine to only require one-use on one of the selects, as we'll preserve the number of instructions in that case. I'm not entirely clear on profitability for that case -- I guess the fact that we're converting an arbitrary select into a logical and/or may make it generally beneficial?
> > 2. If both comparisons fold, we don't care about uses at all, as the result is a constant.
> > 
> > I personally think it would be okay to start with the code you have, but in that case we should at least add a TODO to note the possibility.
> Can we go with relaxing the condition for one-use on one of the selects? if at least it seems beneficial at this point?
Sure!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150360



More information about the llvm-commits mailing list