blob: c97441a5016600eb17c4fd55ce3a4d3e16ee4033 [file] [log] [blame]
Suraj Sudhirb2812112020-11-07 16:35:271// RUN: mlir-opt %s -inline | FileCheck %s
2
3// These tests verify that regions with operations from TOSA dialect
4// can be inlined.
5
6// CHECK-LABEL: func @inlined_if_fn
7// Check that both the calls and the functions are eliminated after inlining:
8// CHECK-NOT: @add
9// CHECK-NOT: @sub
River Riddlec48e3a12022-04-20 23:19:4810func.func @inlined_if_fn(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {
Mogball5c36ee82022-01-18 07:47:2511 %0 = "tosa.cond_if"(%arg2, %arg0, %arg1) ({
Hanhan Wang0a1569a2022-11-28 22:17:5512 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):
Suraj Sudhirb2812112020-11-07 16:35:2713 %1 = call @add(%arg3, %arg4) : (tensor<f32>, tensor<f32>) -> tensor<f32>
14 "tosa.yield"(%1) : (tensor<f32>) -> ()
15 }, {
Hanhan Wang0a1569a2022-11-28 22:17:5516 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):
Suraj Sudhirb2812112020-11-07 16:35:2717 %1 = call @sub(%arg3, %arg4) : (tensor<f32>, tensor<f32>) -> tensor<f32>
18 "tosa.yield"(%1) : (tensor<f32>) -> ()
19 }) : (tensor<i1>, tensor<f32>, tensor<f32>) -> tensor<f32>
20 return %0 : tensor<f32>
21}
River Riddlec48e3a12022-04-20 23:19:4822func.func private @add(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<f32> {
Suraj Sudhirb2812112020-11-07 16:35:2723 %0 = "tosa.add"(%arg0, %arg1) : (tensor<f32>, tensor<f32>) -> tensor<f32>
24 return %0 : tensor<f32>
25}
River Riddlec48e3a12022-04-20 23:19:4826func.func private @sub(%arg0: tensor<f32>, %arg1: tensor<f32>) -> tensor<f32> {
Suraj Sudhirb2812112020-11-07 16:35:2727 %0 = "tosa.sub"(%arg0, %arg1) : (tensor<f32>, tensor<f32>) -> tensor<f32>
28 return %0 : tensor<f32>
29}
30
31// -----
32
33// CHECK-LABEL: func @inlined_while_fn
River Riddlec48e3a12022-04-20 23:19:4834func.func @inlined_while_fn(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: tensor<i32>, %arg3: tensor<10xi32>) -> tensor<10xi32> {
Suraj Sudhirb2812112020-11-07 16:35:2735 // Check that calls are inlined and functions eliminated:
36 // CHECK-NOT: @while
Mogball5c36ee82022-01-18 07:47:2537 %1:4 = "tosa.while_loop"(%arg0, %arg1, %arg2, %arg3) ({
Hanhan Wang0a1569a2022-11-28 22:17:5538 ^bb0(%arg4: tensor<i32>, %arg5: tensor<i32>, %arg6: tensor<i32>, %arg7: tensor<10xi32>):
Suraj Sudhirb2812112020-11-07 16:35:2739 %2 = call @while_cond_40(%arg4, %arg5, %arg6, %arg7) : (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>) -> tensor<i1>
40 "tosa.yield"(%2) : (tensor<i1>) -> ()
41 }, {
Hanhan Wang0a1569a2022-11-28 22:17:5542 ^bb0(%arg4: tensor<i32>, %arg5: tensor<i32>, %arg6: tensor<i32>, %arg7: tensor<10xi32>):
Suraj Sudhirb2812112020-11-07 16:35:2743 %2:4 = call @while_body_50(%arg4, %arg5, %arg6, %arg7) : (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>)
44 "tosa.yield"(%2#0, %2#1, %2#2, %2#3) : (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>) -> ()
45 }) : (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>)
46 return %1#3 : tensor<10xi32>
47}
River Riddlec48e3a12022-04-20 23:19:4848func.func private @while_body_50(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: tensor<i32>, %arg3: tensor<10xi32>) -> (tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>) {
Suraj Sudhirb2812112020-11-07 16:35:2749 %1 = "tosa.add"(%arg0, %arg1) : (tensor<i32>, tensor<i32>) -> tensor<i32>
Jerry-Ge472c2e32025-03-06 22:55:5050 %4 = "tosa.const_shape"() {values = dense<1> : tensor<1xindex>} : () -> !tosa.shape<1>
TatWai Chong571a9872025-02-07 18:24:5251 %3 = "tosa.reshape"(%1, %4) : (tensor<i32>, !tosa.shape<1>) -> tensor<1xi32>
Tai Ly729f9582025-01-22 13:21:0452 %2 = "tosa.add"(%arg3, %3) : (tensor<10xi32>, tensor<1xi32>) -> tensor<10xi32>
Suraj Sudhirb2812112020-11-07 16:35:2753 return %1, %arg1, %arg2, %2: tensor<i32>, tensor<i32>, tensor<i32>, tensor<10xi32>
54}
River Riddlec48e3a12022-04-20 23:19:4855func.func private @while_cond_40(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: tensor<i32>, %arg3: tensor<10xi32>) -> tensor<i1> {
Suraj Sudhirb2812112020-11-07 16:35:2756 %0 = "tosa.greater_equal"(%arg0, %arg1) : (tensor<i32>, tensor<i32>) -> tensor<i1>
57 %1 = "tosa.logical_not"(%0) : (tensor<i1>) -> tensor<i1>
58 return %1 : tensor<i1>
59}