llvm / llvm/llvm-project

[X86][AVX512][AArch64][SVE] failed to lower non-pow2 load/store to pow2-upward masked load/store

Open
#205,006 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

backend:AArch64 backend:X86 llvm:SelectionDAG missed-optimization SVE
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://avx512.godbolt.org/z/nKd96ro36

define void @load_store_nonpow2(ptr %0, ptr %1) {
  %3 = load <15 x i32>, ptr %0
  store <15 x i32> %3, ptr %1
  ret void
}

define void @load_store_nonpow2_masked_pow2(ptr %0, ptr %1) {
  %3 =  tail call <16 x i32> @llvm.masked.load.v16i32.p0(ptr %0, <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 false>, <16 x i32> poison)
  tail call void @llvm.masked.store.v16i32.p0(<16 x i32> %3 , ptr %1, <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 false>)
  ret void
}
load_store_nonpow2:
        mov     eax, dword ptr [rdi + 56]
        mov     rcx, qword ptr [rdi + 48]
        vmovaps ymm0, ymmword ptr [rdi]
        vmovaps xmm1, xmmword ptr [rdi + 32]
        vmovaps xmmword ptr [rsi + 32], xmm1
        vmovaps ymmword ptr [rsi], ymm0
        mov     qword ptr [rsi + 48], rcx
        mov     dword ptr [rsi + 56], eax
        vzeroupper
        ret

load_store_nonpow2_masked_pow2:
        mov     ax, 32767
        kmovd   k1, eax
        vmovdqu32       zmm0 {k1} {z}, zmmword ptr [rdi]
        vmovdqu32       zmmword ptr [rsi] {k1}, zmm0
        vzeroupper
        ret
define void @load_store_nonpow2(ptr %0, ptr %1) {
  %3 = load <15 x i8>, ptr %0
  store <15 x i8> %3, ptr %1
  ret void
}

define void @load_store_nonpow2_masked_pow2(ptr %0, ptr %1) {
  %3 =  tail call <16 x i8> @llvm.masked.load.v16i8.p0(ptr %0, <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 false>, <16 x i8> poison)
  tail call void @llvm.masked.store.v16i8.p0(<16 x i8> %3 , ptr %1, <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 false>)
  ret void
}
load_store_nonpow2:
  vmovdqa xmm0, xmmword ptr [rdi]
  vpextrb byte ptr [rsi + 14], xmm0, 14
  vpextrw word ptr [rsi + 12], xmm0, 6
  vpextrd dword ptr [rsi + 8], xmm0, 2
  vmovq qword ptr [rsi], xmm0
  ret

load_store_nonpow2_masked_pow2:
  mov ax, 32767
  kmovd k1, eax
  vmovdqu8 xmm0 {k1} {z}, xmmword ptr [rdi]
  vmovdqu8 xmmword ptr [rsi] {k1}, xmm0
  ret

Backend should be able to transform the first function to be similar like the second function.

see https://github.com/llvm/llvm-project/pull/204893#issuecomment-4761828244

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Godbolt reproducer and compare the LLVM IR and generated assembly for the non-power-of-two load/store on x86 AVX512 and AArch64 SVE. Trace the backend lowering responsible for the first function and verify that its output becomes equivalent to the shown power-of-two masked load/store sequence.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.