Commit 4ced124
committed
[X86] Distribute Certain Bitwise Operations over SELECT
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
adjusting the `shouldFoldSelectWithIdentityConstant()` implementation
for the X86 backend. 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.1 parent 3572fd8 commit 4ced124
File tree
2 files changed
+125
-261
lines changed- llvm
- lib/Target/X86
- test/CodeGen/X86
2 files changed
+125
-261
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35552 | 35552 | | |
35553 | 35553 | | |
35554 | 35554 | | |
35555 | | - | |
| 35555 | + | |
| 35556 | + | |
| 35557 | + | |
| 35558 | + | |
| 35559 | + | |
| 35560 | + | |
| 35561 | + | |
| 35562 | + | |
| 35563 | + | |
| 35564 | + | |
| 35565 | + | |
| 35566 | + | |
| 35567 | + | |
| 35568 | + | |
| 35569 | + | |
| 35570 | + | |
| 35571 | + | |
| 35572 | + | |
| 35573 | + | |
| 35574 | + | |
| 35575 | + | |
35556 | 35576 | | |
| 35577 | + | |
35557 | 35578 | | |
35558 | 35579 | | |
35559 | 35580 | | |
| |||
0 commit comments