1// RUN: mlir-hlo-opt %s -split-input-file -pass-pipeline='func.func(canonicalize)' | FileCheck %s 2 3// ----- 4 5// CHECK-LABEL: func @noop 6// CHECK-SAME: (%[[ARG0:.*]]: tensor<4x8xf32>) 7// CHECK: return %[[ARG0]] 8func.func @noop(%arg0: tensor<4x8xf32>) -> tensor<4x8xf32> { 9 %0 = mhlo.constant dense<0.000000e+00> : tensor<f32> 10 %2 = "mhlo.reduce"(%arg0, %0) ({ 11 ^bb0(%arg1: tensor<f32>, %arg2: tensor<f32>): 12 %4 = mhlo.add %arg1, %arg2 : tensor<f32> 13 "mhlo.return"(%4) : (tensor<f32>) -> () 14 }) {dimensions = dense<[]> : tensor<0xi64>} : (tensor<4x8xf32>, tensor<f32>) -> tensor<4x8xf32> 15 func.return %2 : tensor<4x8xf32> 16} 17 18// ----- 19 20// CHECK-LABEL: func @and_fold 21func.func @and_fold() -> (tensor<i1>, tensor<i1>) { 22 %0 = mhlo.constant dense<true> : tensor<2xi1> 23 %2 = mhlo.constant dense<true> : tensor<i1> 24 %3 = mhlo.constant dense<false> : tensor<i1> 25 %4 = "mhlo.reduce"(%0, %2) ({ 26 ^bb0(%arg2: tensor<i1>, %arg3: tensor<i1>): 27 %11 = mhlo.and %arg2, %arg3 : tensor<i1> 28 "mhlo.return"(%11) : (tensor<i1>) -> () 29 }) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor<i1>) -> tensor<i1> 30 31 %5 = "mhlo.reduce"(%0, %3) ({ 32 ^bb0(%arg4: tensor<i1>, %arg5: tensor<i1>): 33 %12 = mhlo.and %arg4, %arg5 : tensor<i1> 34 "mhlo.return"(%12) : (tensor<i1>) -> () 35 }) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor<i1>) -> tensor<i1> 36 func.return %4, %5 : tensor<i1>, tensor<i1> 37 38 // CHECK-DAG: %[[CST:.*]] = mhlo.constant dense<true> : tensor<i1> 39 // CHECK-DAG: %[[CST1:.*]] = mhlo.constant dense<false> : tensor<i1> 40 // CHECK: return %[[CST]], %[[CST1]] : tensor<i1>, tensor<i1> 41} 42 43// ----- 44 45// CHECK-LABEL: func @or_fold 46func.func @or_fold() -> (tensor<i1>, tensor<i1>) { 47 %0 = mhlo.constant dense<false> : tensor<2xi1> 48 %2 = mhlo.constant dense<false> : tensor<i1> 49 %3 = mhlo.constant dense<true> : tensor<i1> 50 %4 = "mhlo.reduce"(%0, %2) ({ 51 ^bb0(%arg2: tensor<i1>, %arg3: tensor<i1>): 52 %11 = mhlo.or %arg2, %arg3 : tensor<i1> 53 "mhlo.return"(%11) : (tensor<i1>) -> () 54 }) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor<i1>) -> tensor<i1> 55 56 %5 = "mhlo.reduce"(%0, %3) ({ 57 ^bb0(%arg4: tensor<i1>, %arg5: tensor<i1>): 58 %12 = mhlo.or %arg4, %arg5 : tensor<i1> 59 "mhlo.return"(%12) : (tensor<i1>) -> () 60 }) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor<i1>) -> tensor<i1> 61 func.return %4, %5 : tensor<i1>, tensor<i1> 62 63 // CHECK-DAG: %[[CST:.*]] = mhlo.constant dense<false> : tensor<i1> 64 // CHECK-DAG: %[[CST1:.*]] = mhlo.constant dense<true> : tensor<i1> 65 // CHECK: return %[[CST]], %[[CST1]] : tensor<i1>, tensor<i1> 66} 67