llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[X86] Missed Fold: `vgf2p8affineqb(x, m1) ^ vgf2p8affineqb(x, m2)` => `vgf2p8affineqb(x, m1 ^ m2)`

Open WalterKruger opened this issue 10 months ago • 3 comments

The matrix in vgf2p8affineqb can be interpreted as determining which bits of the input are XORed together for each position. Following from that, XORing two affines of the same input can be folded by XORing both their matrices and immediates together into a single vgf2p8affineqb instruction.

src:
        vgf2p8affineqb  xmm1, xmm0, xmm1, 0
        vgf2p8affineqb  xmm0, xmm0, xmm2, 0
        vpxor   xmm0, xmm0, xmm1
        ret
tgt:
        vpxor   xmm1, xmm2, xmm1
        vgf2p8affineqb  xmm0, xmm0, xmm1, 0
        ret

https://godbolt.org/z/jK8eWPhb7

This can also be applied to vgf2p8affineqb(x, m) ^ x, as the standalone x can be interpreted as being affined by the neutral matrix.

WalterKruger avatar Jan 30 '26 00:01 WalterKruger

@llvm/issue-subscribers-backend-x86

Author: Walter (WalterKruger)

The matrix in `vgf2p8affineqb` can be interpreted as determining which bits of the input are XORed together for each position. Following from that, XORing two affines of the same input can be folded by XORing both their matrices and immediates together into a single `vgf2p8affineqb` instruction.
src:
        vgf2p8affineqb  xmm1, xmm0, xmm1, 0
        vgf2p8affineqb  xmm0, xmm0, xmm2, 0
        vpxor   xmm0, xmm0, xmm1
        ret
tgt:
        vpxor   xmm1, xmm2, xmm1
        vgf2p8affineqb  xmm0, xmm0, xmm1, 0
        ret

https://godbolt.org/z/jK8eWPhb7

This can also be applied to vgf2p8affineqb(x, m) ^ x, as the standalone x can be interpreted as being affined by the neutral matrix.

llvmbot avatar Jan 30 '26 00:01 llvmbot

@WalterKruger can i work on this ??

bala-bhargav avatar Feb 03 '26 13:02 bala-bhargav

Fixed by #179900

WalterKruger avatar Mar 02 '26 04:03 WalterKruger