2021-04-27 06:10:20 +08:00
|
|
|
// RUN: mlir-hlo-opt %s -split-input-file -pass-pipeline='func(canonicalize)' | FileCheck %s
|
|
|
|
|
|
|
|
// -----
|
2020-07-07 07:28:26 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: func @noop
|
|
|
|
// CHECK-SAME: (%[[ARG0:.*]]: tensor<4x8xf32>)
|
|
|
|
// CHECK: return %[[ARG0]]
|
|
|
|
func @noop(%arg0: tensor<4x8xf32>) -> tensor<4x8xf32> {
|
2020-07-07 12:51:24 +08:00
|
|
|
%0 = mhlo.constant dense<0.000000e+00> : tensor<f32>
|
|
|
|
%2 = "mhlo.reduce"(%arg0, %0) ( {
|
2020-07-07 07:28:26 +08:00
|
|
|
^bb0(%arg1: tensor<f32>, %arg2: tensor<f32>):
|
2020-07-07 12:51:24 +08:00
|
|
|
%4 = mhlo.add %arg1, %arg2 : tensor<f32>
|
|
|
|
"mhlo.return"(%4) : (tensor<f32>) -> ()
|
2020-07-07 07:28:26 +08:00
|
|
|
}) {dimensions = dense<[]> : tensor<0xi64>} : (tensor<4x8xf32>, tensor<f32>) -> tensor<4x8xf32>
|
|
|
|
return %2 : tensor<4x8xf32>
|
|
|
|
}
|
2021-04-27 06:10:20 +08:00
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// CHECK-LABEL: func @and_fold
|
|
|
|
func @and_fold() -> (tensor<i1>, tensor<i1>) {
|
|
|
|
%0 = mhlo.constant dense<true> : tensor<2xi1>
|
|
|
|
%2 = mhlo.constant dense<true> : tensor<i1>
|
|
|
|
%3 = mhlo.constant dense<false> : tensor<i1>
|
|
|
|
%4 = "mhlo.reduce"(%0, %2) ( {
|
|
|
|
^bb0(%arg2: tensor<i1>, %arg3: tensor<i1>):
|
|
|
|
%11 = mhlo.and %arg2, %arg3 : tensor<i1>
|
|
|
|
"mhlo.return"(%11) : (tensor<i1>) -> ()
|
|
|
|
}) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor<i1>) -> tensor<i1>
|
|
|
|
|
|
|
|
%5 = "mhlo.reduce"(%0, %3) ( {
|
|
|
|
^bb0(%arg4: tensor<i1>, %arg5: tensor<i1>):
|
|
|
|
%12 = mhlo.and %arg4, %arg5 : tensor<i1>
|
|
|
|
"mhlo.return"(%12) : (tensor<i1>) -> ()
|
|
|
|
}) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor<i1>) -> tensor<i1>
|
|
|
|
return %4, %5 : tensor<i1>, tensor<i1>
|
|
|
|
|
2021-05-26 19:46:41 +08:00
|
|
|
// CHECK-DAG: %[[CST:.*]] = mhlo.constant dense<true> : tensor<i1>
|
|
|
|
// CHECK-DAG: %[[CST1:.*]] = mhlo.constant dense<false> : tensor<i1>
|
2021-04-27 06:10:20 +08:00
|
|
|
// CHECK: return %[[CST]], %[[CST1]] : tensor<i1>, tensor<i1>
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----
|
|
|
|
|
|
|
|
// CHECK-LABEL: func @or_fold
|
|
|
|
func @or_fold() -> (tensor<i1>, tensor<i1>) {
|
|
|
|
%0 = mhlo.constant dense<false> : tensor<2xi1>
|
|
|
|
%2 = mhlo.constant dense<false> : tensor<i1>
|
|
|
|
%3 = mhlo.constant dense<true> : tensor<i1>
|
|
|
|
%4 = "mhlo.reduce"(%0, %2) ( {
|
|
|
|
^bb0(%arg2: tensor<i1>, %arg3: tensor<i1>):
|
|
|
|
%11 = mhlo.or %arg2, %arg3 : tensor<i1>
|
|
|
|
"mhlo.return"(%11) : (tensor<i1>) -> ()
|
|
|
|
}) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor<i1>) -> tensor<i1>
|
|
|
|
|
|
|
|
%5 = "mhlo.reduce"(%0, %3) ( {
|
|
|
|
^bb0(%arg4: tensor<i1>, %arg5: tensor<i1>):
|
|
|
|
%12 = mhlo.or %arg4, %arg5 : tensor<i1>
|
|
|
|
"mhlo.return"(%12) : (tensor<i1>) -> ()
|
|
|
|
}) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor<i1>) -> tensor<i1>
|
|
|
|
return %4, %5 : tensor<i1>, tensor<i1>
|
|
|
|
|
2021-05-26 19:46:41 +08:00
|
|
|
// CHECK-DAG: %[[CST:.*]] = mhlo.constant dense<false> : tensor<i1>
|
|
|
|
// CHECK-DAG: %[[CST1:.*]] = mhlo.constant dense<true> : tensor<i1>
|
2021-04-27 06:10:20 +08:00
|
|
|
// CHECK: return %[[CST]], %[[CST1]] : tensor<i1>, tensor<i1>
|
|
|
|
}
|