[llvm] [BPF] Use FETCH atomic instruction for monotonic atomicrmw when the result is used (PR #210371)

Denis Mingulov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 23:32:33 PDT 2026


mingulov wrote:

I originally encountered the same issue in a real Rust eBPF build through bpf-linker, which led me to this LLVM issue.

@yonghong-song I checked the reproducer from [#210280](https://github.com/llvm/llvm-project/issues/210280). The example there (https://godbolt.org/z/Gsje6xbjn) already uses current llc trunk with `-mtriple=bpf -mcpu=v3`:

```llvm
; __atomic_fetch_add(&x, 7, __ATOMIC_RELAXED)
define i64 @test(ptr %p) {
entry:
  %old = atomicrmw add ptr %p, i64 7 monotonic, align 8
  ret i64 %old
}
```

It produces with and without `-mcpu=v3`:

```
r0 = 7
lock *(u64 *)(r1 + 0) += r0
exit
```

So it updates memory, but r0 still contains the addend (7) - not the previous value.

Could you please take another look at the v3 case?

https://github.com/llvm/llvm-project/pull/210371


More information about the llvm-commits mailing list