Skip to content

Commit df0d249

Browse files
authored
[mlir] [linalg] fix side effect of linalg op (llvm#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 llvm#112881
1 parent f1467b3 commit df0d249

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,3 +1232,20 @@ 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(%arg : tensor<1xf32>) {
1241+
%init = arith.constant dense<0.0> : tensor<1xf32>
1242+
%mapped = linalg.map ins(%arg:tensor<1xf32>) outs(%init :tensor<1xf32>)
1243+
(%in : f32) {
1244+
vector.print %in : f32
1245+
linalg.yield %in : f32
1246+
}
1247+
func.return
1248+
}
1249+
1250+
// CHECK-LABEL: @recursive_effect
1251+
// CHECK: linalg.map

0 commit comments

Comments
 (0)