Commit c6cb302
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
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.1 parent 733d9d4 commit c6cb302
File tree
3 files changed
+118
-219
lines changed- llvm
- lib/Target/X86
- test/CodeGen/X86
3 files changed
+118
-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 | | |
| |||
35385 | 35386 | | |
35386 | 35387 | | |
35387 | 35388 | | |
| 35389 | + | |
| 35390 | + | |
| 35391 | + | |
| 35392 | + | |
| 35393 | + | |
| 35394 | + | |
| 35395 | + | |
| 35396 | + | |
35388 | 35397 | | |
35389 | 35398 | | |
35390 | 35399 | | |
35391 | 35400 | | |
35392 | 35401 | | |
35393 | 35402 | | |
35394 | | - | |
| 35403 | + | |
35395 | 35404 | | |
35396 | 35405 | | |
35397 | 35406 | | |
35398 | 35407 | | |
35399 | 35408 | | |
| 35409 | + | |
| 35410 | + | |
| 35411 | + | |
| 35412 | + | |
| 35413 | + | |
| 35414 | + | |
| 35415 | + | |
| 35416 | + | |
| 35417 | + | |
| 35418 | + | |
| 35419 | + | |
| 35420 | + | |
| 35421 | + | |
| 35422 | + | |
| 35423 | + | |
| 35424 | + | |
| 35425 | + | |
| 35426 | + | |
| 35427 | + | |
| 35428 | + | |
| 35429 | + | |
| 35430 | + | |
35400 | 35431 | | |
35401 | 35432 | | |
35402 | 35433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1463 | 1463 | | |
1464 | 1464 | | |
1465 | 1465 | | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
1466 | 1471 | | |
1467 | 1472 | | |
1468 | 1473 | | |
| |||
0 commit comments