xref: /llvm-project/mlir/test/Dialect/Linalg/fusion-elementwise-options.mlir (revision 2d4b998697fda9a0a213e5fb29f8af45a4828dc7)
1// RUN: mlir-opt %s -test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control -split-input-file | FileCheck %s
2
3#map0 = affine_map<(d0, d1) -> (d0, d1)>
4#binary2Dpointwise = {
5  indexing_maps = [#map0, #map0, #map0],
6  iterator_types = ["parallel", "parallel"]
7}
8#ternary2Dpointwise = {
9  indexing_maps = [#map0, #map0, #map0, #map0],
10  iterator_types = ["parallel", "parallel"]
11}
12func.func @test_fusion_limit(
13    %arg0 : tensor<?x?xf32>, %arg1 : tensor<?x?xf32>, %arg2 : tensor<?x?xf32>,
14    %arg3 : tensor<?x?xf32>, %arg4 : tensor<?x?xf32>, %arg5 : tensor<?x?xf32>)
15    -> tensor<?x?xf32> {
16  %c0 = arith.constant 0 : index
17  %c1 = arith.constant 1 : index
18  %d0 = tensor.dim %arg0, %c0 : tensor<?x?xf32>
19  %d1 = tensor.dim %arg0, %c1 : tensor<?x?xf32>
20  %init = tensor.empty(%d0, %d1) : tensor<?x?xf32>
21  %0 = linalg.generic #binary2Dpointwise
22      ins(%arg0, %arg1 : tensor<?x?xf32>, tensor<?x?xf32>)
23      outs(%init : tensor<?x?xf32>) {
24    ^bb0(%arg6 : f32, %arg7 : f32, %arg8 : f32):
25       %1 = arith.mulf %arg6, %arg7 : f32
26       linalg.yield %1 : f32
27    } -> tensor<?x?xf32>
28  %2 = linalg.generic #binary2Dpointwise
29      ins(%arg2, %arg3 : tensor<?x?xf32>, tensor<?x?xf32>)
30      outs(%init : tensor<?x?xf32>) {
31    ^bb0(%arg6 : f32, %arg7 : f32, %arg8 : f32):
32       %3 = arith.mulf %arg6, %arg7 : f32
33       linalg.yield %3 : f32
34    } -> tensor<?x?xf32>
35  %4 = linalg.generic #binary2Dpointwise
36      ins(%arg4, %arg5 : tensor<?x?xf32>, tensor<?x?xf32>)
37      outs(%init : tensor<?x?xf32>) {
38    ^bb0(%arg6 : f32, %arg7 : f32, %arg8 : f32):
39       %5 = arith.mulf %arg6, %arg7 : f32
40       linalg.yield %5 : f32
41    } -> tensor<?x?xf32>
42  %6 = linalg.generic #ternary2Dpointwise
43      ins(%0, %2, %4 : tensor<?x?xf32>, tensor<?x?xf32>, tensor<?x?xf32>)
44      outs(%init : tensor<?x?xf32>) {
45    ^bb0(%arg6 : f32, %arg7 : f32, %arg8 : f32, %arg9 : f32):
46       %7 = arith.addf %arg6, %arg7 : f32
47       %8 = arith.addf %7, %arg8 : f32
48       linalg.yield %8 : f32
49    } -> tensor<?x?xf32>
50  return %6 : tensor<?x?xf32>
51}
52
53// CHECK-LABEL: func @test_fusion_limit
54//  CHECK-SAME:   %[[ARG0:[a-zA-z0-9_]+]]: tensor<?x?xf32>
55//  CHECK-SAME:   %[[ARG1:[a-zA-z0-9_]+]]: tensor<?x?xf32>
56//  CHECK-SAME:   %[[ARG2:[a-zA-z0-9_]+]]: tensor<?x?xf32>
57//  CHECK-SAME:   %[[ARG3:[a-zA-z0-9_]+]]: tensor<?x?xf32>
58//  CHECK-SAME:   %[[ARG4:[a-zA-z0-9_]+]]: tensor<?x?xf32>
59//  CHECK-SAME:   %[[ARG5:[a-zA-z0-9_]+]]: tensor<?x?xf32>
60//       CHECK:   %[[OP1:.+]] = linalg.generic {{.+}} ins(%[[ARG2]], %[[ARG3]]
61//       CHECK:   %[[OP2:.+]] = linalg.generic {{.+}} ins(%[[ARG4]], %[[ARG5]]
62//       CHECK:   %[[OP3:.+]] = linalg.generic {{.+}} ins(%[[ARG0]], %[[ARG1]], %[[OP1]], %[[OP2]]
63//       CHECK:   return %[[OP3]]
64