[Mlir-commits] [flang] [mlir] [Flang] [OpenMP] atomic compare (PR #184761)
Tom Eccles
llvmlistbot at llvm.org
Thu Apr 23 03:13:41 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
----------------
tblah wrote:
Wouldn't this create a bitwise comparison? This isn't the same as a floating point comparison. For example -0.0 == +0.0 but they have different bit patterns.
https://github.com/llvm/llvm-project/pull/184761
More information about the Mlir-commits
mailing list