// RUN: mlir-hlo-opt %s -split-input-file -pass-pipeline='func(canonicalize)' | FileCheck %s // ----- // CHECK-LABEL: func @noop // CHECK-SAME: (%[[ARG0:.*]]: tensor<4x8xf32>) // CHECK: return %[[ARG0]] func @noop(%arg0: tensor<4x8xf32>) -> tensor<4x8xf32> { %0 = mhlo.constant dense<0.000000e+00> : tensor %2 = "mhlo.reduce"(%arg0, %0) ( { ^bb0(%arg1: tensor, %arg2: tensor): %4 = mhlo.add %arg1, %arg2 : tensor "mhlo.return"(%4) : (tensor) -> () }) {dimensions = dense<[]> : tensor<0xi64>} : (tensor<4x8xf32>, tensor) -> tensor<4x8xf32> return %2 : tensor<4x8xf32> } // ----- // CHECK-LABEL: func @and_fold func @and_fold() -> (tensor, tensor) { %0 = mhlo.constant dense : tensor<2xi1> %2 = mhlo.constant dense : tensor %3 = mhlo.constant dense : tensor %4 = "mhlo.reduce"(%0, %2) ( { ^bb0(%arg2: tensor, %arg3: tensor): %11 = mhlo.and %arg2, %arg3 : tensor "mhlo.return"(%11) : (tensor) -> () }) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor) -> tensor %5 = "mhlo.reduce"(%0, %3) ( { ^bb0(%arg4: tensor, %arg5: tensor): %12 = mhlo.and %arg4, %arg5 : tensor "mhlo.return"(%12) : (tensor) -> () }) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor) -> tensor return %4, %5 : tensor, tensor // CHECK-DAG: %[[CST:.*]] = mhlo.constant dense : tensor // CHECK-DAG: %[[CST1:.*]] = mhlo.constant dense : tensor // CHECK: return %[[CST]], %[[CST1]] : tensor, tensor } // ----- // CHECK-LABEL: func @or_fold func @or_fold() -> (tensor, tensor) { %0 = mhlo.constant dense : tensor<2xi1> %2 = mhlo.constant dense : tensor %3 = mhlo.constant dense : tensor %4 = "mhlo.reduce"(%0, %2) ( { ^bb0(%arg2: tensor, %arg3: tensor): %11 = mhlo.or %arg2, %arg3 : tensor "mhlo.return"(%11) : (tensor) -> () }) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor) -> tensor %5 = "mhlo.reduce"(%0, %3) ( { ^bb0(%arg4: tensor, %arg5: tensor): %12 = mhlo.or %arg4, %arg5 : tensor "mhlo.return"(%12) : (tensor) -> () }) {dimensions = dense<0> : tensor<1xi64>} : (tensor<2xi1>, tensor) -> tensor return %4, %5 : tensor, tensor // CHECK-DAG: %[[CST:.*]] = mhlo.constant dense : tensor // CHECK-DAG: %[[CST1:.*]] = mhlo.constant dense : tensor // CHECK: return %[[CST]], %[[CST1]] : tensor, tensor }