[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
Sat Aug 10 05:31:16 PDT 2024


Poseydon42 wrote:

I've rewritten the function to accomodate folding of all three patterns that were suggested. One of them had to be changed slightly since it was originally in non-cannonical form. Currently the following patterns are all folded to `ucmp(x, y)` or `scmp(x, y)`, depending on the signedness of the predicate in the condition of the select:
```
  (x < y) ? -1 : zext(x != y)
  (x > y) ? 1 : sext(x != y)
  (x >= y) ? zext(x != y) : -1
```
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.

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


More information about the llvm-commits mailing list