[Mlir-commits] [mlir] [mlir] [linalg] fix side effect of linalg op (PR #114045)
donald chen
llvmlistbot at llvm.org
Tue Oct 29 06:01:31 PDT 2024
https://github.com/cxy-1993 created https://github.com/llvm/llvm-project/pull/114045
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
>From e1417e08f44f6ff4d9d0ed5de1f0d8b427a9722e Mon Sep 17 00:00:00 2001
From: donald chen <chenxunyu1993 at gmail.com>
Date: Tue, 29 Oct 2024 12:57:12 +0000
Subject: [PATCH] [mlir] [linalg] fix side effect of linalg op
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
---
.../mlir/Dialect/Linalg/IR/LinalgStructuredOps.td | 1 +
mlir/test/Dialect/Linalg/recursive-effect.mlir | 15 +++++++++++++++
2 files changed, 16 insertions(+)
create mode 100644 mlir/test/Dialect/Linalg/recursive-effect.mlir
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
More information about the Mlir-commits
mailing list