[llvm] [InstCombine] Fold `(x < y) ? -1 : zext(x != y)` into `u/scmp(x,y)` (PR #101049)

Volodymyr Vasylkun via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 11 13:06:29 PDT 2024


Poseydon42 wrote:

> > > There's one test that existed before this PR that ended up regressing after I've updated the check lines, it's located in `Transforms/PhaseOrdering/partialord-ule.ll`. One of the selects in that test is folded to `ucmp`, but this then prohibits other optimizations functioning that would've worked on "raw" select. I'm curious to hear any suggestions about how this can be fixed. I can only think of somehow checking whether not folding to ucmp would be more beneficial than doing so, but I can't imagine that being a good solution as it would require running the whole pipeline (or at least an iteration of InstCombine) on two different versions of IR.
> > 
> > 
> > We need to implement any missing folds before doing the canonicalization. In this case, what is missing is basically https://alive2.llvm.org/ce/z/tz24gi if we view this independently of ucmp/scmp. (If we consider them together, then this would be a variant of ucmp/scmp -> icmp.)
> 
> You might start by creating a new decomposed select matcher that also matches `{s,u}cmp` i.e `m_SelectWithCmp(CmpLHS, CmpRHS, CmpPred, TrueArm, FalseArm)` and trying to replace existing uses of `m_Select` with the generalized matcher.

I don't think I quite understand your approach, can you elaborate a bit more please?

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


More information about the llvm-commits mailing list