xref: /llvm-project/mlir/test/Dialect/Linalg/fusion-multiuse-producer.mlir (revision 69011a2ad0ce8662f69d3abef12280b1f463f99c)
1// RUN: mlir-opt -test-linalg-elementwise-fusion-patterns=fuse-multiuse-producer -split-input-file %s | FileCheck %s
2
3#map = affine_map<(d0, d1) -> (d0, d1)>
4func.func @multi_use_producer(%arg0 : tensor<?x?xf32>, %arg1 : tensor<?x?xf32>,
5    %arg2 : tensor<?x?xf32>, %arg3 : tensor<?x?xf32>, %arg4 : tensor<?x?xf32>)
6    -> (tensor<?x?xf32>, tensor<?x?xf32>, tensor<?x?xf32>) {
7  %0:2 = linalg.generic {
8      indexing_maps = [#map, #map, #map],
9      iterator_types = ["parallel", "parallel"]}
10      ins(%arg0 : tensor<?x?xf32>)
11      outs(%arg1, %arg2 : tensor<?x?xf32>, tensor<?x?xf32>) {
12  ^bb0(%b0: f32, %b1 : f32, %b2 : f32):
13    %1 = arith.addf %b0, %b1 : f32
14    linalg.yield %1, %1 : f32, f32
15  } -> (tensor<?x?xf32>, tensor<?x?xf32>)
16  %2 = linalg.generic {
17      indexing_maps = [#map, #map, #map],
18      iterator_types = ["parallel", "parallel"]}
19      ins(%0#1, %arg3 : tensor<?x?xf32>, tensor<?x?xf32>)
20      outs(%arg4 : tensor<?x?xf32>) {
21  ^bb0(%b0 : f32, %b1 : f32, %b2 : f32):
22    %3 = arith.mulf %b0, %b1 : f32
23    linalg.yield %3 : f32
24  } -> tensor<?x?xf32>
25  return %0#0, %0#1, %2 : tensor<?x?xf32>, tensor<?x?xf32>, tensor<?x?xf32>
26}
27//      CHECK: func @multi_use_producer(
28// CHECK-SAME:     %[[ARG0:[a-zA-Z0-9]+]]: tensor<?x?xf32>
29// CHECK-SAME:     %[[ARG1:[a-zA-Z0-9]+]]: tensor<?x?xf32>
30// CHECK-SAME:     %[[ARG2:[a-zA-Z0-9]+]]: tensor<?x?xf32>
31// CHECK-SAME:     %[[ARG3:[a-zA-Z0-9]+]]: tensor<?x?xf32>
32// CHECK-SAME:     %[[ARG4:[a-zA-Z0-9]+]]: tensor<?x?xf32>)
33//      CHECK:   %[[RESULT:.+]]:3 = linalg.generic
34//      CHECK:   return %[[RESULT]]#0, %[[RESULT]]#1, %[[RESULT]]#2
35