Skip to content

Commit 3346ea4

Browse files
committed
Add support for the Interlocked[Compare]ExchangePointer_{acq|nf|rel} MS intrinsics
1 parent b0ca543 commit 3346ea4

File tree

5 files changed

+120
-30
lines changed

5 files changed

+120
-30
lines changed

clang/include/clang/Basic/BuiltinsAArch64.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ TARGET_HEADER_BUILTIN(_InterlockedExchange_rel, "NiNiD*Ni", "nh", INTRIN_H,
182182
TARGET_HEADER_BUILTIN(_InterlockedExchange64_acq, "LLiLLiD*LLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
183183
TARGET_HEADER_BUILTIN(_InterlockedExchange64_nf, "LLiLLiD*LLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
184184
TARGET_HEADER_BUILTIN(_InterlockedExchange64_rel, "LLiLLiD*LLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
185+
TARGET_HEADER_BUILTIN(_InterlockedExchangePointer_acq, "v*v*D*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
186+
TARGET_HEADER_BUILTIN(_InterlockedExchangePointer_nf, "v*v*D*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
187+
TARGET_HEADER_BUILTIN(_InterlockedExchangePointer_rel, "v*v*D*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
185188

186189
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_acq, "ccD*cc", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
187190
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_nf, "ccD*cc", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
@@ -195,6 +198,8 @@ TARGET_HEADER_BUILTIN(_InterlockedCompareExchange_rel, "NiNiD*NiNi", "nh",
195198
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_acq, "LLiLLiD*LLiLLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
196199
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_nf, "LLiLLiD*LLiLLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
197200
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_rel, "LLiLLiD*LLiLLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
201+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchangePointer_acq, "v*v*D*v*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
202+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchangePointer_rel, "v*v*D*v*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
198203

199204
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange128, "UcLLiD*LLiLLiLLi*", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
200205
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange128_acq,"UcLLiD*LLiLLiLLi*", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")

clang/include/clang/Basic/BuiltinsARM.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ TARGET_HEADER_BUILTIN(_InterlockedExchange_rel, "NiNiD*Ni", "nh", INTRIN_H,
270270
TARGET_HEADER_BUILTIN(_InterlockedExchange64_acq, "LLiLLiD*LLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
271271
TARGET_HEADER_BUILTIN(_InterlockedExchange64_nf, "LLiLLiD*LLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
272272
TARGET_HEADER_BUILTIN(_InterlockedExchange64_rel, "LLiLLiD*LLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
273+
TARGET_HEADER_BUILTIN(_InterlockedExchangePointer_acq, "v*v*D*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
274+
TARGET_HEADER_BUILTIN(_InterlockedExchangePointer_nf, "v*v*D*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
275+
TARGET_HEADER_BUILTIN(_InterlockedExchangePointer_rel, "v*v*D*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
273276

274277
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_acq, "ccD*cc", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
275278
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_nf, "ccD*cc", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
@@ -283,6 +286,8 @@ TARGET_HEADER_BUILTIN(_InterlockedCompareExchange_rel, "NiNiD*NiNi", "nh",
283286
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_acq, "LLiLLiD*LLiLLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
284287
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_nf, "LLiLLiD*LLiLLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
285288
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_rel, "LLiLLiD*LLiLLi", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
289+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchangePointer_acq, "v*v*D*v*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
290+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchangePointer_rel, "v*v*D*v*v*","nh", INTRIN_H, ALL_MS_LANGUAGES, "")
286291

287292
TARGET_HEADER_BUILTIN(_InterlockedOr8_acq, "ccD*c", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")
288293
TARGET_HEADER_BUILTIN(_InterlockedOr8_nf, "ccD*c", "nh", INTRIN_H, ALL_MS_LANGUAGES, "")

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,15 @@ Value *EmitAtomicCmpXchgForMSIntrin(CodeGenFunction &CGF, const CallExpr *E,
509509

510510
Address DestAddr = CheckAtomicAlignment(CGF, E);
511511

512-
auto *Comparand = CGF.EmitScalarExpr(E->getArg(2));
513512
auto *Exchange = CGF.EmitScalarExpr(E->getArg(1));
513+
auto *RTy = Exchange->getType();
514+
515+
auto *Comparand = CGF.EmitScalarExpr(E->getArg(2));
516+
517+
if (RTy->isPointerTy()) {
518+
Exchange = CGF.Builder.CreatePtrToInt(Exchange, CGF.IntPtrTy);
519+
Comparand = CGF.Builder.CreatePtrToInt(Comparand, CGF.IntPtrTy);
520+
}
514521

515522
// For Release ordering, the failure ordering should be Monotonic.
516523
auto FailureOrdering = SuccessOrdering == AtomicOrdering::Release ?
@@ -521,10 +528,16 @@ Value *EmitAtomicCmpXchgForMSIntrin(CodeGenFunction &CGF, const CallExpr *E,
521528
// blocks the few atomics optimizations that LLVM has. If we want to optimize
522529
// _Interlocked* operations in the future, we will have to remove the volatile
523530
// marker.
524-
auto *Result = CGF.Builder.CreateAtomicCmpXchg(
531+
auto *CmpXchg = CGF.Builder.CreateAtomicCmpXchg(
525532
DestAddr, Comparand, Exchange, SuccessOrdering, FailureOrdering);
526-
Result->setVolatile(true);
527-
return CGF.Builder.CreateExtractValue(Result, 0);
533+
CmpXchg->setVolatile(true);
534+
535+
auto *Result = CGF.Builder.CreateExtractValue(CmpXchg, 0);
536+
if (RTy->isPointerTy()) {
537+
Result = CGF.Builder.CreateIntToPtr(Result, RTy);
538+
}
539+
540+
return Result;
528541
}
529542

530543
// 64-bit Microsoft platforms support 128 bit cmpxchg operations. They are
@@ -1595,6 +1608,7 @@ enum class CodeGenFunction::MSVCIntrin {
15951608
_BitScanForward,
15961609
_BitScanReverse,
15971610
_InterlockedAnd,
1611+
_InterlockedCompareExchange,
15981612
_InterlockedDecrement,
15991613
_InterlockedExchange,
16001614
_InterlockedExchangeAdd,
@@ -1680,26 +1694,31 @@ translateArmToMsvcIntrin(unsigned BuiltinID) {
16801694
case clang::ARM::BI_InterlockedExchange16_acq:
16811695
case clang::ARM::BI_InterlockedExchange_acq:
16821696
case clang::ARM::BI_InterlockedExchange64_acq:
1697+
case clang::ARM::BI_InterlockedExchangePointer_acq:
16831698
return MSVCIntrin::_InterlockedExchange_acq;
16841699
case clang::ARM::BI_InterlockedExchange8_rel:
16851700
case clang::ARM::BI_InterlockedExchange16_rel:
16861701
case clang::ARM::BI_InterlockedExchange_rel:
16871702
case clang::ARM::BI_InterlockedExchange64_rel:
1703+
case clang::ARM::BI_InterlockedExchangePointer_rel:
16881704
return MSVCIntrin::_InterlockedExchange_rel;
16891705
case clang::ARM::BI_InterlockedExchange8_nf:
16901706
case clang::ARM::BI_InterlockedExchange16_nf:
16911707
case clang::ARM::BI_InterlockedExchange_nf:
16921708
case clang::ARM::BI_InterlockedExchange64_nf:
1709+
case clang::ARM::BI_InterlockedExchangePointer_nf:
16931710
return MSVCIntrin::_InterlockedExchange_nf;
16941711
case clang::ARM::BI_InterlockedCompareExchange8_acq:
16951712
case clang::ARM::BI_InterlockedCompareExchange16_acq:
16961713
case clang::ARM::BI_InterlockedCompareExchange_acq:
16971714
case clang::ARM::BI_InterlockedCompareExchange64_acq:
1715+
case clang::ARM::BI_InterlockedCompareExchangePointer_acq:
16981716
return MSVCIntrin::_InterlockedCompareExchange_acq;
16991717
case clang::ARM::BI_InterlockedCompareExchange8_rel:
17001718
case clang::ARM::BI_InterlockedCompareExchange16_rel:
17011719
case clang::ARM::BI_InterlockedCompareExchange_rel:
17021720
case clang::ARM::BI_InterlockedCompareExchange64_rel:
1721+
case clang::ARM::BI_InterlockedCompareExchangePointer_rel:
17031722
return MSVCIntrin::_InterlockedCompareExchange_rel;
17041723
case clang::ARM::BI_InterlockedCompareExchange8_nf:
17051724
case clang::ARM::BI_InterlockedCompareExchange16_nf:
@@ -1826,26 +1845,31 @@ translateAarch64ToMsvcIntrin(unsigned BuiltinID) {
18261845
case clang::AArch64::BI_InterlockedExchange16_acq:
18271846
case clang::AArch64::BI_InterlockedExchange_acq:
18281847
case clang::AArch64::BI_InterlockedExchange64_acq:
1848+
case clang::AArch64::BI_InterlockedExchangePointer_acq:
18291849
return MSVCIntrin::_InterlockedExchange_acq;
18301850
case clang::AArch64::BI_InterlockedExchange8_rel:
18311851
case clang::AArch64::BI_InterlockedExchange16_rel:
18321852
case clang::AArch64::BI_InterlockedExchange_rel:
18331853
case clang::AArch64::BI_InterlockedExchange64_rel:
1854+
case clang::AArch64::BI_InterlockedExchangePointer_rel:
18341855
return MSVCIntrin::_InterlockedExchange_rel;
18351856
case clang::AArch64::BI_InterlockedExchange8_nf:
18361857
case clang::AArch64::BI_InterlockedExchange16_nf:
18371858
case clang::AArch64::BI_InterlockedExchange_nf:
18381859
case clang::AArch64::BI_InterlockedExchange64_nf:
1860+
case clang::AArch64::BI_InterlockedExchangePointer_nf:
18391861
return MSVCIntrin::_InterlockedExchange_nf;
18401862
case clang::AArch64::BI_InterlockedCompareExchange8_acq:
18411863
case clang::AArch64::BI_InterlockedCompareExchange16_acq:
18421864
case clang::AArch64::BI_InterlockedCompareExchange_acq:
18431865
case clang::AArch64::BI_InterlockedCompareExchange64_acq:
1866+
case clang::AArch64::BI_InterlockedCompareExchangePointer_acq:
18441867
return MSVCIntrin::_InterlockedCompareExchange_acq;
18451868
case clang::AArch64::BI_InterlockedCompareExchange8_rel:
18461869
case clang::AArch64::BI_InterlockedCompareExchange16_rel:
18471870
case clang::AArch64::BI_InterlockedCompareExchange_rel:
18481871
case clang::AArch64::BI_InterlockedCompareExchange64_rel:
1872+
case clang::AArch64::BI_InterlockedCompareExchangePointer_rel:
18491873
return MSVCIntrin::_InterlockedCompareExchange_rel;
18501874
case clang::AArch64::BI_InterlockedCompareExchange8_nf:
18511875
case clang::AArch64::BI_InterlockedCompareExchange16_nf:
@@ -2048,6 +2072,8 @@ Value *CodeGenFunction::EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID,
20482072
case MSVCIntrin::_InterlockedExchange_nf:
20492073
return MakeBinaryAtomicValue(*this, AtomicRMWInst::Xchg, E,
20502074
AtomicOrdering::Monotonic);
2075+
case MSVCIntrin::_InterlockedCompareExchange:
2076+
return EmitAtomicCmpXchgForMSIntrin(*this, E);
20512077
case MSVCIntrin::_InterlockedCompareExchange_acq:
20522078
return EmitAtomicCmpXchgForMSIntrin(*this, E, AtomicOrdering::Acquire);
20532079
case MSVCIntrin::_InterlockedCompareExchange_rel:
@@ -5695,32 +5721,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
56955721
return RValue::get(
56965722
EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchange, E));
56975723
case Builtin::BI_InterlockedCompareExchangePointer:
5698-
case Builtin::BI_InterlockedCompareExchangePointer_nf: {
5699-
llvm::Type *RTy;
5700-
llvm::IntegerType *IntType = IntegerType::get(
5701-
getLLVMContext(), getContext().getTypeSize(E->getType()));
5702-
5703-
Address DestAddr = CheckAtomicAlignment(*this, E);
5704-
5705-
llvm::Value *Exchange = EmitScalarExpr(E->getArg(1));
5706-
RTy = Exchange->getType();
5707-
Exchange = Builder.CreatePtrToInt(Exchange, IntType);
5708-
5709-
llvm::Value *Comparand =
5710-
Builder.CreatePtrToInt(EmitScalarExpr(E->getArg(2)), IntType);
5711-
5712-
auto Ordering =
5713-
BuiltinID == Builtin::BI_InterlockedCompareExchangePointer_nf ?
5714-
AtomicOrdering::Monotonic : AtomicOrdering::SequentiallyConsistent;
5715-
5716-
auto Result = Builder.CreateAtomicCmpXchg(DestAddr, Comparand, Exchange,
5717-
Ordering, Ordering);
5718-
Result->setVolatile(true);
5719-
5720-
return RValue::get(Builder.CreateIntToPtr(Builder.CreateExtractValue(Result,
5721-
0),
5722-
RTy));
5723-
}
5724+
return RValue::get(
5725+
EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedCompareExchange, E));
5726+
case Builtin::BI_InterlockedCompareExchangePointer_nf:
5727+
return RValue::get(
5728+
EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedCompareExchange_nf, E));
57245729
case Builtin::BI_InterlockedCompareExchange8:
57255730
case Builtin::BI_InterlockedCompareExchange16:
57265731
case Builtin::BI_InterlockedCompareExchange:

clang/lib/Headers/intrin0.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ long _InterlockedExchange_rel(long volatile *_Target, long _Value);
207207
__int64 _InterlockedExchange64_acq(__int64 volatile *_Target, __int64 _Value);
208208
__int64 _InterlockedExchange64_nf(__int64 volatile *_Target, __int64 _Value);
209209
__int64 _InterlockedExchange64_rel(__int64 volatile *_Target, __int64 _Value);
210+
void *_InterlockedExchangePointer_acq(void *volatile *_Target, void *_Value);
211+
void *_InterlockedExchangePointer_nf(void *volatile *_Target, void *_Value);
212+
void *_InterlockedExchangePointer_rel(void *volatile *_Target, void *_Value);
210213

211214
/*----------------------------------------------------------------------------*\
212215
|* Interlocked Compare Exchange
@@ -237,6 +240,12 @@ __int64 _InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
237240
__int64 _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
238241
__int64 _Exchange,
239242
__int64 _Comparand);
243+
void *_InterlockedCompareExchangePointer_acq(void *volatile *_Destination,
244+
void *_Exchange, void *_Comparand);
245+
void *_InterlockedCompareExchangePointer_nf(void *volatile *_Destination,
246+
void *_Exchange, void *_Comparand);
247+
void *_InterlockedCompareExchangePointer_rel(void *volatile *_Destination,
248+
void *_Exchange, void *_Comparand);
240249
#endif
241250

242251
#ifdef __cplusplus

clang/test/CodeGen/ms-intrinsics.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,41 @@ void *test_InterlockedExchangePointer(void * volatile *Target, void *Value) {
221221
// CHECK: ret ptr %[[RESULT]]
222222
// CHECK: }
223223

224+
#if defined(__arm__) || defined(__aarch64__)
225+
void *test_InterlockedExchangePointer_acq(void * volatile *Target, void *Value) {
226+
return _InterlockedExchangePointer_acq(Target, Value);
227+
}
228+
229+
// CHECK-ARM-ARM64: define{{.*}}ptr @test_InterlockedExchangePointer_acq(ptr {{[a-z_ ]*}}%Target, ptr {{[a-z_ ]*}}%Value){{.*}}{
230+
// CHECK-ARM-ARM64: %[[VALUE:[0-9]+]] = ptrtoint ptr %Value to [[iPTR:i[0-9]+]]
231+
// CHECK-ARM-ARM64: %[[EXCHANGE:[0-9]+]] = atomicrmw xchg ptr %Target, [[iPTR]] %[[VALUE]] acquire, align {{4|8}}
232+
// CHECK-ARM-ARM64: %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXCHANGE]] to ptr
233+
// CHECK-ARM-ARM64: ret ptr %[[RESULT]]
234+
// CHECK-ARM-ARM64: }
235+
236+
void *test_InterlockedExchangePointer_nf(void * volatile *Target, void *Value) {
237+
return _InterlockedExchangePointer_nf(Target, Value);
238+
}
239+
240+
// CHECK-ARM-ARM64: define{{.*}}ptr @test_InterlockedExchangePointer_nf(ptr {{[a-z_ ]*}}%Target, ptr {{[a-z_ ]*}}%Value){{.*}}{
241+
// CHECK-ARM-ARM64: %[[VALUE:[0-9]+]] = ptrtoint ptr %Value to [[iPTR]]
242+
// CHECK-ARM-ARM64: %[[EXCHANGE:[0-9]+]] = atomicrmw xchg ptr %Target, [[iPTR]] %[[VALUE]] monotonic, align {{4|8}}
243+
// CHECK-ARM-ARM64: %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXCHANGE]] to ptr
244+
// CHECK-ARM-ARM64: ret ptr %[[RESULT]]
245+
// CHECK-ARM-ARM64: }
246+
247+
void *test_InterlockedExchangePointer_rel(void * volatile *Target, void *Value) {
248+
return _InterlockedExchangePointer_rel(Target, Value);
249+
}
250+
251+
// CHECK-ARM-ARM64: define{{.*}}ptr @test_InterlockedExchangePointer_rel(ptr {{[a-z_ ]*}}%Target, ptr {{[a-z_ ]*}}%Value){{.*}}{
252+
// CHECK-ARM-ARM64: %[[VALUE:[0-9]+]] = ptrtoint ptr %Value to [[iPTR]]
253+
// CHECK-ARM-ARM64: %[[EXCHANGE:[0-9]+]] = atomicrmw xchg ptr %Target, [[iPTR]] %[[VALUE]] release, align {{4|8}}
254+
// CHECK-ARM-ARM64: %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXCHANGE]] to ptr
255+
// CHECK-ARM-ARM64: ret ptr %[[RESULT]]
256+
// CHECK-ARM-ARM64: }
257+
#endif
258+
224259
void *test_InterlockedCompareExchangePointer(void * volatile *Destination,
225260
void *Exchange, void *Comparand) {
226261
return _InterlockedCompareExchangePointer(Destination, Exchange, Comparand);
@@ -249,6 +284,37 @@ void *test_InterlockedCompareExchangePointer_nf(void * volatile *Destination,
249284
// CHECK: ret ptr %[[RESULT:[0-9]+]]
250285
// CHECK: }
251286

287+
#if defined(__arm__) || defined(__aarch64__)
288+
void *test_InterlockedCompareExchangePointer_acq(void * volatile *Destination,
289+
void *Exchange, void *Comparand) {
290+
return _InterlockedCompareExchangePointer_acq(Destination, Exchange, Comparand);
291+
}
292+
293+
// CHECK-ARM-ARM64: define{{.*}}ptr @test_InterlockedCompareExchangePointer_acq(ptr {{[a-z_ ]*}}%Destination, ptr {{[a-z_ ]*}}%Exchange, ptr {{[a-z_ ]*}}%Comparand){{.*}}{
294+
// CHECK-ARM-ARM64: %[[EXCHANGE:[0-9]+]] = ptrtoint ptr %Exchange to [[iPTR]]
295+
// CHECK-ARM-ARM64: %[[COMPARAND:[0-9]+]] = ptrtoint ptr %Comparand to [[iPTR]]
296+
// CHECK-ARM-ARM64: %[[XCHG:[0-9]+]] = cmpxchg volatile ptr %[[DEST:.+]], [[iPTR]] %[[COMPARAND:[0-9]+]], [[iPTR]] %[[EXCHANGE:[0-9]+]] acquire acquire, align {{4|8}}
297+
// CHECK-ARM-ARM64: %[[EXTRACT:[0-9]+]] = extractvalue { [[iPTR]], i1 } %[[XCHG]], 0
298+
// CHECK-ARM-ARM64: %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXTRACT]] to ptr
299+
// CHECK-ARM-ARM64: ret ptr %[[RESULT:[0-9]+]]
300+
// CHECK-ARM-ARM64: }
301+
302+
303+
void *test_InterlockedCompareExchangePointer_rel(void * volatile *Destination,
304+
void *Exchange, void *Comparand) {
305+
return _InterlockedCompareExchangePointer_rel(Destination, Exchange, Comparand);
306+
}
307+
308+
// CHECK-ARM-ARM64: define{{.*}}ptr @test_InterlockedCompareExchangePointer_rel(ptr {{[a-z_ ]*}}%Destination, ptr {{[a-z_ ]*}}%Exchange, ptr {{[a-z_ ]*}}%Comparand){{.*}}{
309+
// CHECK-ARM-ARM64: %[[EXCHANGE:[0-9]+]] = ptrtoint ptr %Exchange to [[iPTR]]
310+
// CHECK-ARM-ARM64: %[[COMPARAND:[0-9]+]] = ptrtoint ptr %Comparand to [[iPTR]]
311+
// CHECK-ARM-ARM64: %[[XCHG:[0-9]+]] = cmpxchg volatile ptr %[[DEST:.+]], [[iPTR]] %[[COMPARAND:[0-9]+]], [[iPTR]] %[[EXCHANGE:[0-9]+]] release monotonic, align {{4|8}}
312+
// CHECK-ARM-ARM64: %[[EXTRACT:[0-9]+]] = extractvalue { [[iPTR]], i1 } %[[XCHG]], 0
313+
// CHECK-ARM-ARM64: %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXTRACT]] to ptr
314+
// CHECK-ARM-ARM64: ret ptr %[[RESULT:[0-9]+]]
315+
// CHECK-ARM-ARM64: }
316+
#endif
317+
252318
char test_InterlockedExchange8(char volatile *value, char mask) {
253319
return _InterlockedExchange8(value, mask);
254320
}

0 commit comments

Comments
 (0)