[llvm] BPF: Ensure __sync_fetch_and_add() always generate atomic_fetch_add insn (PR #101428)

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 24 22:00:53 PDT 2024


yonghong-song wrote:

> @yonghong-song this seems to be a breaking change for folks still targeting `v1` or `v2` instruction sets. LLVM generates an instruction that isn't available.

@brycekahle Yes. This is a deliberate choice. See upstream discussion in
https://lore.kernel.org/bpf/ZqqiQQWRnz7H93Hc@google.com/T/#mb68d67bc8f39e35a0c3db52468b9de59b79f021f

The following is the quote from the discussion from Alexei:

Right. We did it for backward compat. Older llvm was
completely wrong to generate xadd for __sync_fetch_and_add.
That was my hack from 10 years ago when xadd was all we had.
So we fixed that old llvm bug, but introduced another with all
good intentions.
Since proper atomic insns were introduced 3 years ago we should
remove this backward compat feature/bug from llvm.
The only breakage is for kernels older than 5.12.
I think that's an acceptable risk.

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


More information about the llvm-commits mailing list