llvm / llvm/llvm-project

[X86] Missed Fold: `vgf2p8affineqb(x | C, M, imm8)` => `vgf2p8affineqb(x, M & ~C, (u8)vgf2p8affineqb(C, M, imm8))`

Open
#191,327 1 comment 0 reactions 0 assignees View on GitHub
backend:X86 missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Removing the same bit within each matrix's row acts like masking away the corresponding source bit. Using the following identity `(x & ~C) ^ C = x | C`, ORs by splatted 8-bit constants can be folded by masking the matrix and setting the immediate to be the affine transformation of the constant in the same manner (see #179606 & #191325).

Only works if the 64-bit matrix is the same for all lanes as they all use the same immediate.

```asm
setLowerBitRev_src:
por xmm0, xmmword ptr [rip + .LCPI0_0]
gf2p8affineqb xmm0, xmmword ptr [rip + .LCPI0_1], 0
ret
```

```asm
setLowerBitRev_tgt:
gf2p8affineqb xmm0, xmmword ptr [rip + .LCPI1_0], 240
ret
```

https://godbolt.org/z/ed7E45b31

Contributor guide

Open the contributing guide

Research direction

Start by comparing the identities and examples in #179606 and #191325, then reproduce the source and target assembly on the linked Godbolt example. The work is done when the compiler recognizes this vgf2p8affineqb transformation, including the condition that the 64-bit matrix is identical across lanes, and produces the target form.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.