// RUN: mlir-hlo-opt --chlo-legalize-to-hlo --split-input-file %s | FileCheck %s // Lower statically shaped `constant_like` to constant. // CHECK-LABEL: @constant_like_static_shape func @constant_like_static_shape(%arg : tensor<1x2xi64>) -> tensor<1x2xf32> { // CHECK: %[[RESULT:.*]] = mhlo.constant dense<3.200000e+00> : tensor<1x2xf32> // CHECK: return %[[RESULT]] %result = "chlo.constant_like"(%arg) { value = 3.2 : f32 } : (tensor<1x2xi64>) -> tensor<1x2xf32> return %result : tensor<1x2xf32> } // Lower dynamically shaped `constant_like` to broadcasted constant. // CHECK-LABEL: constant_like_dynamic_shape // CHECK-SAME: (%[[ARG:.*]]: tensor) func @constant_like_dynamic_shape(%arg : tensor) -> tensor { // CHECK: %[[CONSTANT:.*]] = mhlo.constant dense<3.200000e+00> : tensor // CHECK: %[[UNCASTED_SHAPE:.*]] = shape.shape_of %[[ARG]] : tensor -> tensor // CHECK: %[[SHAPE:.*]] = tensor.cast %[[UNCASTED_SHAPE]] : tensor to tensor<2xindex> // CHECK: %[[BROADCASTED_CONSTANT:.*]] = "mhlo.dynamic_broadcast_in_dim"(%[[CONSTANT]], %[[SHAPE]]) {broadcast_dimensions = dense<> : tensor<0xi64>} : (tensor, tensor<2xindex>) -> tensor // CHECK: return %[[BROADCASTED_CONSTANT]] : tensor %result = "chlo.constant_like"(%arg) { value = 3.2 : f32 } : (tensor) -> tensor return %result : tensor } // CHECK-LABEL: func @conj func @conj(%arg0: tensor<3xcomplex>) -> tensor<3xcomplex> { // CHECK-SAME: ([[INPUT:%.*]]: tensor // CHECK-NEXT: [[R1:%.*]] = "mhlo.real"([[INPUT]]) // CHECK-NEXT: [[R2:%.*]] = "mhlo.imag"([[INPUT]]) // CHECK-NEXT: [[R3:%.*]] = "mhlo.negate"([[R2]]) // CHECK-NEXT: [[R4:%.*]] = "mhlo.complex"([[R1]], [[R3]]) %1 = "chlo.conj"(%arg0) : (tensor<3xcomplex>) -> tensor<3xcomplex> return %1 : tensor<3xcomplex> }