llvm / llvm/llvm-project

[Analysis] `@llvm.pdep` can be transformed into squaring with `@llvm.clmul`, and vice versa

Open
#204,535 0 comments 0 reactions 0 assignees View on GitHub
llvm:codegen missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`pdep` with an alternating bit pattern like `0b01010101...` is used to perform bitwise interleaving. See https://stackoverflow.com/a/79962549/5740428

On platforms where there exists `clmul` but no `pdep` (e.g. RISC-V) or x86_64 CPUs with the PCLMUL extensions but no BMI2, it is beneficial to transform `pdep` into `clmul` if such a mask is detected.

That is, `pdep(x, 0b10101010...) -> clmul(x, x)`.

The inverse is also possible and potentially beneficial because on x86_64, CLMUL is done through vector registers, so there is a bit of fluff just to get things set up and extract the result in the case of scalar operations. That is, `clmul(x, x) -> pdep(x, 0b1010101010...)`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.