Skip to content

Commit 6b88068

Browse files
author
Mandeep Singh Grang
committedNov 6, 2018
[COFF, ARM64] Implement InterlockedCompareExchange*_* builtins
Summary: This is third in a series of patches to move intrinsic definitions out of intrin.h. Reviewers: rnk, efriedma, mstorsjo, TomTan Reviewed By: efriedma Subscribers: javed.absar, kristof.beyls, chrib, jfb, kristina, cfe-commits Differential Revision: https://reviews.llvm.org/D54062 llvm-svn: 346189
1 parent 17057b5 commit 6b88068

File tree

5 files changed

+241
-94
lines changed

5 files changed

+241
-94
lines changed
 

‎clang/include/clang/Basic/BuiltinsAArch64.def

+13
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ TARGET_HEADER_BUILTIN(_InterlockedExchange64_acq, "LLiLLiD*LLi", "nh", "intrin.h
130130
TARGET_HEADER_BUILTIN(_InterlockedExchange64_nf, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
131131
TARGET_HEADER_BUILTIN(_InterlockedExchange64_rel, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
132132

133+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_acq, "ccD*cc", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
134+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_nf, "ccD*cc", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
135+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_rel, "ccD*cc", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
136+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange16_acq, "ssD*ss", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
137+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange16_nf, "ssD*ss", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
138+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange16_rel, "ssD*ss", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
139+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange_acq, "LiLiD*LiLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
140+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange_nf, "LiLiD*LiLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
141+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange_rel, "LiLiD*LiLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
142+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_acq, "LLiLLiD*LLiLLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
143+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_nf, "LLiLLiD*LLiLLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
144+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_rel, "LLiLLiD*LLiLLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
145+
133146
TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
134147
TARGET_HEADER_BUILTIN(__getReg, "ULLii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
135148
TARGET_HEADER_BUILTIN(_ReadStatusReg, "ii", "nh", "intrin.h", ALL_MS_LANGUAGES, "")

‎clang/include/clang/Basic/BuiltinsARM.def

+13
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,19 @@ TARGET_HEADER_BUILTIN(_InterlockedExchange64_acq, "LLiLLiD*LLi", "nh", "intrin.h
256256
TARGET_HEADER_BUILTIN(_InterlockedExchange64_nf, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
257257
TARGET_HEADER_BUILTIN(_InterlockedExchange64_rel, "LLiLLiD*LLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
258258

259+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_acq, "ccD*cc", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
260+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_nf, "ccD*cc", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
261+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange8_rel, "ccD*cc", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
262+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange16_acq, "ssD*ss", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
263+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange16_nf, "ssD*ss", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
264+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange16_rel, "ssD*ss", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
265+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange_acq, "LiLiD*LiLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
266+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange_nf, "LiLiD*LiLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
267+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange_rel, "LiLiD*LiLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
268+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_acq, "LLiLLiD*LLiLLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
269+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_nf, "LLiLLiD*LLiLLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
270+
TARGET_HEADER_BUILTIN(_InterlockedCompareExchange64_rel, "LLiLLiD*LLiLLi", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
271+
259272
#undef BUILTIN
260273
#undef LANGBUILTIN
261274
#undef TARGET_HEADER_BUILTIN

‎clang/lib/CodeGen/CGBuiltin.cpp

+83-10
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ static RValue EmitBinaryAtomicPost(CodeGenFunction &CGF,
200200
/// cmpxchg result or the old value.
201201
///
202202
/// @returns result of cmpxchg, according to ReturnBool
203+
///
204+
/// Note: In order to lower Microsoft's _InterlockedCompareExchange* intrinsics
205+
/// invoke the function EmitAtomicCmpXchgForMSIntrin.
203206
static Value *MakeAtomicCmpXchgValue(CodeGenFunction &CGF, const CallExpr *E,
204207
bool ReturnBool) {
205208
QualType T = ReturnBool ? E->getArg(1)->getType() : E->getType();
@@ -230,6 +233,45 @@ static Value *MakeAtomicCmpXchgValue(CodeGenFunction &CGF, const CallExpr *E,
230233
ValueType);
231234
}
232235

236+
/// This function should be invoked to emit atomic cmpxchg for Microsoft's
237+
/// _InterlockedCompareExchange* intrinsics which have the following signature:
238+
/// T _InterlockedCompareExchange(T volatile *Destination,
239+
/// T Exchange,
240+
/// T Comparand);
241+
///
242+
/// Whereas the llvm 'cmpxchg' instruction has the following syntax:
243+
/// cmpxchg *Destination, Comparand, Exchange.
244+
/// So we need to swap Comparand and Exchange when invoking
245+
/// CreateAtomicCmpXchg. That is the reason we could not use the above utility
246+
/// function MakeAtomicCmpXchgValue since it expects the arguments to be
247+
/// already swapped.
248+
249+
static
250+
Value *EmitAtomicCmpXchgForMSIntrin(CodeGenFunction &CGF, const CallExpr *E,
251+
AtomicOrdering SuccessOrdering = AtomicOrdering::SequentiallyConsistent) {
252+
auto T = E->getType();
253+
assert(E->getArg(0)->getType()->isPointerType());
254+
assert(CGF.getContext().hasSameUnqualifiedType(T,
255+
E->getArg(0)->getType()->getPointeeType()));
256+
assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType()));
257+
assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(2)->getType()));
258+
259+
auto *Destination = CGF.EmitScalarExpr(E->getArg(0));
260+
auto *Comparand = CGF.EmitScalarExpr(E->getArg(2));
261+
auto *Exchange = CGF.EmitScalarExpr(E->getArg(1));
262+
263+
// For Release ordering, the failure ordering should be Monotonic.
264+
auto FailureOrdering = SuccessOrdering == AtomicOrdering::Release ?
265+
AtomicOrdering::Monotonic :
266+
SuccessOrdering;
267+
268+
auto *Result = CGF.Builder.CreateAtomicCmpXchg(
269+
Destination, Comparand, Exchange,
270+
SuccessOrdering, FailureOrdering);
271+
Result->setVolatile(true);
272+
return CGF.Builder.CreateExtractValue(Result, 0);
273+
}
274+
233275
// Emit a simple mangled intrinsic that has 1 argument and a return type
234276
// matching the argument type.
235277
static Value *emitUnaryBuiltin(CodeGenFunction &CGF,
@@ -754,6 +796,9 @@ enum class CodeGenFunction::MSVCIntrin {
754796
_InterlockedExchange_acq,
755797
_InterlockedExchange_rel,
756798
_InterlockedExchange_nf,
799+
_InterlockedCompareExchange_acq,
800+
_InterlockedCompareExchange_rel,
801+
_InterlockedCompareExchange_nf,
757802
__fastfail,
758803
};
759804

@@ -838,6 +883,12 @@ Value *CodeGenFunction::EmitMSVCBuiltinExpr(MSVCIntrin BuiltinID,
838883
case MSVCIntrin::_InterlockedExchange_nf:
839884
return MakeBinaryAtomicValue(*this, AtomicRMWInst::Xchg, E,
840885
AtomicOrdering::Monotonic);
886+
case MSVCIntrin::_InterlockedCompareExchange_acq:
887+
return EmitAtomicCmpXchgForMSIntrin(*this, E, AtomicOrdering::Acquire);
888+
case MSVCIntrin::_InterlockedCompareExchange_rel:
889+
return EmitAtomicCmpXchgForMSIntrin(*this, E, AtomicOrdering::Release);
890+
case MSVCIntrin::_InterlockedCompareExchange_nf:
891+
return EmitAtomicCmpXchgForMSIntrin(*this, E, AtomicOrdering::Monotonic);
841892

842893
case MSVCIntrin::_InterlockedDecrement: {
843894
llvm::Type *IntTy = ConvertType(E->getType());
@@ -3059,16 +3110,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
30593110
case Builtin::BI_InterlockedCompareExchange8:
30603111
case Builtin::BI_InterlockedCompareExchange16:
30613112
case Builtin::BI_InterlockedCompareExchange:
3062-
case Builtin::BI_InterlockedCompareExchange64: {
3063-
AtomicCmpXchgInst *CXI = Builder.CreateAtomicCmpXchg(
3064-
EmitScalarExpr(E->getArg(0)),
3065-
EmitScalarExpr(E->getArg(2)),
3066-
EmitScalarExpr(E->getArg(1)),
3067-
AtomicOrdering::SequentiallyConsistent,
3068-
AtomicOrdering::SequentiallyConsistent);
3069-
CXI->setVolatile(true);
3070-
return RValue::get(Builder.CreateExtractValue(CXI, 0));
3071-
}
3113+
case Builtin::BI_InterlockedCompareExchange64:
3114+
return RValue::get(EmitAtomicCmpXchgForMSIntrin(*this, E));
30723115
case Builtin::BI_InterlockedIncrement16:
30733116
case Builtin::BI_InterlockedIncrement:
30743117
return RValue::get(
@@ -6159,6 +6202,21 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned BuiltinID,
61596202
case ARM::BI_InterlockedExchange_nf:
61606203
case ARM::BI_InterlockedExchange64_nf:
61616204
return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchange_nf, E);
6205+
case ARM::BI_InterlockedCompareExchange8_acq:
6206+
case ARM::BI_InterlockedCompareExchange16_acq:
6207+
case ARM::BI_InterlockedCompareExchange_acq:
6208+
case ARM::BI_InterlockedCompareExchange64_acq:
6209+
return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedCompareExchange_acq, E);
6210+
case ARM::BI_InterlockedCompareExchange8_rel:
6211+
case ARM::BI_InterlockedCompareExchange16_rel:
6212+
case ARM::BI_InterlockedCompareExchange_rel:
6213+
case ARM::BI_InterlockedCompareExchange64_rel:
6214+
return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedCompareExchange_rel, E);
6215+
case ARM::BI_InterlockedCompareExchange8_nf:
6216+
case ARM::BI_InterlockedCompareExchange16_nf:
6217+
case ARM::BI_InterlockedCompareExchange_nf:
6218+
case ARM::BI_InterlockedCompareExchange64_nf:
6219+
return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedCompareExchange_nf, E);
61626220
}
61636221

61646222
// Get the last argument, which specifies the vector type.
@@ -8675,6 +8733,21 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
86758733
case AArch64::BI_InterlockedExchange_nf:
86768734
case AArch64::BI_InterlockedExchange64_nf:
86778735
return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedExchange_nf, E);
8736+
case AArch64::BI_InterlockedCompareExchange8_acq:
8737+
case AArch64::BI_InterlockedCompareExchange16_acq:
8738+
case AArch64::BI_InterlockedCompareExchange_acq:
8739+
case AArch64::BI_InterlockedCompareExchange64_acq:
8740+
return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedCompareExchange_acq, E);
8741+
case AArch64::BI_InterlockedCompareExchange8_rel:
8742+
case AArch64::BI_InterlockedCompareExchange16_rel:
8743+
case AArch64::BI_InterlockedCompareExchange_rel:
8744+
case AArch64::BI_InterlockedCompareExchange64_rel:
8745+
return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedCompareExchange_rel, E);
8746+
case AArch64::BI_InterlockedCompareExchange8_nf:
8747+
case AArch64::BI_InterlockedCompareExchange16_nf:
8748+
case AArch64::BI_InterlockedCompareExchange_nf:
8749+
case AArch64::BI_InterlockedCompareExchange64_nf:
8750+
return EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedCompareExchange_nf, E);
86788751

