[Mlir-commits] [flang] [mlir] [Flang] [OpenMP] atomic compare (PR #184761)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Apr 24 04:24:46 PDT 2026
================
@@ -2452,6 +2452,95 @@ llvm.func @omp_atomic_capture_misc(
// -----
+// CHECK-LABEL: @omp_atomic_compare
+// CHECK-SAME: (ptr %[[X:.*]], i32 %[[E:.*]], i32 %[[D:.*]], ptr %[[XF:.*]], float %[[EF:.*]], float %[[DF:.*]], ptr %[[XC:.*]], { float, float } %[[EC:.*]], { float, float } %[[DC:.*]])
+llvm.func @omp_atomic_compare(
+ %x : !llvm.ptr, %e : i32, %d : i32,
+ %xf : !llvm.ptr, %ef : f32, %df : f32,
+ %xc : !llvm.ptr, %ec : !llvm.struct<(f32, f32)>, %dc : !llvm.struct<(f32, f32)>) {
+
+ // Integer equality → cmpxchg
+ // CHECK: cmpxchg ptr %[[X]], i32 %[[E]], i32 %[[D]] monotonic monotonic
+ omp.atomic.compare %x : !llvm.ptr {
+ ^bb0(%xval : i32):
+ %cmp0 = llvm.icmp "eq" %xval, %e : i32
+ %sel0 = llvm.select %cmp0, %d, %xval : i1, i32
+ omp.yield(%sel0 : i32)
+ }
+
+ // Float equality → bitcast + cmpxchg
+ // CHECK: %[[EBC:.*]] = bitcast float %[[EF]] to i32
+ // CHECK: %[[DBC:.*]] = bitcast float %[[DF]] to i32
+ // CHECK: cmpxchg ptr %[[XF]], i32 %[[EBC]], i32 %[[DBC]] monotonic monotonic
----------------
SunilKuravinakop wrote:
CAS loops i.e. `load,` `fcmp oeq`, `compxchg` (on successfull fcmp) has to be done for this. This is not an atomic instruction. Do you know of any alternative where it can done as an atomic instruction?
https://github.com/llvm/llvm-project/pull/184761
More information about the Mlir-commits
mailing list