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

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 26 12:06:27 PDT 2024


eddyz87 wrote:

Hi @brycekahle ,

Could you please elaborate a bit on issues with inline assembly and `clang` + `llc`?
A simple test appears to work:

```llvm
$ cat test3.c
void foo(unsigned long *p, unsigned long v)
{
  asm volatile("lock *(u64 *)(%[p] + 0) += %[v];" :: [p]"r"(p), [v]"r"(v));
}

$ clang -mcpu=v1 -O2 --target=bpf -S -emit-llvm -o - test3.c | llc -march=bpf -mcpu=v1 -o - -filetype=asm
	.text
	.file	"test3.c"
	.globl	foo                             # -- Begin function foo
	.p2align	3
	.type	foo, at function
foo:                                    # @foo
.Lfoo$local:
	.type	.Lfoo$local, at function
# %bb.0:
	#APP
	lock *(u64 *)(r1 + 0) += r2

	#NO_APP
	exit
.Lfunc_end0:
	.size	foo, .Lfunc_end0-foo
	.size	.Lfoo$local, .Lfunc_end0-foo
                                        # -- End function
```

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


More information about the llvm-commits mailing list