[Mlir-commits] [mlir] [mlir] [linalg] fix side effect of linalg op (PR #114045)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Oct 29 06:02:05 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: donald chen (cxy-1993)

<details>
<summary>Changes</summary>

Linalg op need to take into account memory side effects happening inside the region when determining their own side effects.

This patch fixed issue https://github.com/llvm/llvm-project/issues/112881

---
Full diff: https://github.com/llvm/llvm-project/pull/114045.diff


2 Files Affected:

- (modified) mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td (+1) 
- (added) mlir/test/Dialect/Linalg/recursive-effect.mlir (+15) 


``````````diff
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
index bfc609bd708164..c2fee8ea55c960 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td
@@ -30,6 +30,7 @@ class LinalgStructuredBase_Op<string mnemonic, list<Trait> props>
        SingleBlockImplicitTerminator<"YieldOp">,
        DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
        DeclareOpInterfaceMethods<ConditionallySpeculatable>,
+       RecursiveMemoryEffects,
        DestinationStyleOpInterface,
        LinalgStructuredInterface,
        ReifyRankedShapedTypeOpInterface], props)> {
diff --git a/mlir/test/Dialect/Linalg/recursive-effect.mlir b/mlir/test/Dialect/Linalg/recursive-effect.mlir
new file mode 100644
index 00000000000000..b5063d48b84cff
--- /dev/null
+++ b/mlir/test/Dialect/Linalg/recursive-effect.mlir
@@ -0,0 +1,15 @@
+// RUN: mlir-opt %s --canonicalize | FileCheck %s
+
+func.func @map(%arg0: memref<1xf32>, %arg1 : tensor<1xf32>) {
+  %c1 = arith.constant 1 : index
+  %init = arith.constant dense<0.0> : tensor<1xf32>
+  %mapped = linalg.map ins(%arg1:tensor<1xf32>) outs(%init :tensor<1xf32>) 
+            (%in : f32) {
+              memref.store %in, %arg0[%c1] : memref<1xf32>
+              linalg.yield %in : f32
+            }
+  func.return
+}
+
+// CHECK-LABEL: @map
+//       CHECK: linalg.map

``````````

</details>


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


More information about the Mlir-commits mailing list