llvm / llvm/llvm-project

bpf __builtin_memcpy from large aligned global spills unnecessarily

Open
#164,792 5 comments 0 reactions 0 assignees View on GitHub
backend:BPF llvm:codegen regression:20
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```c
int meow[512 / sizeof(int)];

void cpy(char *dest)
{
__builtin_memcpy(dest, meow, 512);
}
```

https://godbolt.org/z/9czYacMfT

Compiles with LLVM 19, Fails with this error on >= 20:

```
:3:6: error: Looks like the BPF stack limit is exceeded. Please move large on stack variables into BPF per-cpu array map. For non-kernel uses, the stack can be increased using -mllvm -bpf-stack-size.
3 | void cpy(char *dest)
| ^
:3:6: note: could not determine the original source location for example.c:0:0
:3:6: note: could not determine the original source location for example.c:0:0
```

Reducing the memcpy size to 40 or similar reveals that the code now spills to stack, for seemingly no reason:

```
cpy:
r3 = meow ll
[...]
w2 = *(u32 *)(r3 + 8)
*(u64 *)(r10 - 24) = r2
*(u8 *)(r1 + 8) = w2
w2 = *(u32 *)(r3 + 4)
*(u64 *)(r10 - 16) = r2
*(u8 *)(r1 + 4) = w2
w3 = *(u32 *)(r3 + 0)
*(u64 *)(r10 - 8) = r3
*(u8 *)(r1 + 0) = w3
[...]
```

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.