Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGen / ms-intrinsics-other.c
blob76f54add7496695776773b4c88a1b23b61c34c4d
1 // RUN: %clang_cc1 -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
2 // RUN: -triple x86_64--darwin -Oz -emit-llvm %s -o - \
3 // RUN: | FileCheck %s
4 // RUN: %clang_cc1 -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
5 // RUN: -triple x86_64--linux -Oz -emit-llvm %s -o - \
6 // RUN: | FileCheck %s
7 // RUN: %clang_cc1 -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
8 // RUN: -triple aarch64--darwin -Oz -emit-llvm %s -o - \
9 // RUN: | FileCheck %s --check-prefix=CHECK-ARM-ARM64
10 // RUN: %clang_cc1 -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
11 // RUN: -triple aarch64--darwin -Oz -emit-llvm %s -o - \
12 // RUN: | FileCheck %s --check-prefix=CHECK-ARM
13 // RUN: %clang_cc1 -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
14 // RUN: -triple armv7--darwin -Oz -emit-llvm %s -o - \
15 // RUN: | FileCheck %s --check-prefix=CHECK-ARM
17 // RUN: %clang_cc1 -x c++ -std=c++11 \
18 // RUN: -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
19 // RUN: -triple x86_64--darwin -Oz -emit-llvm %s -o - \
20 // RUN: | FileCheck %s
21 // RUN: %clang_cc1 -x c++ -std=c++11 \
22 // RUN: -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
23 // RUN: -triple x86_64--linux -Oz -emit-llvm %s -o - \
24 // RUN: | FileCheck %s
25 // RUN: %clang_cc1 -x c++ -std=c++11 \
26 // RUN: -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
27 // RUN: -triple aarch64--darwin -Oz -emit-llvm %s -o - \
28 // RUN: | FileCheck %s --check-prefix=CHECK-ARM-ARM64
29 // RUN: %clang_cc1 -x c++ -std=c++11 \
30 // RUN: -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
31 // RUN: -triple aarch64--darwin -Oz -emit-llvm %s -o - \
32 // RUN: | FileCheck %s --check-prefix=CHECK-ARM
33 // RUN: %clang_cc1 -x c++ -std=c++11 \
34 // RUN: -ffreestanding -fms-extensions -Wno-implicit-function-declaration \
35 // RUN: -triple armv7--darwin -Oz -emit-llvm %s -o - \
36 // RUN: | FileCheck %s --check-prefix=CHECK-ARM
38 // LP64 targets use 'long' as 'int' for MS intrinsics (-fms-extensions)
39 #ifdef __LP64__
40 #define LONG int
41 #else
42 #define LONG long
43 #endif
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
49 unsigned char test_BitScanForward(unsigned LONG *Index, unsigned LONG Mask) {
50 return _BitScanForward(Index, Mask);
52 // CHECK: define{{.*}}i8 @test_BitScanForward(ptr {{[a-z_ ]*}}%Index, i32 {{[a-z_ ]*}}%Mask){{.*}}{
53 // CHECK: [[ISNOTZERO:%[a-z0-9._]+]] = icmp eq i32 %Mask, 0
54 // CHECK: br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9._]+]], label %[[ISNOTZERO_LABEL:[a-z0-9._]+]]
55 // CHECK: [[END_LABEL]]:
56 // CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
57 // CHECK: ret i8 [[RESULT]]
58 // CHECK: [[ISNOTZERO_LABEL]]:
59 // CHECK: [[INDEX:%[0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %Mask, i1 true)
60 // CHECK: store i32 [[INDEX]], ptr %Index, align 4
61 // CHECK: br label %[[END_LABEL]]
63 unsigned char test_BitScanReverse(unsigned LONG *Index, unsigned LONG Mask) {
64 return _BitScanReverse(Index, Mask);
66 // CHECK: define{{.*}}i8 @test_BitScanReverse(ptr {{[a-z_ ]*}}%Index, i32 {{[a-z_ ]*}}%Mask){{.*}}{
67 // CHECK: [[ISNOTZERO:%[0-9]+]] = icmp eq i32 %Mask, 0
68 // CHECK: br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9._]+]], label %[[ISNOTZERO_LABEL:[a-z0-9._]+]]
69 // CHECK: [[END_LABEL]]:
70 // CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
71 // CHECK: ret i8 [[RESULT]]
72 // CHECK: [[ISNOTZERO_LABEL]]:
73 // CHECK: [[REVINDEX:%[0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %Mask, i1 true)
74 // CHECK: [[INDEX:%[0-9]+]] = xor i32 [[REVINDEX]], 31
75 // CHECK: store i32 [[INDEX]], ptr %Index, align 4
76 // CHECK: br label %[[END_LABEL]]
78 #if defined(__x86_64__)
79 unsigned char test_BitScanForward64(unsigned LONG *Index, unsigned __int64 Mask) {
80 return _BitScanForward64(Index, Mask);
82 // CHECK: define{{.*}}i8 @test_BitScanForward64(ptr {{[a-z_ ]*}}%Index, i64 {{[a-z_ ]*}}%Mask){{.*}}{
83 // CHECK: [[ISNOTZERO:%[a-z0-9._]+]] = icmp eq i64 %Mask, 0
84 // CHECK: br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9._]+]], label %[[ISNOTZERO_LABEL:[a-z0-9._]+]]
85 // CHECK: [[END_LABEL]]:
86 // CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
87 // CHECK: ret i8 [[RESULT]]
88 // CHECK: [[ISNOTZERO_LABEL]]:
89 // CHECK: [[INDEX:%[0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %Mask, i1 true)
90 // CHECK: [[TRUNC_INDEX:%[0-9]+]] = trunc i64 [[INDEX]] to i32
91 // CHECK: store i32 [[TRUNC_INDEX]], ptr %Index, align 4
92 // CHECK: br label %[[END_LABEL]]
94 unsigned char test_BitScanReverse64(unsigned LONG *Index, unsigned __int64 Mask) {
95 return _BitScanReverse64(Index, Mask);
97 // CHECK: define{{.*}}i8 @test_BitScanReverse64(ptr {{[a-z_ ]*}}%Index, i64 {{[a-z_ ]*}}%Mask){{.*}}{
98 // CHECK: [[ISNOTZERO:%[0-9]+]] = icmp eq i64 %Mask, 0
99 // CHECK: br i1 [[ISNOTZERO]], label %[[END_LABEL:[a-z0-9._]+]], label %[[ISNOTZERO_LABEL:[a-z0-9._]+]]
100 // CHECK: [[END_LABEL]]:
101 // CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
102 // CHECK: ret i8 [[RESULT]]
103 // CHECK: [[ISNOTZERO_LABEL]]:
104 // CHECK: [[REVINDEX:%[0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %Mask, i1 true)
105 // CHECK: [[TRUNC_REVINDEX:%[0-9]+]] = trunc i64 [[REVINDEX]] to i32
106 // CHECK: [[INDEX:%[0-9]+]] = xor i32 [[TRUNC_REVINDEX]], 63
107 // CHECK: store i32 [[INDEX]], ptr %Index, align 4
108 // CHECK: br label %[[END_LABEL]]
109 #endif
111 LONG test_InterlockedExchange(LONG volatile *value, LONG mask) {
112 return _InterlockedExchange(value, mask);
114 // CHECK: define{{.*}}i32 @test_InterlockedExchange(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
115 // CHECK: [[RESULT:%[0-9]+]] = atomicrmw xchg ptr %value, i32 %mask seq_cst, align 4
116 // CHECK: ret i32 [[RESULT:%[0-9]+]]
117 // CHECK: }
119 LONG test_InterlockedExchangeAdd(LONG volatile *value, LONG mask) {
120 return _InterlockedExchangeAdd(value, mask);
122 // CHECK: define{{.*}}i32 @test_InterlockedExchangeAdd(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
123 // CHECK: [[RESULT:%[0-9]+]] = atomicrmw add ptr %value, i32 %mask seq_cst, align 4
124 // CHECK: ret i32 [[RESULT:%[0-9]+]]
125 // CHECK: }
127 LONG test_InterlockedExchangeSub(LONG volatile *value, LONG mask) {
128 return _InterlockedExchangeSub(value, mask);
130 // CHECK: define{{.*}}i32 @test_InterlockedExchangeSub(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
131 // CHECK: [[RESULT:%[0-9]+]] = atomicrmw sub ptr %value, i32 %mask seq_cst, align 4
132 // CHECK: ret i32 [[RESULT:%[0-9]+]]
133 // CHECK: }
135 LONG test_InterlockedOr(LONG volatile *value, LONG mask) {
136 return _InterlockedOr(value, mask);
138 // CHECK: define{{.*}}i32 @test_InterlockedOr(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
139 // CHECK: [[RESULT:%[0-9]+]] = atomicrmw or ptr %value, i32 %mask seq_cst, align 4
140 // CHECK: ret i32 [[RESULT:%[0-9]+]]
141 // CHECK: }
143 LONG test_InterlockedXor(LONG volatile *value, LONG mask) {
144 return _InterlockedXor(value, mask);
146 // CHECK: define{{.*}}i32 @test_InterlockedXor(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
147 // CHECK: [[RESULT:%[0-9]+]] = atomicrmw xor ptr %value, i32 %mask seq_cst, align 4
148 // CHECK: ret i32 [[RESULT:%[0-9]+]]
149 // CHECK: }
151 LONG test_InterlockedAnd(LONG volatile *value, LONG mask) {
152 return _InterlockedAnd(value, mask);
154 // CHECK: define{{.*}}i32 @test_InterlockedAnd(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
155 // CHECK: [[RESULT:%[0-9]+]] = atomicrmw and ptr %value, i32 %mask seq_cst, align 4
156 // CHECK: ret i32 [[RESULT:%[0-9]+]]
157 // CHECK: }
159 LONG test_InterlockedCompareExchange(LONG volatile *Destination, LONG Exchange, LONG Comperand) {
160 return _InterlockedCompareExchange(Destination, Exchange, Comperand);
162 // CHECK: define{{.*}}i32 @test_InterlockedCompareExchange(ptr{{[a-z_ ]*}}%Destination, i32{{[a-z_ ]*}}%Exchange, i32{{[a-z_ ]*}}%Comperand){{.*}}{
163 // CHECK: [[TMP:%[0-9]+]] = cmpxchg volatile ptr %Destination, i32 %Comperand, i32 %Exchange seq_cst seq_cst, align 4
164 // CHECK: [[RESULT:%[0-9]+]] = extractvalue { i32, i1 } [[TMP]], 0
165 // CHECK: ret i32 [[RESULT]]
166 // CHECK: }
168 LONG test_InterlockedIncrement(LONG volatile *Addend) {
169 return _InterlockedIncrement(Addend);
171 // CHECK: define{{.*}}i32 @test_InterlockedIncrement(ptr{{[a-z_ ]*}}%Addend){{.*}}{
172 // CHECK: [[TMP:%[0-9]+]] = atomicrmw add ptr %Addend, i32 1 seq_cst, align 4
173 // CHECK: [[RESULT:%[0-9]+]] = add i32 [[TMP]], 1
174 // CHECK: ret i32 [[RESULT]]
175 // CHECK: }
177 LONG test_InterlockedDecrement(LONG volatile *Addend) {
178 return _InterlockedDecrement(Addend);
180 // CHECK: define{{.*}}i32 @test_InterlockedDecrement(ptr{{[a-z_ ]*}}%Addend){{.*}}{
181 // CHECK: [[TMP:%[0-9]+]] = atomicrmw sub ptr %Addend, i32 1 seq_cst, align 4
182 // CHECK: [[RESULT:%[0-9]+]] = add i32 [[TMP]], -1
183 // CHECK: ret i32 [[RESULT]]
184 // CHECK: }
186 unsigned short test__lzcnt16(unsigned short x) {
187 return __lzcnt16(x);
189 // CHECK: i16 @test__lzcnt16
190 // CHECK: [[RESULT:%[0-9]+]] = tail call i16 @llvm.ctlz.i16(i16 %x, i1 false)
191 // CHECK: ret i16 [[RESULT]]
192 // CHECK: }
194 unsigned int test__lzcnt(unsigned int x) {
195 return __lzcnt(x);
197 // CHECK: i32 @test__lzcnt
198 // CHECK: [[RESULT:%[0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %x, i1 false)
199 // CHECK: ret i32 [[RESULT]]
200 // CHECK: }
202 unsigned __int64 test__lzcnt64(unsigned __int64 x) {
203 return __lzcnt64(x);
205 // CHECK: i64 @test__lzcnt64
206 // CHECK: [[RESULT:%[0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %x, i1 false)
207 // CHECK: ret i64 [[RESULT]]
208 // CHECK: }
210 unsigned short test__popcnt16(unsigned short x) {
211 return __popcnt16(x);
213 // CHECK: i16 @test__popcnt16
214 // CHECK: [[RESULT:%[0-9]+]] = tail call i16 @llvm.ctpop.i16(i16 %x)
215 // CHECK: ret i16 [[RESULT]]
216 // CHECK: }
218 unsigned int test__popcnt(unsigned int x) {
219 return __popcnt(x);
221 // CHECK: i32 @test__popcnt
222 // CHECK: [[RESULT:%[0-9]+]] = tail call i32 @llvm.ctpop.i32(i32 %x)
223 // CHECK: ret i32 [[RESULT]]
224 // CHECK: }
226 unsigned __int64 test__popcnt64(unsigned __int64 x) {
227 return __popcnt64(x);
229 // CHECK: i64 @test__popcnt64
230 // CHECK: [[RESULT:%[0-9]+]] = tail call i64 @llvm.ctpop.i64(i64 %x)
231 // CHECK: ret i64 [[RESULT]]
232 // CHECK: }
234 #if defined(__aarch64__)
235 LONG test_InterlockedAdd(LONG volatile *Addend, LONG Value) {
236 return _InterlockedAdd(Addend, Value);
239 // CHECK-ARM-ARM64: define{{.*}}i32 @test_InterlockedAdd(ptr{{[a-z_ ]*}}%Addend, i32 noundef %Value) {{.*}} {
240 // CHECK-ARM-ARM64: %[[OLDVAL:[0-9]+]] = atomicrmw add ptr %Addend, i32 %Value seq_cst, align 4
241 // CHECK-ARM-ARM64: %[[NEWVAL:[0-9]+]] = add i32 %[[OLDVAL:[0-9]+]], %Value
242 // CHECK-ARM-ARM64: ret i32 %[[NEWVAL:[0-9]+]]
243 #endif
245 #if defined(__arm__) || defined(__aarch64__)
246 LONG test_InterlockedExchangeAdd_acq(LONG volatile *value, LONG mask) {
247 return _InterlockedExchangeAdd_acq(value, mask);
249 // CHECK-ARM: define{{.*}}i32 @test_InterlockedExchangeAdd_acq(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
250 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw add ptr %value, i32 %mask acquire, align 4
251 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
252 // CHECK-ARM: }
253 LONG test_InterlockedExchangeAdd_rel(LONG volatile *value, LONG mask) {
254 return _InterlockedExchangeAdd_rel(value, mask);
256 // CHECK-ARM: define{{.*}}i32 @test_InterlockedExchangeAdd_rel(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
257 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw add ptr %value, i32 %mask release, align 4
258 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
259 // CHECK-ARM: }
260 LONG test_InterlockedExchangeAdd_nf(LONG volatile *value, LONG mask) {
261 return _InterlockedExchangeAdd_nf(value, mask);
263 // CHECK-ARM: define{{.*}}i32 @test_InterlockedExchangeAdd_nf(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
264 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw add ptr %value, i32 %mask monotonic, align 4
265 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
266 // CHECK-ARM: }
268 LONG test_InterlockedExchange_acq(LONG volatile *value, LONG mask) {
269 return _InterlockedExchange_acq(value, mask);
271 // CHECK-ARM: define{{.*}}i32 @test_InterlockedExchange_acq(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
272 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw xchg ptr %value, i32 %mask acquire, align 4
273 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
274 // CHECK-ARM: }
275 LONG test_InterlockedExchange_rel(LONG volatile *value, LONG mask) {
276 return _InterlockedExchange_rel(value, mask);
278 // CHECK-ARM: define{{.*}}i32 @test_InterlockedExchange_rel(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
279 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw xchg ptr %value, i32 %mask release, align 4
280 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
281 // CHECK-ARM: }
282 LONG test_InterlockedExchange_nf(LONG volatile *value, LONG mask) {
283 return _InterlockedExchange_nf(value, mask);
285 // CHECK-ARM: define{{.*}}i32 @test_InterlockedExchange_nf(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
286 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw xchg ptr %value, i32 %mask monotonic, align 4
287 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
288 // CHECK-ARM: }
290 LONG test_InterlockedCompareExchange_acq(LONG volatile *Destination, LONG Exchange, LONG Comperand) {
291 return _InterlockedCompareExchange_acq(Destination, Exchange, Comperand);
293 // CHECK-ARM: define{{.*}}i32 @test_InterlockedCompareExchange_acq(ptr{{[a-z_ ]*}}%Destination, i32{{[a-z_ ]*}}%Exchange, i32{{[a-z_ ]*}}%Comperand){{.*}}{
294 // CHECK-ARM: [[TMP:%[0-9]+]] = cmpxchg volatile ptr %Destination, i32 %Comperand, i32 %Exchange acquire acquire, align 4
295 // CHECK-ARM: [[RESULT:%[0-9]+]] = extractvalue { i32, i1 } [[TMP]], 0
296 // CHECK-ARM: ret i32 [[RESULT]]
297 // CHECK-ARM: }
299 LONG test_InterlockedCompareExchange_rel(LONG volatile *Destination, LONG Exchange, LONG Comperand) {
300 return _InterlockedCompareExchange_rel(Destination, Exchange, Comperand);
302 // CHECK-ARM: define{{.*}}i32 @test_InterlockedCompareExchange_rel(ptr{{[a-z_ ]*}}%Destination, i32{{[a-z_ ]*}}%Exchange, i32{{[a-z_ ]*}}%Comperand){{.*}}{
303 // CHECK-ARM: [[TMP:%[0-9]+]] = cmpxchg volatile ptr %Destination, i32 %Comperand, i32 %Exchange release monotonic, align 4
304 // CHECK-ARM: [[RESULT:%[0-9]+]] = extractvalue { i32, i1 } [[TMP]], 0
305 // CHECK-ARM: ret i32 [[RESULT]]
306 // CHECK-ARM: }
308 LONG test_InterlockedCompareExchange_nf(LONG volatile *Destination, LONG Exchange, LONG Comperand) {
309 return _InterlockedCompareExchange_nf(Destination, Exchange, Comperand);
311 // CHECK-ARM: define{{.*}}i32 @test_InterlockedCompareExchange_nf(ptr{{[a-z_ ]*}}%Destination, i32{{[a-z_ ]*}}%Exchange, i32{{[a-z_ ]*}}%Comperand){{.*}}{
312 // CHECK-ARM: [[TMP:%[0-9]+]] = cmpxchg volatile ptr %Destination, i32 %Comperand, i32 %Exchange monotonic monotonic, align 4
313 // CHECK-ARM: [[RESULT:%[0-9]+]] = extractvalue { i32, i1 } [[TMP]], 0
314 // CHECK-ARM: ret i32 [[RESULT]]
315 // CHECK-ARM: }
317 LONG test_InterlockedOr_acq(LONG volatile *value, LONG mask) {
318 return _InterlockedOr_acq(value, mask);
320 // CHECK-ARM: define{{.*}}i32 @test_InterlockedOr_acq(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
321 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw or ptr %value, i32 %mask acquire, align 4
322 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
323 // CHECK-ARM: }
325 LONG test_InterlockedOr_rel(LONG volatile *value, LONG mask) {
326 return _InterlockedOr_rel(value, mask);
328 // CHECK-ARM: define{{.*}}i32 @test_InterlockedOr_rel(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
329 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw or ptr %value, i32 %mask release, align 4
330 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
331 // CHECK-ARM: }
333 LONG test_InterlockedOr_nf(LONG volatile *value, LONG mask) {
334 return _InterlockedOr_nf(value, mask);
336 // CHECK-ARM: define{{.*}}i32 @test_InterlockedOr_nf(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
337 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw or ptr %value, i32 %mask monotonic, align 4
338 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
339 // CHECK-ARM: }
341 LONG test_InterlockedXor_acq(LONG volatile *value, LONG mask) {
342 return _InterlockedXor_acq(value, mask);
344 // CHECK-ARM: define{{.*}}i32 @test_InterlockedXor_acq(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
345 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw xor ptr %value, i32 %mask acquire, align 4
346 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
347 // CHECK-ARM: }
349 LONG test_InterlockedXor_rel(LONG volatile *value, LONG mask) {
350 return _InterlockedXor_rel(value, mask);
352 // CHECK-ARM: define{{.*}}i32 @test_InterlockedXor_rel(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
353 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw xor ptr %value, i32 %mask release, align 4
354 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
355 // CHECK-ARM: }
357 LONG test_InterlockedXor_nf(LONG volatile *value, LONG mask) {
358 return _InterlockedXor_nf(value, mask);
360 // CHECK-ARM: define{{.*}}i32 @test_InterlockedXor_nf(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
361 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw xor ptr %value, i32 %mask monotonic, align 4
362 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
363 // CHECK-ARM: }
365 LONG test_InterlockedAnd_acq(LONG volatile *value, LONG mask) {
366 return _InterlockedAnd_acq(value, mask);
368 // CHECK-ARM: define{{.*}}i32 @test_InterlockedAnd_acq(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
369 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw and ptr %value, i32 %mask acquire, align 4
370 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
371 // CHECK-ARM: }
373 LONG test_InterlockedAnd_rel(LONG volatile *value, LONG mask) {
374 return _InterlockedAnd_rel(value, mask);
376 // CHECK-ARM: define{{.*}}i32 @test_InterlockedAnd_rel(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
377 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw and ptr %value, i32 %mask release, align 4
378 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
379 // CHECK-ARM: }
381 LONG test_InterlockedAnd_nf(LONG volatile *value, LONG mask) {
382 return _InterlockedAnd_nf(value, mask);
384 // CHECK-ARM: define{{.*}}i32 @test_InterlockedAnd_nf(ptr{{[a-z_ ]*}}%value, i32{{[a-z_ ]*}}%mask){{.*}}{
385 // CHECK-ARM: [[RESULT:%[0-9]+]] = atomicrmw and ptr %value, i32 %mask monotonic, align 4
386 // CHECK-ARM: ret i32 [[RESULT:%[0-9]+]]
387 // CHECK-ARM: }
390 LONG test_InterlockedIncrement_acq(LONG volatile *Addend) {
391 return _InterlockedIncrement_acq(Addend);
393 // CHECK-ARM: define{{.*}}i32 @test_InterlockedIncrement_acq(ptr{{[a-z_ ]*}}%Addend){{.*}}{
394 // CHECK-ARM: [[TMP:%[0-9]+]] = atomicrmw add ptr %Addend, i32 1 acquire, align 4
395 // CHECK-ARM: [[RESULT:%[0-9]+]] = add i32 [[TMP]], 1
396 // CHECK-ARM: ret i32 [[RESULT]]
397 // CHECK-ARM: }
399 LONG test_InterlockedIncrement_rel(LONG volatile *Addend) {
400 return _InterlockedIncrement_rel(Addend);
402 // CHECK-ARM: define{{.*}}i32 @test_InterlockedIncrement_rel(ptr{{[a-z_ ]*}}%Addend){{.*}}{
403 // CHECK-ARM: [[TMP:%[0-9]+]] = atomicrmw add ptr %Addend, i32 1 release, align 4
404 // CHECK-ARM: [[RESULT:%[0-9]+]] = add i32 [[TMP]], 1
405 // CHECK-ARM: ret i32 [[RESULT]]
406 // CHECK-ARM: }
408 LONG test_InterlockedIncrement_nf(LONG volatile *Addend) {
409 return _InterlockedIncrement_nf(Addend);
411 // CHECK-ARM: define{{.*}}i32 @test_InterlockedIncrement_nf(ptr{{[a-z_ ]*}}%Addend){{.*}}{
412 // CHECK-ARM: [[TMP:%[0-9]+]] = atomicrmw add ptr %Addend, i32 1 monotonic, align 4
413 // CHECK-ARM: [[RESULT:%[0-9]+]] = add i32 [[TMP]], 1
414 // CHECK-ARM: ret i32 [[RESULT]]
415 // CHECK-ARM: }
417 LONG test_InterlockedDecrement_acq(LONG volatile *Addend) {
418 return _InterlockedDecrement_acq(Addend);
420 // CHECK-ARM: define{{.*}}i32 @test_InterlockedDecrement_acq(ptr{{[a-z_ ]*}}%Addend){{.*}}{
421 // CHECK-ARM: [[TMP:%[0-9]+]] = atomicrmw sub ptr %Addend, i32 1 acquire, align 4
422 // CHECK-ARM: [[RESULT:%[0-9]+]] = add i32 [[TMP]], -1
423 // CHECK-ARM: ret i32 [[RESULT]]
424 // CHECK-ARM: }
426 LONG test_InterlockedDecrement_rel(LONG volatile *Addend) {
427 return _InterlockedDecrement_rel(Addend);
429 // CHECK-ARM: define{{.*}}i32 @test_InterlockedDecrement_rel(ptr{{[a-z_ ]*}}%Addend){{.*}}{
430 // CHECK-ARM: [[TMP:%[0-9]+]] = atomicrmw sub ptr %Addend, i32 1 release, align 4
431 // CHECK-ARM: [[RESULT:%[0-9]+]] = add i32 [[TMP]], -1
432 // CHECK-ARM: ret i32 [[RESULT]]
433 // CHECK-ARM: }
435 LONG test_InterlockedDecrement_nf(LONG volatile *Addend) {
436 return _InterlockedDecrement_nf(Addend);
438 // CHECK-ARM: define{{.*}}i32 @test_InterlockedDecrement_nf(ptr{{[a-z_ ]*}}%Addend){{.*}}{
439 // CHECK-ARM: [[TMP:%[0-9]+]] = atomicrmw sub ptr %Addend, i32 1 monotonic, align 4
440 // CHECK-ARM: [[RESULT:%[0-9]+]] = add i32 [[TMP]], -1
441 // CHECK-ARM: ret i32 [[RESULT]]
442 // CHECK-ARM: }
443 #endif
445 #ifdef __cplusplus
447 #endif
450 // Test constexpr handling.
451 #if defined(__cplusplus) && (__cplusplus >= 201103L)
453 char popcnt16_0[__popcnt16(0x0000) == 0 ? 1 : -1];
454 char popcnt16_1[__popcnt16(0x10F0) == 5 ? 1 : -1];
456 char popcnt_0[__popcnt(0x00000000) == 0 ? 1 : -1];
457 char popcnt_1[__popcnt(0x100000F0) == 5 ? 1 : -1];
459 char popcnt64_0[__popcnt64(0x0000000000000000ULL) == 0 ? 1 : -1];
460 char popcnt64_1[__popcnt64(0xF00000F000000001ULL) == 9 ? 1 : -1];
462 #define BITSIZE(x) (sizeof(x) * 8)
463 char lzcnt16_0[__lzcnt16(1) == BITSIZE(short) - 1 ? 1 : -1];
464 char lzcnt16_1[__lzcnt16(1 << (BITSIZE(short) - 1)) == 0 ? 1 : -1];
465 char lzcnt16_2[__lzcnt16(0) == BITSIZE(short) ? 1 : -1];
467 char lzcnt_0[__lzcnt(1) == BITSIZE(int) - 1 ? 1 : -1];
468 char lzcnt_1[__lzcnt(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];
469 char lzcnt_2[__lzcnt(0) == BITSIZE(int) ? 1 : -1];
471 char lzcnt64_0[__lzcnt64(1ULL) == BITSIZE(__int64) - 1 ? 1 : -1];
472 char lzcnt64_1[__lzcnt64(1ULL << (BITSIZE(__int64) - 1)) == 0 ? 1 : -1];
473 char lzcnt64_2[__lzcnt64(0ULL) == BITSIZE(__int64) ? 1 : -1];
474 #undef BITSIZE
476 #endif