From 80f74eb50e932e2fb8c4fd3313010d611376769c Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Thu, 25 Apr 2024 18:58:18 -0700 Subject: [PATCH] [CIR][CIRGen] Atomics: handle atomic_compare_exchange_strong --- clang/lib/CIR/CodeGen/CIRGenAtomic.cpp | 3 ++- clang/test/CIR/CodeGen/atomic.cpp | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp b/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp index 2e736206c775..d5799ddf0e93 100644 --- a/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp @@ -416,7 +416,8 @@ static void buildAtomicOp(CIRGenFunction &CGF, AtomicExpr *E, Address Dest, case AtomicExpr::AO__c11_atomic_compare_exchange_strong: case AtomicExpr::AO__hip_atomic_compare_exchange_strong: case AtomicExpr::AO__opencl_atomic_compare_exchange_strong: - llvm_unreachable("NYI"); + buildAtomicCmpXchgFailureSet(CGF, E, false, Dest, Ptr, Val1, Val2, + FailureOrder, Size, Order, Scope); return; case AtomicExpr::AO__c11_atomic_compare_exchange_weak: case AtomicExpr::AO__opencl_atomic_compare_exchange_weak: diff --git a/clang/test/CIR/CodeGen/atomic.cpp b/clang/test/CIR/CodeGen/atomic.cpp index d617b627c73b..0971d47b5ca3 100644 --- a/clang/test/CIR/CodeGen/atomic.cpp +++ b/clang/test/CIR/CodeGen/atomic.cpp @@ -272,4 +272,15 @@ bool fi4b(int *i) { // LLVM-LABEL: @_Z4fi4bPi // LLVM: %[[R:.*]] = cmpxchg weak ptr {{.*}}, i32 {{.*}}, i32 {{.*}} acquire acquire, align 4 // LLVM: extractvalue { i32, i1 } %[[R]], 0 -// LLVM: extractvalue { i32, i1 } %[[R]], 1 \ No newline at end of file +// LLVM: extractvalue { i32, i1 } %[[R]], 1 + +bool fi4c(atomic_int *i) { + int cmp = 0; + return atomic_compare_exchange_strong(i, &cmp, 1); +} + +// CHECK-LABEL: @_Z4fi4cPU7_Atomici +// CHECK: cir.atomic.cmp_xchg({{.*}} : !cir.ptr, {{.*}} : , {{.*}} : !cir.ptr, success = seq_cst, failure = seq_cst) : !cir.bool + +// LLVM-LABEL: @_Z4fi4cPU7_Atomici +// LLVM: cmpxchg ptr {{.*}}, i32 {{.*}}, i32 {{.*}} seq_cst seq_cst, align 4 \ No newline at end of file