// RUN: mlir-hlo-opt %s -split-input-file -pass-pipeline='func(canonicalize)' | FileCheck %s // ----- // CHECK-LABEL: func @same_type // CHECK-SAME: [[ARG:%[a-zA-Z0-9]+]] func @same_type(%arg: tensor) -> tensor { %0 = "xla_hlo.convert"(%arg) : (tensor) -> tensor // CHECK-NEXT: return [[ARG]] return %0 : tensor } // ----- // CHECK-LABEL: func @int_widening // CHECK-SAME: [[ARG:%[a-zA-Z0-9]+]] func @int_widening(%arg: tensor) -> tensor { // CHECK-NEXT: [[RES:%.+]] = "xla_hlo.convert"([[ARG]]) : (tensor) -> tensor %0 = "xla_hlo.convert"(%arg) : (tensor) -> tensor // CHECK-NEXT: return [[RES]] return %0 : tensor } // ----- // CHECK-LABEL: func @int_narrowing // CHECK-SAME: [[ARG:%[a-zA-Z0-9]+]] func @int_narrowing(%arg: tensor) -> tensor { // CHECK-NEXT: [[RES:%.+]] = "xla_hlo.convert"([[ARG]]) : (tensor) -> tensor %0 = "xla_hlo.convert"(%arg) : (tensor) -> tensor // CHECK-NEXT: return [[RES]] return %0 : tensor } // ----- // CHECK-LABEL: func @float_int // CHECK-SAME: [[ARG:%[a-zA-Z0-9]+]] func @float_int(%arg: tensor) -> tensor { // CHECK-NEXT: [[RES:%.+]] = "xla_hlo.convert"([[ARG]]) : (tensor) -> tensor %0 = "xla_hlo.convert"(%arg) : (tensor) -> tensor // CHECK-NEXT: return [[RES]] return %0 : tensor } // ----- // CHECK-LABEL: func @int_float // CHECK-SAME: [[ARG:%[a-zA-Z0-9]+]] func @int_float(%arg: tensor) -> tensor { // CHECK-NEXT: [[RES:%.+]] = "xla_hlo.convert"([[ARG]]) : (tensor) -> tensor %0 = "xla_hlo.convert"(%arg) : (tensor) -> tensor // CHECK-NEXT: return [[RES]] return %0 : tensor } // ----- // CHECK-LABEL: func @high_rank_tensor // CHECK-SAME: [[ARG:%[a-zA-Z0-9]+]] func @high_rank_tensor(%arg: tensor<2x3xi32>) -> tensor<2x3xf32> { // CHECK-NEXT: [[RES:%.+]] = "xla_hlo.convert"([[ARG]]) : (tensor<2x3xi32>) -> tensor<2x3xf32> %0 = "xla_hlo.convert"(%arg) : (tensor<2x3xi32>) -> tensor<2x3xf32> // CHECK-NEXT: return [[RES]] return %0 : tensor<2x3xf32> } // ----- // CHECK-LABEL: func @const_same_type func @const_same_type() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<42> : tensor %cst = xla_hlo.constant dense<42> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_float_int func @const_float_int() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<42> : tensor %cst = xla_hlo.constant dense<42.0> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_int_float func @const_int_float() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<4.{{0*}}e+00> : tensor %cst = xla_hlo.constant dense<4> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_negative_int_float func @const_negative_int_float() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<-4.{{0*}}e+00> : tensor %cst = xla_hlo.constant dense<-4> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_int_bf16 func @const_int_bf16() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<4.{{0*}}e+00> : tensor %cst = xla_hlo.constant dense<4> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_bf16_int func @const_bf16_int() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<42> : tensor %cst = xla_hlo.constant dense<42.0> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_int_narrowing func @const_int_narrowing() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<42> : tensor %cst = xla_hlo.constant dense<42> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_int_widening func @const_int_widening() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<42> : tensor %cst = xla_hlo.constant dense<42> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_negative_int_widening func @const_negative_int_widening() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<-42> : tensor %cst = xla_hlo.constant dense<-42> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_float_narrowing func @const_float_narrowing() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<4.2{{0*}}e+00> : tensor %cst = xla_hlo.constant dense<4.2> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_f32_bf16 func @const_f32_bf16() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<4.2{{0*}}e+01> : tensor %cst = xla_hlo.constant dense<42.0> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_bf16_f64 func @const_bf16_f64() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<4.187500e+00> : tensor %cst = xla_hlo.constant dense<4.2> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_bf16_int func @const_bf16_int() -> tensor { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<42> : tensor %cst = xla_hlo.constant dense<42.0> : tensor %0 = "xla_hlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_high_rank_tensor func @const_high_rank_tensor() -> tensor<2x3xi32> { // CHECK-NEXT: [[CST:%.+]] = xla_hlo.constant dense<[ // CHECK-SAME: [1, 2, 3], [4, 5, 6] // CHECK-SAME: ]> : tensor<2x3xi32> %cst = xla_hlo.constant dense<[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]> : tensor<2x3xf32> %0 = "xla_hlo.convert"(%cst) : (tensor<2x3xf32>) -> tensor<2x3xi32> // CHECK-NEXT: return [[CST]] return %0 : tensor<2x3xi32> }