[Mlir-commits] [mlir] [mlir][OpenMP] Model recursive memory effects of omp.masked (PR #230493)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Oct 13 07:57:55 PDT 2026


https://github.com/JRP-arm updated https://github.com/llvm/llvm-project/pull/230493

>From 30b24306bbe84d47e42a5d0dabc591935504ab4d Mon Sep 17 00:00:00 2001
From: "Jamie.Rowlinson-Patel at arm.com"
 <jamrow01 at ip-10-252-16-38.eu-west-1.compute.internal>
Date: Fri, 2 Oct 2026 10:16:31 +0000
Subject: [PATCH 1/6] [mlir][OpenMP] Model recursive memory effects of
 omp.masked

Test that canonicalisation preserves stores.
---
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td |  2 +-
 mlir/test/Dialect/OpenMP/canonicalize.mlir    | 31 +++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
index 6bc99cf7656992..491c9b3e8ab132 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
@@ -2410,7 +2410,7 @@ def DeclareReductionOp : OpenMP_Op<"declare_reduction", [IsolatedFromAbove,
 // [Spec 5.2] 10.5 masked Construct
 //===----------------------------------------------------------------------===//
 def MaskedOp : OpenMP_Op<"masked", traits = [
-    DeclareOpInterfaceMethods<ComposableOpInterface>
+    DeclareOpInterfaceMethods<ComposableOpInterface>, RecursiveMemoryEffects
   ], clauses = [
     OpenMP_FilterClause
   ], singleRegion = 1> {
diff --git a/mlir/test/Dialect/OpenMP/canonicalize.mlir b/mlir/test/Dialect/OpenMP/canonicalize.mlir
index cc42f2ed8618c7..50b35987776f65 100644
--- a/mlir/test/Dialect/OpenMP/canonicalize.mlir
+++ b/mlir/test/Dialect/OpenMP/canonicalize.mlir
@@ -143,3 +143,34 @@ func.func @constant_hoisting_target(%x : !llvm.ptr) {
 // CHECK-NOT: arith.constant
 // CHECK: omp.target
 // CHECK: arith.constant
+
+// -----
+
+// Masked has no implicit barrier so a body with no effects can be removed.
+// CHECK-LABEL: func.func @masked_no_side_effects
+// CHECK-NEXT: return
+func.func @masked_no_side_effects(%a: i32, %b: i32, %filter: i32) {
+  omp.masked filter(%filter : i32) {
+    %unused = arith.addi %a, %b : i32
+    omp.terminator
+  }
+  return
+}
+
+// -----
+
+// Masked must preserve memory effects in its body.
+// CHECK-LABEL: func.func @masked_store
+// CHECK-SAME: (%[[X:.*]]: memref<i32>, %[[VALUE:.*]]: i32, %[[FILTER:.*]]: i32)
+// CHECK-NEXT: omp.masked filter(%[[FILTER]] : i32) {
+// CHECK-NEXT: memref.store %[[VALUE]], %[[X]][] : memref<i32>
+// CHECK-NEXT: omp.terminator
+// CHECK-NEXT: }
+// CHECK-NEXT: return
+func.func @masked_store(%x: memref<i32>, %value: i32, %filter: i32) {
+  omp.masked filter(%filter : i32) {
+    memref.store %value, %x[] : memref<i32>
+    omp.terminator
+  }
+  return
+}

>From eddfa37518eb43077ba5499e4c088691cffff7ba Mon Sep 17 00:00:00 2001
From: "Jamie.Rowlinson-Patel at arm.com" <jamie.rowlinson-patel at arm.com>
Date: Tue, 13 Oct 2026 14:05:10 +0000
Subject: [PATCH 2/6] Add testing for recursive memory effects directly. Test
 memory effects of the masked construct directly.

---
 mlir/test/Dialect/OpenMP/memory-effects.mlir | 10 ++++++++++
 mlir/test/lib/IR/TestSideEffects.cpp         |  7 +++++++
 2 files changed, 17 insertions(+)
 create mode 100644 mlir/test/Dialect/OpenMP/memory-effects.mlir

diff --git a/mlir/test/Dialect/OpenMP/memory-effects.mlir b/mlir/test/Dialect/OpenMP/memory-effects.mlir
new file mode 100644
index 00000000000000..bf65703e87544f
--- /dev/null
+++ b/mlir/test/Dialect/OpenMP/memory-effects.mlir
@@ -0,0 +1,10 @@
+// RUN: mlir-opt %s --test-side-effects --verify-diagnostics
+
+// Check the trait on omp.masked itself, independently of its body.
+func.func @masked_recursive_memory_effects() {
+  // expected-remark at +1 {{recursive memory effects}}
+  omp.masked {
+    omp.terminator
+  } {test_recursive_memory_effects}
+  return
+}
\ No newline at end of file
diff --git a/mlir/test/lib/IR/TestSideEffects.cpp b/mlir/test/lib/IR/TestSideEffects.cpp
index 7c6132c51f3106..360b66cdd11b59 100644
--- a/mlir/test/lib/IR/TestSideEffects.cpp
+++ b/mlir/test/lib/IR/TestSideEffects.cpp
@@ -23,6 +23,13 @@ struct SideEffectsPass
   void runOnOperation() override {
     auto module = getOperation();
 
+    // Emit recursive memory effects.
+    module.walk([](Operation *op) {
+      if (op->hasAttr("test_recursive_memory_effects") &&
+          op->hasTrait<OpTrait::HasRecursiveMemoryEffects>())
+        op->emitRemark() << "recursive memory effects";
+    });
+
     // Walk operations detecting side effects.
     SmallVector<MemoryEffects::EffectInstance, 8> effects;
     module.walk([&](MemoryEffectOpInterface op) {

>From 7c6da90e84da1784078f8631b2064974adf5f419 Mon Sep 17 00:00:00 2001
From: "Jamie.Rowlinson-Patel at arm.com" <jamie.rowlinson-patel at arm.com>
Date: Tue, 13 Oct 2026 14:49:42 +0000
Subject: [PATCH 3/6] Remove canonicalize test

---
 mlir/test/Dialect/OpenMP/canonicalize.mlir | 33 +---------------------
 1 file changed, 1 insertion(+), 32 deletions(-)

diff --git a/mlir/test/Dialect/OpenMP/canonicalize.mlir b/mlir/test/Dialect/OpenMP/canonicalize.mlir
index 50b35987776f65..09dca489ae8a76 100644
--- a/mlir/test/Dialect/OpenMP/canonicalize.mlir
+++ b/mlir/test/Dialect/OpenMP/canonicalize.mlir
@@ -142,35 +142,4 @@ func.func @constant_hoisting_target(%x : !llvm.ptr) {
 // CHECK-LABEL: func.func @constant_hoisting_target
 // CHECK-NOT: arith.constant
 // CHECK: omp.target
-// CHECK: arith.constant
-
-// -----
-
-// Masked has no implicit barrier so a body with no effects can be removed.
-// CHECK-LABEL: func.func @masked_no_side_effects
-// CHECK-NEXT: return
-func.func @masked_no_side_effects(%a: i32, %b: i32, %filter: i32) {
-  omp.masked filter(%filter : i32) {
-    %unused = arith.addi %a, %b : i32
-    omp.terminator
-  }
-  return
-}
-
-// -----
-
-// Masked must preserve memory effects in its body.
-// CHECK-LABEL: func.func @masked_store
-// CHECK-SAME: (%[[X:.*]]: memref<i32>, %[[VALUE:.*]]: i32, %[[FILTER:.*]]: i32)
-// CHECK-NEXT: omp.masked filter(%[[FILTER]] : i32) {
-// CHECK-NEXT: memref.store %[[VALUE]], %[[X]][] : memref<i32>
-// CHECK-NEXT: omp.terminator
-// CHECK-NEXT: }
-// CHECK-NEXT: return
-func.func @masked_store(%x: memref<i32>, %value: i32, %filter: i32) {
-  omp.masked filter(%filter : i32) {
-    memref.store %value, %x[] : memref<i32>
-    omp.terminator
-  }
-  return
-}
+// CHECK: arith.constant
\ No newline at end of file

>From f78b200244b7fc76f303c294b829a4428cf28986 Mon Sep 17 00:00:00 2001
From: "Jamie.Rowlinson-Patel at arm.com" <jamie.rowlinson-patel at arm.com>
Date: Tue, 13 Oct 2026 14:50:43 +0000
Subject: [PATCH 4/6] Fully remove canonicalise tests

---
 mlir/test/Dialect/OpenMP/canonicalize.mlir | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mlir/test/Dialect/OpenMP/canonicalize.mlir b/mlir/test/Dialect/OpenMP/canonicalize.mlir
index 09dca489ae8a76..cf836db066a45e 100644
--- a/mlir/test/Dialect/OpenMP/canonicalize.mlir
+++ b/mlir/test/Dialect/OpenMP/canonicalize.mlir
@@ -141,5 +141,4 @@ func.func @constant_hoisting_target(%x : !llvm.ptr) {
 
 // CHECK-LABEL: func.func @constant_hoisting_target
 // CHECK-NOT: arith.constant
-// CHECK: omp.target
-// CHECK: arith.constant
\ No newline at end of file
+// CHECK: omp.target
\ No newline at end of file

>From 4d3ed9542cb7a30fa74c662b7a114886390654eb Mon Sep 17 00:00:00 2001
From: "Jamie.Rowlinson-Patel at arm.com" <jamie.rowlinson-patel at arm.com>
Date: Tue, 13 Oct 2026 14:53:15 +0000
Subject: [PATCH 5/6] Restore canonicalise tests

---
 mlir/test/Dialect/OpenMP/canonicalize.mlir | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mlir/test/Dialect/OpenMP/canonicalize.mlir b/mlir/test/Dialect/OpenMP/canonicalize.mlir
index cf836db066a45e..09dca489ae8a76 100644
--- a/mlir/test/Dialect/OpenMP/canonicalize.mlir
+++ b/mlir/test/Dialect/OpenMP/canonicalize.mlir
@@ -141,4 +141,5 @@ func.func @constant_hoisting_target(%x : !llvm.ptr) {
 
 // CHECK-LABEL: func.func @constant_hoisting_target
 // CHECK-NOT: arith.constant
-// CHECK: omp.target
\ No newline at end of file
+// CHECK: omp.target
+// CHECK: arith.constant
\ No newline at end of file

>From 99a4f044bc57a02880b427275c5d740efabe133b Mon Sep 17 00:00:00 2001
From: "Jamie.Rowlinson-Patel at arm.com" <jamie.rowlinson-patel at arm.com>
Date: Tue, 13 Oct 2026 14:57:17 +0000
Subject: [PATCH 6/6] Restore canonicalise test file newline

---
 mlir/test/Dialect/OpenMP/canonicalize.mlir | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mlir/test/Dialect/OpenMP/canonicalize.mlir b/mlir/test/Dialect/OpenMP/canonicalize.mlir
index 09dca489ae8a76..cc42f2ed8618c7 100644
--- a/mlir/test/Dialect/OpenMP/canonicalize.mlir
+++ b/mlir/test/Dialect/OpenMP/canonicalize.mlir
@@ -142,4 +142,4 @@ func.func @constant_hoisting_target(%x : !llvm.ptr) {
 // CHECK-LABEL: func.func @constant_hoisting_target
 // CHECK-NOT: arith.constant
 // CHECK: omp.target
-// CHECK: arith.constant
\ No newline at end of file
+// CHECK: arith.constant



More information about the Mlir-commits mailing list