86798752
case AArch64::BI_InterlockedAdd: {
86808753
Value *Arg0 = EmitScalarExpr(E->getArg(0));

‎clang/lib/Headers/intrin.h

+24-84
Original file line numberDiff line numberDiff line change
@@ -621,90 +621,30 @@ __int64 _InterlockedExchange64_rel(__int64 volatile *_Target, __int64 _Value);
621621
|* Interlocked Compare Exchange
622622
\*----------------------------------------------------------------------------*/
623623
#if defined(__arm__) || defined(__aarch64__)
624-
static __inline__ char __DEFAULT_FN_ATTRS
625-
_InterlockedCompareExchange8_acq(char volatile *_Destination,
626-
char _Exchange, char _Comparand) {
627-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
628-
__ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
629-
return _Comparand;
630-
}
631-
static __inline__ char __DEFAULT_FN_ATTRS
632-
_InterlockedCompareExchange8_nf(char volatile *_Destination,
633-
char _Exchange, char _Comparand) {
634-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
635-
__ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
636-
return _Comparand;
637-
}
638-
static __inline__ char __DEFAULT_FN_ATTRS
639-
_InterlockedCompareExchange8_rel(char volatile *_Destination,
640-
char _Exchange, char _Comparand) {
641-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
642-
__ATOMIC_SEQ_CST, __ATOMIC_RELEASE);
643-
return _Comparand;
644-
}
645-
static __inline__ short __DEFAULT_FN_ATTRS
646-
_InterlockedCompareExchange16_acq(short volatile *_Destination,
647-
short _Exchange, short _Comparand) {
648-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
649-
__ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
650-
return _Comparand;
651-
}
652-
static __inline__ short __DEFAULT_FN_ATTRS
653-
_InterlockedCompareExchange16_nf(short volatile *_Destination,
654-
short _Exchange, short _Comparand) {
655-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
656-
__ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
657-
return _Comparand;
658-
}
659-
static __inline__ short __DEFAULT_FN_ATTRS
660-
_InterlockedCompareExchange16_rel(short volatile *_Destination,
661-
short _Exchange, short _Comparand) {
662-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
663-
__ATOMIC_SEQ_CST, __ATOMIC_RELEASE);
664-
return _Comparand;
665-
}
666-
static __inline__ long __DEFAULT_FN_ATTRS
667-
_InterlockedCompareExchange_acq(long volatile *_Destination,
668-
long _Exchange, long _Comparand) {
669-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
670-
__ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
671-
return _Comparand;
672-
}
673-
static __inline__ long __DEFAULT_FN_ATTRS
674-
_InterlockedCompareExchange_nf(long volatile *_Destination,
675-
long _Exchange, long _Comparand) {
676-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
677-
__ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
678-
return _Comparand;
679-
}
680-
static __inline__ long __DEFAULT_FN_ATTRS
681-
_InterlockedCompareExchange_rel(long volatile *_Destination,
682-
long _Exchange, long _Comparand) {
683-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
684-
__ATOMIC_SEQ_CST, __ATOMIC_RELEASE);
685-
return _Comparand;
686-
}
687-
static __inline__ __int64 __DEFAULT_FN_ATTRS
688-
_InterlockedCompareExchange64_acq(__int64 volatile *_Destination,
689-
__int64 _Exchange, __int64 _Comparand) {
690-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
691-
__ATOMIC_SEQ_CST, __ATOMIC_ACQUIRE);
692-
return _Comparand;
693-
}
694-
static __inline__ __int64 __DEFAULT_FN_ATTRS
695-
_InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
696-
__int64 _Exchange, __int64 _Comparand) {
697-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
698-
__ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
699-
return _Comparand;
700-
}
701-
static __inline__ __int64 __DEFAULT_FN_ATTRS
702-
_InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
703-
__int64 _Exchange, __int64 _Comparand) {
704-
__atomic_compare_exchange(_Destination, &_Comparand, &_Exchange, 0,
705-
__ATOMIC_SEQ_CST, __ATOMIC_RELEASE);
706-
return _Comparand;
707-
}
624+
char _InterlockedCompareExchange8_acq(char volatile *_Destination,
625+
char _Exchange, char _Comparand);
626+
char _InterlockedCompareExchange8_nf(char volatile *_Destination,
627+
char _Exchange, char _Comparand);
628+
char _InterlockedCompareExchange8_rel(char volatile *_Destination,
629+
char _Exchange, char _Comparand);
630+
short _InterlockedCompareExchange16_acq(short volatile *_Destination,
631+
short _Exchange, short _Comparand);
632+
short _InterlockedCompareExchange16_nf(short volatile *_Destination,
633+
short _Exchange, short _Comparand);
634+
short _InterlockedCompareExchange16_rel(short volatile *_Destination,
635+
short _Exchange, short _Comparand);
636+
long _InterlockedCompareExchange_acq(long volatile *_Destination,
637+
long _Exchange, long _Comparand);
638+
long _InterlockedCompareExchange_nf(long volatile *_Destination,
639+
long _Exchange, long _Comparand);
640+
long _InterlockedCompareExchange_rel(long volatile *_Destination,
641+
long _Exchange, long _Comparand);
642+
__int64 _InterlockedCompareExchange64_acq(__int64 volatile *_Destination,
643+
__int64 _Exchange, __int64 _Comparand);
644+
__int64 _InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
645+
__int64 _Exchange, __int64 _Comparand);
646+
__int64 _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
647+
__int64 _Exchange, __int64 _Comparand);
708648
#endif
709649

