xref: /llvm-project/clang/test/CodeGen/PowerPC/quadword-atomics.c (revision 5fdd094837c6d8437803ebf3ccc91c3d494a2ac8)
1 // RUN: %clang_cc1 -Werror -Wno-atomic-alignment -triple powerpc64le-linux-gnu \
2 // RUN:   -target-cpu pwr8 -emit-llvm -o - %s | FileCheck %s \
3 // RUN:   --check-prefixes=PPC64,PPC64-QUADWORD-ATOMICS
4 // RUN: %clang_cc1 -Werror -Wno-atomic-alignment -triple powerpc64le-linux-gnu \
5 // RUN:   -emit-llvm -o - %s | FileCheck %s \
6 // RUN:   --check-prefixes=PPC64,PPC64-NO-QUADWORD-ATOMICS
7 // RUN: %clang_cc1 -Werror -Wno-atomic-alignment -triple powerpc64-unknown-aix \
8 // RUN:   -target-cpu pwr7 -emit-llvm -o - %s | FileCheck %s \
9 // RUN:   --check-prefixes=PPC64,PPC64-NO-QUADWORD-ATOMICS
10 // RUN: %clang_cc1 -Werror -Wno-atomic-alignment -triple powerpc64-unknown-aix \
11 // RUN:   -target-cpu pwr8 -emit-llvm -o - %s | FileCheck %s \
12 // RUN:   --check-prefixes=PPC64,PPC64-NO-QUADWORD-ATOMICS
13 // RUN: %clang_cc1 -Werror -Wno-atomic-alignment -triple powerpc64-unknown-aix \
14 // RUN:   -mabi=quadword-atomics -target-cpu pwr8 -emit-llvm -o - %s | \
15 // RUN:   FileCheck %s --check-prefixes=PPC64,PPC64-QUADWORD-ATOMICS
16 
17 
18 typedef struct {
19   char x[16];
20 } Q;
21 
22 typedef _Atomic(Q) AtomicQ;
23 
24 typedef __int128_t int128_t;
25 
26 // PPC64-LABEL: @test_load(
27 // PPC64:    [[TMP3:%.*]] = load atomic i128, ptr [[TMP1:%.*]] acquire, align 16
28 //
test_load(AtomicQ * ptr)29 Q test_load(AtomicQ *ptr) {
30   // expected-no-diagnostics
31   return __c11_atomic_load(ptr, __ATOMIC_ACQUIRE);
32 }
33 
34 // PPC64-LABEL: @test_store(
35 // PPC64:    store atomic i128 [[TMP6:%.*]], ptr [[TMP4:%.*]] release, align 16
36 //
test_store(Q val,AtomicQ * ptr)37 void test_store(Q val, AtomicQ *ptr) {
38   // expected-no-diagnostics
39   __c11_atomic_store(ptr, val, __ATOMIC_RELEASE);
40 }
41 
42 // PPC64-LABEL: @test_add(
43 // PPC64:    [[ATOMICRMW:%.*]] = atomicrmw add ptr [[TMP0:%.*]], i128 [[TMP2:%.*]] monotonic, align 16
44 //
test_add(_Atomic (int128_t)* ptr,int128_t x)45 void test_add(_Atomic(int128_t) *ptr, int128_t x) {
46   // expected-no-diagnostics
47   __c11_atomic_fetch_add(ptr, x, __ATOMIC_RELAXED);
48 }
49 
50 // PPC64-LABEL: @test_xchg(
51 // PPC64:    [[TMP8:%.*]] = atomicrmw xchg ptr [[TMP4:%.*]], i128 [[TMP7:%.*]] seq_cst, align 16
52 //
test_xchg(AtomicQ * ptr,Q new)53 Q test_xchg(AtomicQ *ptr, Q new) {
54   // expected-no-diagnostics
55   return __c11_atomic_exchange(ptr, new, __ATOMIC_SEQ_CST);
56 }
57 
58 // PPC64-LABEL: @test_cmpxchg(
59 // PPC64:    [[TMP10:%.*]] = cmpxchg ptr [[TMP5:%.*]], i128 [[TMP8:%.*]], i128 [[TMP9:%.*]] seq_cst monotonic, align 16
60 //
test_cmpxchg(AtomicQ * ptr,Q * cmp,Q new)61 int test_cmpxchg(AtomicQ *ptr, Q *cmp, Q new) {
62   // expected-no-diagnostics
63   return __c11_atomic_compare_exchange_strong(ptr, cmp, new, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
64 }
65 
66 // PPC64-LABEL: @test_cmpxchg_weak(
67 // PPC64:    [[TMP10:%.*]] = cmpxchg weak ptr [[TMP5:%.*]], i128 [[TMP8:%.*]], i128 [[TMP9:%.*]] seq_cst monotonic, align 16
68 //
test_cmpxchg_weak(AtomicQ * ptr,Q * cmp,Q new)69 int test_cmpxchg_weak(AtomicQ *ptr, Q *cmp, Q new) {
70   // expected-no-diagnostics
71   return __c11_atomic_compare_exchange_weak(ptr, cmp, new, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
72 }
73 
74 // PPC64-QUADWORD-ATOMICS-LABEL: @is_lock_free(
75 // PPC64-QUADWORD-ATOMICS:    ret i32 1
76 //
77 // PPC64-NO-QUADWORD-ATOMICS-LABEL: @is_lock_free(
78 // PPC64-NO-QUADWORD-ATOMICS:    [[CALL:%.*]] = call zeroext i1 @__atomic_is_lock_free(i64 noundef 16, ptr noundef null)
79 //
is_lock_free()80 int is_lock_free() {
81   AtomicQ q;
82  // expected-no-diagnostics
83   return __c11_atomic_is_lock_free(sizeof(q));
84 }
85