// 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 = "mhlo.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:%.+]] = "mhlo.convert"([[ARG]]) : (tensor) -> tensor %0 = "mhlo.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:%.+]] = "mhlo.convert"([[ARG]]) : (tensor) -> tensor %0 = "mhlo.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:%.+]] = "mhlo.convert"([[ARG]]) : (tensor) -> tensor %0 = "mhlo.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:%.+]] = "mhlo.convert"([[ARG]]) : (tensor) -> tensor %0 = "mhlo.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:%.+]] = "mhlo.convert"([[ARG]]) : (tensor<2x3xi32>) -> tensor<2x3xf32> %0 = "mhlo.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:%.+]] = mhlo.constant dense<42> : tensor %cst = mhlo.constant dense<42> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<42> : tensor %cst = mhlo.constant dense<42.0> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<4.{{0*}}e+00> : tensor %cst = mhlo.constant dense<4> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<-4.{{0*}}e+00> : tensor %cst = mhlo.constant dense<-4> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<4.{{0*}}e+00> : tensor %cst = mhlo.constant dense<4> : tensor %0 = "mhlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_bool_f32 func @const_bool_f32() -> tensor<2xf32> { // CHECK-NEXT: [[CST:%.+]] = mhlo.constant dense<[0.000000e+00, 1.000000e+00]> : tensor<2xf32> %cst = mhlo.constant dense<[0, 1]> : tensor<2xi1> %0 = "mhlo.convert"(%cst) : (tensor<2xi1>) -> tensor<2xf32> // CHECK-NEXT: return [[CST]] return %0 : tensor<2xf32> } // ----- // CHECK-LABEL: func @const_bf16_int func @const_bf16_int() -> tensor { // CHECK-NEXT: [[CST:%.+]] = mhlo.constant dense<42> : tensor %cst = mhlo.constant dense<42.0> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<42> : tensor %cst = mhlo.constant dense<42> : tensor %0 = "mhlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_bool_widening func @const_bool_widening() -> tensor { // CHECK-NEXT: [[CST:%.+]] = mhlo.constant dense<42> : tensor %cst = mhlo.constant dense<42> : tensor %0 = "mhlo.convert"(%cst) : (tensor) -> tensor // CHECK-NEXT: return [[CST]] return %0 : tensor } // ----- // CHECK-LABEL: func @const_int_widening func @const_int_widening() -> tensor<2xi32> { // CHECK-NEXT: [[CST:%.+]] = mhlo.constant dense<[0, 1]> : tensor<2xi32> %cst = mhlo.constant dense<[0, 1]> : tensor<2xi1> %0 = "mhlo.convert"(%cst) : (tensor<2xi1>) -> tensor<2xi32> // CHECK-NEXT: return [[CST]] return %0 : tensor<2xi32> } // ----- // CHECK-LABEL: func @const_negative_int_widening func @const_negative_int_widening() -> tensor { // CHECK-NEXT: [[CST:%.+]] = mhlo.constant dense<-42> : tensor %cst = mhlo.constant dense<-42> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<4.2{{0*}}e+00> : tensor %cst = mhlo.constant dense<4.2> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<4.2{{0*}}e+01> : tensor %cst = mhlo.constant dense<42.0> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<4.187500e+00> : tensor %cst = mhlo.constant dense<4.2> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<42> : tensor %cst = mhlo.constant dense<42.0> : tensor %0 = "mhlo.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:%.+]] = mhlo.constant dense<[ // CHECK-SAME: [1, 2, 3], [4, 5, 6] // CHECK-SAME: ]> : tensor<2x3xi32> %cst = mhlo.constant dense<[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]> : tensor<2x3xf32> %0 = "mhlo.convert"(%cst) : (tensor<2x3xf32>) -> tensor<2x3xi32> // CHECK-NEXT: return [[CST]] return %0 : tensor<2x3xi32> } // ----- // CHECK-LABEL: func @const_int_complex func @const_int_complex() -> tensor<2xcomplex> { %cst = mhlo.constant dense<[0, 1]> : tensor<2xi1> // CHECK: mhlo.convert %0 = "mhlo.convert"(%cst) : (tensor<2xi1>) -> tensor<2xcomplex> return %0 : tensor<2xcomplex> } // ----- // CHECK-LABEL: func @const_float_complex func @const_float_complex() -> tensor<2xcomplex> { %cst = mhlo.constant dense<[0.0, 1.0]> : tensor<2xf32> // CHECK: mhlo.convert %0 = "mhlo.convert"(%cst) : (tensor<2xf32>) -> tensor<2xcomplex> return %0 : tensor<2xcomplex> } // ----- // CHECK-LABEL: func @const_complex_int func @const_complex_int() -> tensor { %cst = mhlo.constant dense<(0.0, 1.0)> : tensor> // CHECK: mhlo.convert %0 = "mhlo.convert"(%cst) : (tensor>) -> tensor return %0 : tensor } // ----- // CHECK-LABEL: func @const_complex_float func @const_complex_float() -> tensor { %cst = mhlo.constant dense<(0.0, 1.0)> : tensor> // CHECK: mhlo.convert %0 = "mhlo.convert"(%cst) : (tensor>) -> tensor return %0 : tensor } // ----- // CHECK-LABEL: func @const_complex_complex func @const_complex_complex() -> tensor> { %cst = mhlo.constant dense<(0.0, 1.0)> : tensor> // CHECK: mhlo.convert %0 = "mhlo.convert"(%cst) : (tensor>) -> tensor> return %0 : tensor> }