Skip to content

Commit dabfcdb

Browse files
committed
[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 #112881
1 parent 98c8d64 commit dabfcdb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mlir/include/mlir/Dialect/Linalg/IR/LinalgStructuredOps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class LinalgStructuredBase_Op<string mnemonic, list<Trait> props>
3030
SingleBlockImplicitTerminator<"YieldOp">,
3131
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
3232
DeclareOpInterfaceMethods<ConditionallySpeculatable>,
33+
RecursiveMemoryEffects,
3334
DestinationStyleOpInterface,
3435
LinalgStructuredInterface,
3536
ReifyRankedShapedTypeOpInterface], props)> {

mlir/test/Dialect/Linalg/canonicalize.mlir

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,3 +1232,21 @@ func.func @transpose_buffer(%input: memref<?xf32>,
12321232
// CHECK-SAME: %[[VAL_1:.*]]: memref<?xf32>) {
12331233
// CHECK: linalg.transpose ins(%[[VAL_0]] : memref<?xf32>)
12341234
// CHECK-SAME: outs(%[[VAL_1]] : memref<?xf32>) permutation = [0]
1235+
1236+
// -----
1237+
1238+
// This test checks linalg op has a recursive memory effect. Otherwise
1239+
// linalg.map without a user would be DCEd.
1240+
func.func @recursive_effect(%arg0: memref<1xf32>, %arg1 : tensor<1xf32>) {
1241+
%c1 = arith.constant 1 : index
1242+
%init = arith.constant dense<0.0> : tensor<1xf32>
1243+
%mapped = linalg.map ins(%arg1:tensor<1xf32>) outs(%init :tensor<1xf32>)
1244+
(%in : f32) {
1245+
memref.store %in, %arg0[%c1] : memref<1xf32>
1246+
linalg.yield %in : f32
1247+
}
1248+
func.return
1249+
}
1250+
1251+
// CHECK-LABEL: @recursive_effect
1252+
// CHECK: linalg.map

0 commit comments

Comments
 (0)