Issue 241962
Summary [X86] zmm byte rotate by 24 lowered to vprold instead of vpshufb
Labels new issue
Assignees
Reporter timurgol007
    In a round loop from godbolt a 32-bit rotate by 24 is written as `_mm512_shuffle_epi8` with a constant mask from a global array. Since https://github.com/llvm/llvm-project/pull/192775 the mask load is constant-folded, the `pshufb` becomes a byte-rotate shufflevector, and the X86 backend lowers it to `vprold $24` instead of `vpshufb`.

Usually that's the right choice because `vprold` needs no mask (no extra vector register to hold it, no load, and no bytes of constant data). So it has lower register pressure and smaller code overall. It only hurts when the rotate unit is already the bottleneck.

That's the case here. On sapphirerapids, zmm `vprold` runs only on port 0, while `vpshufb` runs on port 5. The round already has three other `vprold` and two GFNI instructions on port 0, so the extra rotate makes port 0 the bottleneck. llvm-mca (-mcpu=sapphirerapids) shows the block's reciprocal throughput going from 20 to 24 cycles.

godbolt clang 22.1.0 vs 23.1.0: https://godbolt.org/z/G38WWbr9c

|              | `vpshufb` | `vprold $24` | Block RThroughput | port 0 / port 5 |
|--------------|-----------|--------------|-------------------|-----------------|
| clang 22.1.0 | 4         | 0            | 20.0              | 24 / 20 |
| clang 23.1.0 | 0         | 4            | 24.0              | 28 / 16 |

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to