Commit b715849
Automerge: [X86] Distribute Certain Bitwise Operations over SELECT (#136555)
InstCombine canonicalizes `(select P (and X (- X)) X)` to
`(and (select P (- X) umax) X)`. This is counterproductive for the X86
backend when BMI is available because we can encode `(and X (- X))`
using the `BLSI` instruction. A similar situation arises if we have
`(select P (and X (sub X 1)) X)` (prevents use of `BLSR` instruction) or
`(select P (xor X (sub X 1)) X)` (prevents use of `BLSMSK` instruction).
Trigger the inverse transformation in the X86 backend if BMI is
available and we can use the mentioned BMI instructions. This is done by
overriding the appropriate `shouldFoldSelectWithIdentityConstant()`
overload. In this way, we get `(select P (and X (- X)) X)` again, which
enables the use of `BLSI` (similar for the other cases described above).
Alive proofs: https://alive2.llvm.org/ce/z/MT_pKi
Fixes #131587, fixes #133848.
---------
Co-authored-by: Simon Pilgrim <[email protected]>File tree
2 files changed
+892
-1
lines changed- llvm
- lib/Target/X86
- test/CodeGen/X86
2 files changed
+892
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35618 | 35618 | | |
35619 | 35619 | | |
35620 | 35620 | | |
35621 | | - | |
| 35621 | + | |
| 35622 | + | |
| 35623 | + | |
| 35624 | + | |
| 35625 | + | |
| 35626 | + | |
| 35627 | + | |
| 35628 | + | |
| 35629 | + | |
| 35630 | + | |
| 35631 | + | |
| 35632 | + | |
| 35633 | + | |
| 35634 | + | |
| 35635 | + | |
| 35636 | + | |
| 35637 | + | |
| 35638 | + | |
| 35639 | + | |
| 35640 | + | |
| 35641 | + | |
35622 | 35642 | | |
| 35643 | + | |
35623 | 35644 | | |
35624 | 35645 | | |
35625 | 35646 | | |
| |||
0 commit comments