1f4a2713aSLionel Sambuc // Test frontend handling of __sync builtins.
2f4a2713aSLionel Sambuc // Modified from a gcc testcase.
3f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc signed char sc;
6f4a2713aSLionel Sambuc unsigned char uc;
7f4a2713aSLionel Sambuc signed short ss;
8f4a2713aSLionel Sambuc unsigned short us;
9f4a2713aSLionel Sambuc signed int si;
10f4a2713aSLionel Sambuc unsigned int ui;
11f4a2713aSLionel Sambuc signed long long sll;
12f4a2713aSLionel Sambuc unsigned long long ull;
13f4a2713aSLionel Sambuc
test_op_ignore(void)14f4a2713aSLionel Sambuc void test_op_ignore (void) // CHECK-LABEL: define void @test_op_ignore
15f4a2713aSLionel Sambuc {
16f4a2713aSLionel Sambuc (void) __sync_fetch_and_add (&sc, 1); // CHECK: atomicrmw add i8
17f4a2713aSLionel Sambuc (void) __sync_fetch_and_add (&uc, 1); // CHECK: atomicrmw add i8
18f4a2713aSLionel Sambuc (void) __sync_fetch_and_add (&ss, 1); // CHECK: atomicrmw add i16
19f4a2713aSLionel Sambuc (void) __sync_fetch_and_add (&us, 1); // CHECK: atomicrmw add i16
20f4a2713aSLionel Sambuc (void) __sync_fetch_and_add (&si, 1); // CHECK: atomicrmw add i32
21f4a2713aSLionel Sambuc (void) __sync_fetch_and_add (&ui, 1); // CHECK: atomicrmw add i32
22f4a2713aSLionel Sambuc (void) __sync_fetch_and_add (&sll, 1); // CHECK: atomicrmw add i64
23f4a2713aSLionel Sambuc (void) __sync_fetch_and_add (&ull, 1); // CHECK: atomicrmw add i64
24f4a2713aSLionel Sambuc
25f4a2713aSLionel Sambuc (void) __sync_fetch_and_sub (&sc, 1); // CHECK: atomicrmw sub i8
26f4a2713aSLionel Sambuc (void) __sync_fetch_and_sub (&uc, 1); // CHECK: atomicrmw sub i8
27f4a2713aSLionel Sambuc (void) __sync_fetch_and_sub (&ss, 1); // CHECK: atomicrmw sub i16
28f4a2713aSLionel Sambuc (void) __sync_fetch_and_sub (&us, 1); // CHECK: atomicrmw sub i16
29f4a2713aSLionel Sambuc (void) __sync_fetch_and_sub (&si, 1); // CHECK: atomicrmw sub i32
30f4a2713aSLionel Sambuc (void) __sync_fetch_and_sub (&ui, 1); // CHECK: atomicrmw sub i32
31f4a2713aSLionel Sambuc (void) __sync_fetch_and_sub (&sll, 1); // CHECK: atomicrmw sub i64
32f4a2713aSLionel Sambuc (void) __sync_fetch_and_sub (&ull, 1); // CHECK: atomicrmw sub i64
33f4a2713aSLionel Sambuc
34f4a2713aSLionel Sambuc (void) __sync_fetch_and_or (&sc, 1); // CHECK: atomicrmw or i8
35f4a2713aSLionel Sambuc (void) __sync_fetch_and_or (&uc, 1); // CHECK: atomicrmw or i8
36f4a2713aSLionel Sambuc (void) __sync_fetch_and_or (&ss, 1); // CHECK: atomicrmw or i16
37f4a2713aSLionel Sambuc (void) __sync_fetch_and_or (&us, 1); // CHECK: atomicrmw or i16
38f4a2713aSLionel Sambuc (void) __sync_fetch_and_or (&si, 1); // CHECK: atomicrmw or i32
39f4a2713aSLionel Sambuc (void) __sync_fetch_and_or (&ui, 1); // CHECK: atomicrmw or i32
40f4a2713aSLionel Sambuc (void) __sync_fetch_and_or (&sll, 1); // CHECK: atomicrmw or i64
41f4a2713aSLionel Sambuc (void) __sync_fetch_and_or (&ull, 1); // CHECK: atomicrmw or i64
42f4a2713aSLionel Sambuc
43f4a2713aSLionel Sambuc (void) __sync_fetch_and_xor (&sc, 1); // CHECK: atomicrmw xor i8
44f4a2713aSLionel Sambuc (void) __sync_fetch_and_xor (&uc, 1); // CHECK: atomicrmw xor i8
45f4a2713aSLionel Sambuc (void) __sync_fetch_and_xor (&ss, 1); // CHECK: atomicrmw xor i16
46f4a2713aSLionel Sambuc (void) __sync_fetch_and_xor (&us, 1); // CHECK: atomicrmw xor i16
47f4a2713aSLionel Sambuc (void) __sync_fetch_and_xor (&si, 1); // CHECK: atomicrmw xor i32
48f4a2713aSLionel Sambuc (void) __sync_fetch_and_xor (&ui, 1); // CHECK: atomicrmw xor i32
49f4a2713aSLionel Sambuc (void) __sync_fetch_and_xor (&sll, 1); // CHECK: atomicrmw xor i64
50f4a2713aSLionel Sambuc (void) __sync_fetch_and_xor (&ull, 1); // CHECK: atomicrmw xor i64
51f4a2713aSLionel Sambuc
52*0a6a1f1dSLionel Sambuc (void) __sync_fetch_and_nand (&sc, 1); // CHECK: atomicrmw nand i8
53*0a6a1f1dSLionel Sambuc (void) __sync_fetch_and_nand (&uc, 1); // CHECK: atomicrmw nand i8
54*0a6a1f1dSLionel Sambuc (void) __sync_fetch_and_nand (&ss, 1); // CHECK: atomicrmw nand i16
55*0a6a1f1dSLionel Sambuc (void) __sync_fetch_and_nand (&us, 1); // CHECK: atomicrmw nand i16
56*0a6a1f1dSLionel Sambuc (void) __sync_fetch_and_nand (&si, 1); // CHECK: atomicrmw nand i32
57*0a6a1f1dSLionel Sambuc (void) __sync_fetch_and_nand (&ui, 1); // CHECK: atomicrmw nand i32
58*0a6a1f1dSLionel Sambuc (void) __sync_fetch_and_nand (&sll, 1); // CHECK: atomicrmw nand i64
59*0a6a1f1dSLionel Sambuc (void) __sync_fetch_and_nand (&ull, 1); // CHECK: atomicrmw nand i64
60*0a6a1f1dSLionel Sambuc
61f4a2713aSLionel Sambuc (void) __sync_fetch_and_and (&sc, 1); // CHECK: atomicrmw and i8
62f4a2713aSLionel Sambuc (void) __sync_fetch_and_and (&uc, 1); // CHECK: atomicrmw and i8
63f4a2713aSLionel Sambuc (void) __sync_fetch_and_and (&ss, 1); // CHECK: atomicrmw and i16
64f4a2713aSLionel Sambuc (void) __sync_fetch_and_and (&us, 1); // CHECK: atomicrmw and i16
65f4a2713aSLionel Sambuc (void) __sync_fetch_and_and (&si, 1); // CHECK: atomicrmw and i32
66f4a2713aSLionel Sambuc (void) __sync_fetch_and_and (&ui, 1); // CHECK: atomicrmw and i32
67f4a2713aSLionel Sambuc (void) __sync_fetch_and_and (&sll, 1); // CHECK: atomicrmw and i64
68f4a2713aSLionel Sambuc (void) __sync_fetch_and_and (&ull, 1); // CHECK: atomicrmw and i64
69f4a2713aSLionel Sambuc
70f4a2713aSLionel Sambuc }
71f4a2713aSLionel Sambuc
test_fetch_and_op(void)72f4a2713aSLionel Sambuc void test_fetch_and_op (void) // CHECK-LABEL: define void @test_fetch_and_op
73f4a2713aSLionel Sambuc {
74f4a2713aSLionel Sambuc sc = __sync_fetch_and_add (&sc, 11); // CHECK: atomicrmw add
75f4a2713aSLionel Sambuc uc = __sync_fetch_and_add (&uc, 11); // CHECK: atomicrmw add
76f4a2713aSLionel Sambuc ss = __sync_fetch_and_add (&ss, 11); // CHECK: atomicrmw add
77f4a2713aSLionel Sambuc us = __sync_fetch_and_add (&us, 11); // CHECK: atomicrmw add
78f4a2713aSLionel Sambuc si = __sync_fetch_and_add (&si, 11); // CHECK: atomicrmw add
79f4a2713aSLionel Sambuc ui = __sync_fetch_and_add (&ui, 11); // CHECK: atomicrmw add
80f4a2713aSLionel Sambuc sll = __sync_fetch_and_add (&sll, 11); // CHECK: atomicrmw add
81f4a2713aSLionel Sambuc ull = __sync_fetch_and_add (&ull, 11); // CHECK: atomicrmw add
82f4a2713aSLionel Sambuc
83f4a2713aSLionel Sambuc sc = __sync_fetch_and_sub (&sc, 11); // CHECK: atomicrmw sub
84f4a2713aSLionel Sambuc uc = __sync_fetch_and_sub (&uc, 11); // CHECK: atomicrmw sub
85f4a2713aSLionel Sambuc ss = __sync_fetch_and_sub (&ss, 11); // CHECK: atomicrmw sub
86f4a2713aSLionel Sambuc us = __sync_fetch_and_sub (&us, 11); // CHECK: atomicrmw sub
87f4a2713aSLionel Sambuc si = __sync_fetch_and_sub (&si, 11); // CHECK: atomicrmw sub
88f4a2713aSLionel Sambuc ui = __sync_fetch_and_sub (&ui, 11); // CHECK: atomicrmw sub
89f4a2713aSLionel Sambuc sll = __sync_fetch_and_sub (&sll, 11); // CHECK: atomicrmw sub
90f4a2713aSLionel Sambuc ull = __sync_fetch_and_sub (&ull, 11); // CHECK: atomicrmw sub
91f4a2713aSLionel Sambuc
92f4a2713aSLionel Sambuc sc = __sync_fetch_and_or (&sc, 11); // CHECK: atomicrmw or
93f4a2713aSLionel Sambuc uc = __sync_fetch_and_or (&uc, 11); // CHECK: atomicrmw or
94f4a2713aSLionel Sambuc ss = __sync_fetch_and_or (&ss, 11); // CHECK: atomicrmw or
95f4a2713aSLionel Sambuc us = __sync_fetch_and_or (&us, 11); // CHECK: atomicrmw or
96f4a2713aSLionel Sambuc si = __sync_fetch_and_or (&si, 11); // CHECK: atomicrmw or
97f4a2713aSLionel Sambuc ui = __sync_fetch_and_or (&ui, 11); // CHECK: atomicrmw or
98f4a2713aSLionel Sambuc sll = __sync_fetch_and_or (&sll, 11); // CHECK: atomicrmw or
99f4a2713aSLionel Sambuc ull = __sync_fetch_and_or (&ull, 11); // CHECK: atomicrmw or
100f4a2713aSLionel Sambuc
101f4a2713aSLionel Sambuc sc = __sync_fetch_and_xor (&sc, 11); // CHECK: atomicrmw xor
102f4a2713aSLionel Sambuc uc = __sync_fetch_and_xor (&uc, 11); // CHECK: atomicrmw xor
103f4a2713aSLionel Sambuc ss = __sync_fetch_and_xor (&ss, 11); // CHECK: atomicrmw xor
104f4a2713aSLionel Sambuc us = __sync_fetch_and_xor (&us, 11); // CHECK: atomicrmw xor
105f4a2713aSLionel Sambuc si = __sync_fetch_and_xor (&si, 11); // CHECK: atomicrmw xor
106f4a2713aSLionel Sambuc ui = __sync_fetch_and_xor (&ui, 11); // CHECK: atomicrmw xor
107f4a2713aSLionel Sambuc sll = __sync_fetch_and_xor (&sll, 11); // CHECK: atomicrmw xor
108f4a2713aSLionel Sambuc ull = __sync_fetch_and_xor (&ull, 11); // CHECK: atomicrmw xor
109f4a2713aSLionel Sambuc
110*0a6a1f1dSLionel Sambuc sc = __sync_fetch_and_nand (&sc, 11); // CHECK: atomicrmw nand
111*0a6a1f1dSLionel Sambuc uc = __sync_fetch_and_nand (&uc, 11); // CHECK: atomicrmw nand
112*0a6a1f1dSLionel Sambuc ss = __sync_fetch_and_nand (&ss, 11); // CHECK: atomicrmw nand
113*0a6a1f1dSLionel Sambuc us = __sync_fetch_and_nand (&us, 11); // CHECK: atomicrmw nand
114*0a6a1f1dSLionel Sambuc si = __sync_fetch_and_nand (&si, 11); // CHECK: atomicrmw nand
115*0a6a1f1dSLionel Sambuc ui = __sync_fetch_and_nand (&ui, 11); // CHECK: atomicrmw nand
116*0a6a1f1dSLionel Sambuc sll = __sync_fetch_and_nand (&sll, 11); // CHECK: atomicrmw nand
117*0a6a1f1dSLionel Sambuc ull = __sync_fetch_and_nand (&ull, 11); // CHECK: atomicrmw nand
118*0a6a1f1dSLionel Sambuc
119f4a2713aSLionel Sambuc sc = __sync_fetch_and_and (&sc, 11); // CHECK: atomicrmw and
120f4a2713aSLionel Sambuc uc = __sync_fetch_and_and (&uc, 11); // CHECK: atomicrmw and
121f4a2713aSLionel Sambuc ss = __sync_fetch_and_and (&ss, 11); // CHECK: atomicrmw and
122f4a2713aSLionel Sambuc us = __sync_fetch_and_and (&us, 11); // CHECK: atomicrmw and
123f4a2713aSLionel Sambuc si = __sync_fetch_and_and (&si, 11); // CHECK: atomicrmw and
124f4a2713aSLionel Sambuc ui = __sync_fetch_and_and (&ui, 11); // CHECK: atomicrmw and
125f4a2713aSLionel Sambuc sll = __sync_fetch_and_and (&sll, 11); // CHECK: atomicrmw and
126f4a2713aSLionel Sambuc ull = __sync_fetch_and_and (&ull, 11); // CHECK: atomicrmw and
127f4a2713aSLionel Sambuc
128f4a2713aSLionel Sambuc }
129f4a2713aSLionel Sambuc
test_op_and_fetch(void)130f4a2713aSLionel Sambuc void test_op_and_fetch (void)
131f4a2713aSLionel Sambuc {
132f4a2713aSLionel Sambuc sc = __sync_add_and_fetch (&sc, uc); // CHECK: atomicrmw add
133f4a2713aSLionel Sambuc uc = __sync_add_and_fetch (&uc, uc); // CHECK: atomicrmw add
134f4a2713aSLionel Sambuc ss = __sync_add_and_fetch (&ss, uc); // CHECK: atomicrmw add
135f4a2713aSLionel Sambuc us = __sync_add_and_fetch (&us, uc); // CHECK: atomicrmw add
136f4a2713aSLionel Sambuc si = __sync_add_and_fetch (&si, uc); // CHECK: atomicrmw add
137f4a2713aSLionel Sambuc ui = __sync_add_and_fetch (&ui, uc); // CHECK: atomicrmw add
138f4a2713aSLionel Sambuc sll = __sync_add_and_fetch (&sll, uc); // CHECK: atomicrmw add
139f4a2713aSLionel Sambuc ull = __sync_add_and_fetch (&ull, uc); // CHECK: atomicrmw add
140f4a2713aSLionel Sambuc
141f4a2713aSLionel Sambuc sc = __sync_sub_and_fetch (&sc, uc); // CHECK: atomicrmw sub
142f4a2713aSLionel Sambuc uc = __sync_sub_and_fetch (&uc, uc); // CHECK: atomicrmw sub
143f4a2713aSLionel Sambuc ss = __sync_sub_and_fetch (&ss, uc); // CHECK: atomicrmw sub
144f4a2713aSLionel Sambuc us = __sync_sub_and_fetch (&us, uc); // CHECK: atomicrmw sub
145f4a2713aSLionel Sambuc si = __sync_sub_and_fetch (&si, uc); // CHECK: atomicrmw sub
146f4a2713aSLionel Sambuc ui = __sync_sub_and_fetch (&ui, uc); // CHECK: atomicrmw sub
147f4a2713aSLionel Sambuc sll = __sync_sub_and_fetch (&sll, uc); // CHECK: atomicrmw sub
148f4a2713aSLionel Sambuc ull = __sync_sub_and_fetch (&ull, uc); // CHECK: atomicrmw sub
149f4a2713aSLionel Sambuc
150f4a2713aSLionel Sambuc sc = __sync_or_and_fetch (&sc, uc); // CHECK: atomicrmw or
151f4a2713aSLionel Sambuc uc = __sync_or_and_fetch (&uc, uc); // CHECK: atomicrmw or
152f4a2713aSLionel Sambuc ss = __sync_or_and_fetch (&ss, uc); // CHECK: atomicrmw or
153f4a2713aSLionel Sambuc us = __sync_or_and_fetch (&us, uc); // CHECK: atomicrmw or
154f4a2713aSLionel Sambuc si = __sync_or_and_fetch (&si, uc); // CHECK: atomicrmw or
155f4a2713aSLionel Sambuc ui = __sync_or_and_fetch (&ui, uc); // CHECK: atomicrmw or
156f4a2713aSLionel Sambuc sll = __sync_or_and_fetch (&sll, uc); // CHECK: atomicrmw or
157f4a2713aSLionel Sambuc ull = __sync_or_and_fetch (&ull, uc); // CHECK: atomicrmw or
158f4a2713aSLionel Sambuc
159f4a2713aSLionel Sambuc sc = __sync_xor_and_fetch (&sc, uc); // CHECK: atomicrmw xor
160f4a2713aSLionel Sambuc uc = __sync_xor_and_fetch (&uc, uc); // CHECK: atomicrmw xor
161f4a2713aSLionel Sambuc ss = __sync_xor_and_fetch (&ss, uc); // CHECK: atomicrmw xor
162f4a2713aSLionel Sambuc us = __sync_xor_and_fetch (&us, uc); // CHECK: atomicrmw xor
163f4a2713aSLionel Sambuc si = __sync_xor_and_fetch (&si, uc); // CHECK: atomicrmw xor
164f4a2713aSLionel Sambuc ui = __sync_xor_and_fetch (&ui, uc); // CHECK: atomicrmw xor
165f4a2713aSLionel Sambuc sll = __sync_xor_and_fetch (&sll, uc); // CHECK: atomicrmw xor
166f4a2713aSLionel Sambuc ull = __sync_xor_and_fetch (&ull, uc); // CHECK: atomicrmw xor
167f4a2713aSLionel Sambuc
168*0a6a1f1dSLionel Sambuc sc = __sync_nand_and_fetch (&sc, uc); // CHECK: atomicrmw nand
169*0a6a1f1dSLionel Sambuc // CHECK: and
170*0a6a1f1dSLionel Sambuc // CHECK: xor
171*0a6a1f1dSLionel Sambuc uc = __sync_nand_and_fetch (&uc, uc); // CHECK: atomicrmw nand
172*0a6a1f1dSLionel Sambuc // CHECK: and
173*0a6a1f1dSLionel Sambuc // CHECK: xor
174*0a6a1f1dSLionel Sambuc ss = __sync_nand_and_fetch (&ss, uc); // CHECK: atomicrmw nand
175*0a6a1f1dSLionel Sambuc // CHECK: and
176*0a6a1f1dSLionel Sambuc // CHECK: xor
177*0a6a1f1dSLionel Sambuc us = __sync_nand_and_fetch (&us, uc); // CHECK: atomicrmw nand
178*0a6a1f1dSLionel Sambuc // CHECK: and
179*0a6a1f1dSLionel Sambuc // CHECK: xor
180*0a6a1f1dSLionel Sambuc si = __sync_nand_and_fetch (&si, uc); // CHECK: atomicrmw nand
181*0a6a1f1dSLionel Sambuc // CHECK: and
182*0a6a1f1dSLionel Sambuc // CHECK: xor
183*0a6a1f1dSLionel Sambuc ui = __sync_nand_and_fetch (&ui, uc); // CHECK: atomicrmw nand
184*0a6a1f1dSLionel Sambuc // CHECK: and
185*0a6a1f1dSLionel Sambuc // CHECK: xor
186*0a6a1f1dSLionel Sambuc sll = __sync_nand_and_fetch (&sll, uc); // CHECK: atomicrmw nand
187*0a6a1f1dSLionel Sambuc // CHECK: and
188*0a6a1f1dSLionel Sambuc // CHECK: xor
189*0a6a1f1dSLionel Sambuc ull = __sync_nand_and_fetch (&ull, uc); // CHECK: atomicrmw nand
190*0a6a1f1dSLionel Sambuc // CHECK: and
191*0a6a1f1dSLionel Sambuc // CHECK: xor
192*0a6a1f1dSLionel Sambuc
193f4a2713aSLionel Sambuc sc = __sync_and_and_fetch (&sc, uc); // CHECK: atomicrmw and
194f4a2713aSLionel Sambuc uc = __sync_and_and_fetch (&uc, uc); // CHECK: atomicrmw and
195f4a2713aSLionel Sambuc ss = __sync_and_and_fetch (&ss, uc); // CHECK: atomicrmw and
196f4a2713aSLionel Sambuc us = __sync_and_and_fetch (&us, uc); // CHECK: atomicrmw and
197f4a2713aSLionel Sambuc si = __sync_and_and_fetch (&si, uc); // CHECK: atomicrmw and
198f4a2713aSLionel Sambuc ui = __sync_and_and_fetch (&ui, uc); // CHECK: atomicrmw and
199f4a2713aSLionel Sambuc sll = __sync_and_and_fetch (&sll, uc); // CHECK: atomicrmw and
200f4a2713aSLionel Sambuc ull = __sync_and_and_fetch (&ull, uc); // CHECK: atomicrmw and
201f4a2713aSLionel Sambuc
202f4a2713aSLionel Sambuc }
203f4a2713aSLionel Sambuc
test_compare_and_swap(void)204f4a2713aSLionel Sambuc void test_compare_and_swap (void)
205f4a2713aSLionel Sambuc {
206*0a6a1f1dSLionel Sambuc sc = __sync_val_compare_and_swap (&sc, uc, sc);
207*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i8
208*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i8, i1 } [[PAIR]], 0
209f4a2713aSLionel Sambuc
210*0a6a1f1dSLionel Sambuc uc = __sync_val_compare_and_swap (&uc, uc, sc);
211*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i8
212*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i8, i1 } [[PAIR]], 0
213*0a6a1f1dSLionel Sambuc
214*0a6a1f1dSLionel Sambuc ss = __sync_val_compare_and_swap (&ss, uc, sc);
215*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i16
216*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i16, i1 } [[PAIR]], 0
217*0a6a1f1dSLionel Sambuc
218*0a6a1f1dSLionel Sambuc us = __sync_val_compare_and_swap (&us, uc, sc);
219*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i16
220*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i16, i1 } [[PAIR]], 0
221*0a6a1f1dSLionel Sambuc
222*0a6a1f1dSLionel Sambuc si = __sync_val_compare_and_swap (&si, uc, sc);
223*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i32
224*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i32, i1 } [[PAIR]], 0
225*0a6a1f1dSLionel Sambuc
226*0a6a1f1dSLionel Sambuc ui = __sync_val_compare_and_swap (&ui, uc, sc);
227*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i32
228*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i32, i1 } [[PAIR]], 0
229*0a6a1f1dSLionel Sambuc
230*0a6a1f1dSLionel Sambuc sll = __sync_val_compare_and_swap (&sll, uc, sc);
231*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i64
232*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i64, i1 } [[PAIR]], 0
233*0a6a1f1dSLionel Sambuc
234*0a6a1f1dSLionel Sambuc ull = __sync_val_compare_and_swap (&ull, uc, sc);
235*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i64
236*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i64, i1 } [[PAIR]], 0
237*0a6a1f1dSLionel Sambuc
238*0a6a1f1dSLionel Sambuc
239*0a6a1f1dSLionel Sambuc ui = __sync_bool_compare_and_swap (&sc, uc, sc);
240*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i8
241*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i8, i1 } [[PAIR]], 1
242*0a6a1f1dSLionel Sambuc
243*0a6a1f1dSLionel Sambuc ui = __sync_bool_compare_and_swap (&uc, uc, sc);
244*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i8
245*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i8, i1 } [[PAIR]], 1
246*0a6a1f1dSLionel Sambuc
247*0a6a1f1dSLionel Sambuc ui = __sync_bool_compare_and_swap (&ss, uc, sc);
248*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i16
249*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i16, i1 } [[PAIR]], 1
250*0a6a1f1dSLionel Sambuc
251*0a6a1f1dSLionel Sambuc ui = __sync_bool_compare_and_swap (&us, uc, sc);
252*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i16
253*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i16, i1 } [[PAIR]], 1
254*0a6a1f1dSLionel Sambuc
255*0a6a1f1dSLionel Sambuc ui = __sync_bool_compare_and_swap (&si, uc, sc);
256*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i32
257*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i32, i1 } [[PAIR]], 1
258*0a6a1f1dSLionel Sambuc
259*0a6a1f1dSLionel Sambuc ui = __sync_bool_compare_and_swap (&ui, uc, sc);
260*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i32
261*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i32, i1 } [[PAIR]], 1
262*0a6a1f1dSLionel Sambuc
263*0a6a1f1dSLionel Sambuc ui = __sync_bool_compare_and_swap (&sll, uc, sc);
264*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i64
265*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i64, i1 } [[PAIR]], 1
266*0a6a1f1dSLionel Sambuc
267*0a6a1f1dSLionel Sambuc ui = __sync_bool_compare_and_swap (&ull, uc, sc);
268*0a6a1f1dSLionel Sambuc // CHECK: [[PAIR:%[a-z0-9._]+]] = cmpxchg i64
269*0a6a1f1dSLionel Sambuc // CHECK: extractvalue { i64, i1 } [[PAIR]], 1
270f4a2713aSLionel Sambuc }
271f4a2713aSLionel Sambuc
test_lock(void)272f4a2713aSLionel Sambuc void test_lock (void)
273f4a2713aSLionel Sambuc {
274f4a2713aSLionel Sambuc sc = __sync_lock_test_and_set (&sc, 1); // CHECK: atomicrmw xchg i8
275f4a2713aSLionel Sambuc uc = __sync_lock_test_and_set (&uc, 1); // CHECK: atomicrmw xchg i8
276f4a2713aSLionel Sambuc ss = __sync_lock_test_and_set (&ss, 1); // CHECK: atomicrmw xchg i16
277f4a2713aSLionel Sambuc us = __sync_lock_test_and_set (&us, 1); // CHECK: atomicrmw xchg i16
278f4a2713aSLionel Sambuc si = __sync_lock_test_and_set (&si, 1); // CHECK: atomicrmw xchg i32
279f4a2713aSLionel Sambuc ui = __sync_lock_test_and_set (&ui, 1); // CHECK: atomicrmw xchg i32
280f4a2713aSLionel Sambuc sll = __sync_lock_test_and_set (&sll, 1); // CHECK: atomicrmw xchg i64
281f4a2713aSLionel Sambuc ull = __sync_lock_test_and_set (&ull, 1); // CHECK: atomicrmw xchg i64
282f4a2713aSLionel Sambuc
283f4a2713aSLionel Sambuc __sync_synchronize (); // CHECK: fence seq_cst
284f4a2713aSLionel Sambuc
285f4a2713aSLionel Sambuc __sync_lock_release (&sc); // CHECK: store atomic {{.*}} release, align 1
286f4a2713aSLionel Sambuc __sync_lock_release (&uc); // CHECK: store atomic {{.*}} release, align 1
287f4a2713aSLionel Sambuc __sync_lock_release (&ss); // CHECK: store atomic {{.*}} release, align 2
288f4a2713aSLionel Sambuc __sync_lock_release (&us); /// CHECK: store atomic {{.*}} release, align 2
289f4a2713aSLionel Sambuc __sync_lock_release (&si); // CHECK: store atomic {{.*}} release, align 4
290f4a2713aSLionel Sambuc __sync_lock_release (&ui); // CHECK: store atomic {{.*}} release, align 4
291f4a2713aSLionel Sambuc __sync_lock_release (&sll); // CHECK: store atomic {{.*}} release, align 8
292f4a2713aSLionel Sambuc __sync_lock_release (&ull); // CHECK: store atomic {{.*}} release, align 8
293f4a2713aSLionel Sambuc }
294