Skip to content

Commit

Permalink
[CIR][CIRGen] Atomics: handle atomic_compare_exchange_strong
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardosolopes authored and lanza committed Apr 26, 2024
1 parent a1cb2c0 commit 80f74eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion clang/test/CIR/CodeGen/atomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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<!s32i>, {{.*}} : <!s32i>, {{.*}} : !cir.ptr<!s32i>, success = seq_cst, failure = seq_cst) : !cir.bool

// LLVM-LABEL: @_Z4fi4cPU7_Atomici
// LLVM: cmpxchg ptr {{.*}}, i32 {{.*}}, i32 {{.*}} seq_cst seq_cst, align 4

0 comments on commit 80f74eb

Please sign in to comment.