1
- // RUN: mlir-opt --split-input-file --tosa-layerwise-constant-fold %s | FileCheck %s
2
- // RUN: mlir-opt --split-input-file --tosa-layerwise-constant-fold="fold-splat-or-single-use-only=0" %s | FileCheck %s --check-prefix CHECK-MULTI
1
+ // RUN: mlir-opt --tosa-layerwise-constant-fold %s | FileCheck %s
2
+ // RUN: mlir-opt --tosa-layerwise-constant-fold="fold-splat-or-single-use-only=0" %s \
3
+ // RUN: | FileCheck %s --check-prefix CHECK-ALWAYS
3
4
4
5
// CHECK-LABEL: @reshape_single_user
5
6
func.func @reshape_single_user () -> tensor <1 x2 xf32 > {
@@ -10,6 +11,7 @@ func.func @reshape_single_user() -> tensor<1x2xf32> {
10
11
return %1 : tensor <1 x2 xf32 >
11
12
}
12
13
14
+ // Splat constants are always folded, even when they have multiple users.
13
15
// CHECK-LABEL: @reshape_multi_user_splat
14
16
func.func @reshape_multi_user_splat () -> (tensor <1 x2 xf32 >, tensor <2 xf32 >) {
15
17
// CHECK-DAG: %[[RES:.*]] = "tosa.const"{{.*}}-> tensor<2xf32>
@@ -20,14 +22,16 @@ func.func @reshape_multi_user_splat() -> (tensor<1x2xf32>, tensor<2xf32>) {
20
22
return %1 , %0 : tensor <1 x2 xf32 >, tensor <2 xf32 >
21
23
}
22
24
25
+ // Non-splat constants with multiple users are only folded when
26
+ // fold-splat-or-single-use-only=0 is set.
23
27
// CHECK-LABEL: @reshape_multi_user_non_splat
24
28
func.func @reshape_multi_user_non_splat () -> (tensor <1 x2 xf32 >, tensor <2 xf32 >) {
25
29
// CHECK: %[[CONST:.*]] = "tosa.const"{{.*}}-> tensor<2xf32>
26
30
// CHECK: %[[RES:.*]] = tosa.reshape
27
31
// CHECK: return %[[RES]], %[[CONST]]
28
- // CHECK-MULTI -DAG: %[[RES:.*]] = "tosa.const"{{.*}}-> tensor<2xf32>
29
- // CHECK-MULTI -DAG: %[[RESHAPED:.*]] = "tosa.const"{{.*}}-> tensor<1x2xf32>
30
- // CHECK-MULTI : return %[[RESHAPED]], %[[RES]]
32
+ // CHECK-ALWAYS -DAG: %[[RES:.*]] = "tosa.const"{{.*}}-> tensor<2xf32>
33
+ // CHECK-ALWAYS -DAG: %[[RESHAPED:.*]] = "tosa.const"{{.*}}-> tensor<1x2xf32>
34
+ // CHECK-ALWAYS : return %[[RESHAPED]], %[[RES]]
31
35
%0 = " tosa.const" () {value = dense <[4.0 , 3.0 ]> : tensor <2 xf32 >} : () -> tensor <2 xf32 >
32
36
%1 = tosa.reshape %0 {new_shape = array<i64 : 1 , 2 >}: (tensor <2 xf32 >) -> tensor <1 x2 xf32 >
33
37
return %1 , %0 : tensor <1 x2 xf32 >, tensor <2 xf32 >
0 commit comments