710650
/*----------------------------------------------------------------------------*\

‎clang/test/CodeGen/ms-intrinsics.c

+108
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,114 @@ __int64 test_InterlockedExchange64_nf(__int64 volatile *value, __int64 mask) {
782782
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = atomicrmw xchg i64* %value, i64 %mask monotonic
783783
// CHECK-ARM-ARM64: ret i64 [[RESULT:%[0-9]+]]
784784
// CHECK-ARM-ARM64: }
785+
786+
char test_InterlockedCompareExchange8_acq(char volatile *Destination, char Exchange, char Comperand) {
787+
return _InterlockedCompareExchange8_acq(Destination, Exchange, Comperand);
788+
}
789+
// CHECK-ARM-ARM64: define{{.*}}i8 @test_InterlockedCompareExchange8_acq(i8*{{[a-z_ ]*}}%Destination, i8{{[a-z_ ]*}}%Exchange, i8{{[a-z_ ]*}}%Comperand){{.*}}{
790+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i8* %Destination, i8 %Comperand, i8 %Exchange acquire acquire
791+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i8, i1 } [[TMP]], 0
792+
// CHECK-ARM-ARM64: ret i8 [[RESULT]]
793+
// CHECK-ARM-ARM64: }
794+
795+
char test_InterlockedCompareExchange8_rel(char volatile *Destination, char Exchange, char Comperand) {
796+
return _InterlockedCompareExchange8_rel(Destination, Exchange, Comperand);
797+
}
798+
// CHECK-ARM-ARM64: define{{.*}}i8 @test_InterlockedCompareExchange8_rel(i8*{{[a-z_ ]*}}%Destination, i8{{[a-z_ ]*}}%Exchange, i8{{[a-z_ ]*}}%Comperand){{.*}}{
799+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i8* %Destination, i8 %Comperand, i8 %Exchange release monotonic
800+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i8, i1 } [[TMP]], 0
801+
// CHECK-ARM-ARM64: ret i8 [[RESULT]]
802+
// CHECK-ARM-ARM64: }
803+
804+
char test_InterlockedCompareExchange8_nf(char volatile *Destination, char Exchange, char Comperand) {
805+
return _InterlockedCompareExchange8_nf(Destination, Exchange, Comperand);
806+
}
807+
// CHECK-ARM-ARM64: define{{.*}}i8 @test_InterlockedCompareExchange8_nf(i8*{{[a-z_ ]*}}%Destination, i8{{[a-z_ ]*}}%Exchange, i8{{[a-z_ ]*}}%Comperand){{.*}}{
808+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i8* %Destination, i8 %Comperand, i8 %Exchange monotonic monotonic
809+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i8, i1 } [[TMP]], 0
810+
// CHECK-ARM-ARM64: ret i8 [[RESULT]]
811+
// CHECK-ARM-ARM64: }
812+
813+
short test_InterlockedCompareExchange16_acq(short volatile *Destination, short Exchange, short Comperand) {
814+
return _InterlockedCompareExchange16_acq(Destination, Exchange, Comperand);
815+
}
816+
// CHECK-ARM-ARM64: define{{.*}}i16 @test_InterlockedCompareExchange16_acq(i16*{{[a-z_ ]*}}%Destination, i16{{[a-z_ ]*}}%Exchange, i16{{[a-z_ ]*}}%Comperand){{.*}}{
817+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i16* %Destination, i16 %Comperand, i16 %Exchange acquire acquire
818+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i16, i1 } [[TMP]], 0
819+
// CHECK-ARM-ARM64: ret i16 [[RESULT]]
820+
// CHECK-ARM-ARM64: }
821+
822+
short test_InterlockedCompareExchange16_rel(short volatile *Destination, short Exchange, short Comperand) {
823+
return _InterlockedCompareExchange16_rel(Destination, Exchange, Comperand);
824+
}
825+
// CHECK-ARM-ARM64: define{{.*}}i16 @test_InterlockedCompareExchange16_rel(i16*{{[a-z_ ]*}}%Destination, i16{{[a-z_ ]*}}%Exchange, i16{{[a-z_ ]*}}%Comperand){{.*}}{
826+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i16* %Destination, i16 %Comperand, i16 %Exchange release monotonic
827+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i16, i1 } [[TMP]], 0
828+
// CHECK-ARM-ARM64: ret i16 [[RESULT]]
829+
// CHECK-ARM-ARM64: }
830+
831+
short test_InterlockedCompareExchange16_nf(short volatile *Destination, short Exchange, short Comperand) {
832+
return _InterlockedCompareExchange16_nf(Destination, Exchange, Comperand);
833+
}
834+
// CHECK-ARM-ARM64: define{{.*}}i16 @test_InterlockedCompareExchange16_nf(i16*{{[a-z_ ]*}}%Destination, i16{{[a-z_ ]*}}%Exchange, i16{{[a-z_ ]*}}%Comperand){{.*}}{
835+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i16* %Destination, i16 %Comperand, i16 %Exchange monotonic monotonic
836+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i16, i1 } [[TMP]], 0
837+
// CHECK-ARM-ARM64: ret i16 [[RESULT]]
838+
// CHECK-ARM-ARM64: }
839+
840+
long test_InterlockedCompareExchange_acq(long volatile *Destination, long Exchange, long Comperand) {
841+
return _InterlockedCompareExchange_acq(Destination, Exchange, Comperand);
842+
}
843+
// CHECK-ARM-ARM64: define{{.*}}i32 @test_InterlockedCompareExchange_acq(i32*{{[a-z_ ]*}}%Destination, i32{{[a-z_ ]*}}%Exchange, i32{{[a-z_ ]*}}%Comperand){{.*}}{
844+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i32* %Destination, i32 %Comperand, i32 %Exchange acquire acquire
845+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i32, i1 } [[TMP]], 0
846+
// CHECK-ARM-ARM64: ret i32 [[RESULT]]
847+
// CHECK-ARM-ARM64: }
848+
849+
long test_InterlockedCompareExchange_rel(long volatile *Destination, long Exchange, long Comperand) {
850+
return _InterlockedCompareExchange_rel(Destination, Exchange, Comperand);
851+
}
852+
// CHECK-ARM-ARM64: define{{.*}}i32 @test_InterlockedCompareExchange_rel(i32*{{[a-z_ ]*}}%Destination, i32{{[a-z_ ]*}}%Exchange, i32{{[a-z_ ]*}}%Comperand){{.*}}{
853+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i32* %Destination, i32 %Comperand, i32 %Exchange release monotonic
854+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i32, i1 } [[TMP]], 0
855+
// CHECK-ARM-ARM64: ret i32 [[RESULT]]
856+
// CHECK-ARM-ARM64: }
857+
858+
long test_InterlockedCompareExchange_nf(long volatile *Destination, long Exchange, long Comperand) {
859+
return _InterlockedCompareExchange_nf(Destination, Exchange, Comperand);
860+
}
861+
// CHECK-ARM-ARM64: define{{.*}}i32 @test_InterlockedCompareExchange_nf(i32*{{[a-z_ ]*}}%Destination, i32{{[a-z_ ]*}}%Exchange, i32{{[a-z_ ]*}}%Comperand){{.*}}{
862+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i32* %Destination, i32 %Comperand, i32 %Exchange monotonic monotonic
863+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i32, i1 } [[TMP]], 0
864+
// CHECK-ARM-ARM64: ret i32 [[RESULT]]
865+
// CHECK-ARM-ARM64: }
866+
867+
__int64 test_InterlockedCompareExchange64_acq(__int64 volatile *Destination, __int64 Exchange, __int64 Comperand) {
868+
return _InterlockedCompareExchange64_acq(Destination, Exchange, Comperand);
869+
}
870+
// CHECK-ARM-ARM64: define{{.*}}i64 @test_InterlockedCompareExchange64_acq(i64*{{[a-z_ ]*}}%Destination, i64{{[a-z_ ]*}}%Exchange, i64{{[a-z_ ]*}}%Comperand){{.*}}{
871+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i64* %Destination, i64 %Comperand, i64 %Exchange acquire acquire
872+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i64, i1 } [[TMP]], 0
873+
// CHECK-ARM-ARM64: ret i64 [[RESULT]]
874+
// CHECK-ARM-ARM64: }
875+
876+
__int64 test_InterlockedCompareExchange64_rel(__int64 volatile *Destination, __int64 Exchange, __int64 Comperand) {
877+
return _InterlockedCompareExchange64_rel(Destination, Exchange, Comperand);
878+
}
879+
// CHECK-ARM-ARM64: define{{.*}}i64 @test_InterlockedCompareExchange64_rel(i64*{{[a-z_ ]*}}%Destination, i64{{[a-z_ ]*}}%Exchange, i64{{[a-z_ ]*}}%Comperand){{.*}}{
880+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i64* %Destination, i64 %Comperand, i64 %Exchange release monotonic
881+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i64, i1 } [[TMP]], 0
882+
// CHECK-ARM-ARM64: ret i64 [[RESULT]]
883+
// CHECK-ARM-ARM64: }
884+
885+
__int64 test_InterlockedCompareExchange64_nf(__int64 volatile *Destination, __int64 Exchange, __int64 Comperand) {
886+
return _InterlockedCompareExchange64_nf(Destination, Exchange, Comperand);
887+
}
888+
// CHECK-ARM-ARM64: define{{.*}}i64 @test_InterlockedCompareExchange64_nf(i64*{{[a-z_ ]*}}%Destination, i64{{[a-z_ ]*}}%Exchange, i64{{[a-z_ ]*}}%Comperand){{.*}}{
889+
// CHECK-ARM-ARM64: [[TMP:%[0-9]+]] = cmpxchg volatile i64* %Destination, i64 %Comperand, i64 %Exchange monotonic monotonic
890+
// CHECK-ARM-ARM64: [[RESULT:%[0-9]+]] = extractvalue { i64, i1 } [[TMP]], 0
891+
// CHECK-ARM-ARM64: ret i64 [[RESULT]]
892+
// CHECK-ARM-ARM64: }
785893
#endif
786894

787895
#if !defined(__aarch64__)

0 commit comments

Comments
 (0)
Please sign in to comment.