// RUN: mlir-hlo-opt --mhlo-test-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 }