llvm / llvm/llvm-project

parameter of type libstdc++ std::experimental::simd of 4 x u64 is passed by implicit pointer in clang 21

Open
#176,670 3 comments 0 reactions 0 assignees View on GitHub
ABI clang:codegen diverges-from:gcc libstdc++ regression:21
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following code uses libstdc++ experimental simd. These parameters are supposed to be passed by simd registers.

All the code is available at https://godbolt.org/z/rq3GvWj4W .

```c++
#include
#include
namespace stdx = std::experimental;

template
using simd_of = stdx::simd>;

using simd_t = simd_of;
using vector_t [[gnu::vector_size(sizeof(std::uint64_t) * 4)]] = std::uint64_t;

auto f(simd_t x) { return x; }
auto g(vector_t x) { return x; }

using simd_32x4_t = simd_of;
auto f32(simd_32x4_t x) { return x; }
```

Both clang++ 20 and g++ 15 (the latest release) generates the following assembly at `-O3 -march=x86-64-v3` as desired.

```asm
f(std::experimental::parallelism_v2::simd>):
retq

g(unsigned long vector[4]):
retq

f32(std::experimental::parallelism_v2::simd>):
retq
```

But clang++ 21 (and the latest clang++ trunk) pass the `simd of 4 x u64` parameter by implicit pointer. Interestingly, the wrapped `4 x u64` and `simd of 4 x u32` are both passed by value.

```asm
f(std::experimental::parallelism_v2::simd>):
push rbp
mov rbp, rsp
and rsp, -32
sub rsp, 32
mov rax, rdi
vmovaps ymm0, ymmword ptr [rbp + 16]
vmovaps ymmword ptr [rdi], ymm0
mov rsp, rbp
pop rbp
vzeroupper
ret

g(unsigned long vector[4]):
ret

f32(std::experimental::parallelism_v2::simd>):
ret
```

Contributor guide

Open the contributing guide

Research direction

Start with the Godbolt reproducer linked in the issue and compare clang++ 20, clang++ 21, and current trunk at -O3 -march=x86-64-v3. Trace why the 4 x uint64_t libstdc++ experimental::simd parameter is passed by implicit pointer while the vector and uint32_t cases are passed by value; done means clang matches the expected by-value behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.