[Mlir-commits] [flang] [mlir] [Flang] [OpenMP] atomic compare (PR #184761)

Tom Eccles llvmlistbot at llvm.org
Thu Mar 5 04:23:13 PST 2026


================
@@ -521,8 +562,108 @@ void Fortran::lower::omp::lowerAtomic(
     memOrder = makeValidForAction(memOrder, action0, action1, version);
 
   if (auto *cond = get(analysis.cond)) {
-    (void)cond;
-    TODO(loc, "OpenMP ATOMIC COMPARE");
+    // atomic compare: if (x == e) x = d
+    // e : expecteVal
+    // d : desiredVal
+
+    // Check for compound clauses (fail, capture, weak) that are not yet
+    // supported with atomic compare.
+    if (llvm::any_of(clauses, [](const omp::Clause &clause) {
+          return clause.id == llvm::omp::Clause::OMPC_fail ||
+                 clause.id == llvm::omp::Clause::OMPC_capture ||
+                 clause.id == llvm::omp::Clause::OMPC_weak;
+        })) {
+      TODO(loc, "Compound clauses of OpenMP ATOMIC COMPARE");
+    }
+
+    Fortran::common::RelationalOperator relOpr =
+        Fortran::common::RelationalOperator::EQ;
+    std::optional<semantics::SomeExpr> expectedExprStorage;
+
+    if (const auto *rel = Fortran::evaluate::UnwrapExpr<
+            Fortran::evaluate::Relational<Fortran::evaluate::SomeType>>(
+            *cond)) {
+      std::visit(
+          [&](const auto &relImpl) {
+            relOpr = relImpl.opr;
+            using Operand = typename std::decay_t<decltype(relImpl)>::Operand;
+            expectedExprStorage = Fortran::evaluate::AsGenericExpr(
+                Fortran::evaluate::Expr<Operand>{relImpl.right()});
----------------
tblah wrote:

Why is it always on the right?

https://github.com/llvm/llvm-project/pull/184761


More information about the Mlir-commits mailing list