xref: /llvm-project/llvm/test/CodeGen/BPF/xadd_legal.ll (revision c5037db4acd95790a0ca5061c8fa79c5c291607e)
1; RUN: llc -mtriple=bpfel -mcpu=v1 < %s 2>&1 | FileCheck --check-prefix=CHECK-64 %s
2; RUN: llc -mtriple=bpfeb -mcpu=v1 < %s 2>&1 | FileCheck --check-prefix=CHECK-64 %s
3; RUN: llc -mtriple=bpfel -mcpu=v1 -mattr=+alu32 < %s 2>&1 | FileCheck --check-prefix=CHECK-32 %s
4; RUN: llc -mtriple=bpfeb -mcpu=v1 -mattr=+alu32 < %s 2>&1 | FileCheck --check-prefix=CHECK-32 %s
5
6; This file is generated with the source command and source
7; $ clang -target bpf -O2 -S -emit-llvm t.c
8; $ cat t.c
9; int test(int *ptr, unsigned long long a) {
10;    __sync_fetch_and_add(ptr, a);
11;    return *ptr;
12; }
13;
14; NOTE: passing unsigned long long as the second operand of __sync_fetch_and_add
15; could effectively create sub-register reference coming from indexing a full
16; register which could then exerceise hasLivingDefs inside BPFMIChecker.cpp.
17
18define dso_local i32 @test(ptr nocapture %ptr, i64 %a) {
19entry:
20  %conv = trunc i64 %a to i32
21  %0 = atomicrmw add ptr %ptr, i32 %conv seq_cst
22; CHECK-64: lock *(u32 *)(r1 + 0) += r2
23; CHECK-32: w2 = atomic_fetch_add((u32 *)(r1 + 0), w2)
24  %1 = load i32, ptr %ptr, align 4
25  ret i32 %1
26}
27