Commit e1569b4
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 e0207b3 commit e1569b4
File tree
2 files changed
+101
-219
lines changed- llvm
- lib/Target/X86
- test/CodeGen/X86
2 files changed
+101
-219
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
35386 | 35387 | | |
35387 | 35388 | | |
35388 | 35389 | | |
35389 | | - | |
| 35390 | + | |
| 35391 | + | |
| 35392 | + | |
| 35393 | + | |
| 35394 | + | |
| 35395 | + | |
| 35396 | + | |
| 35397 | + | |
| 35398 | + | |
| 35399 | + | |
| 35400 | + | |
| 35401 | + | |
| 35402 | + | |
| 35403 | + | |
| 35404 | + | |
| 35405 | + | |
| 35406 | + | |
| 35407 | + | |
35390 | 35408 | | |
| 35409 | + | |
35391 | 35410 | | |
35392 | 35411 | | |
35393 | 35412 | | |
| |||
0 commit comments