1// RUN: mlir-opt -split-input-file -convert-complex-to-spirv %s | FileCheck %s 2 3func.func @create_complex(%real: f32, %imag: f32) -> complex<f32> { 4 %0 = complex.create %real, %imag : complex<f32> 5 return %0 : complex<f32> 6} 7 8// CHECK-LABEL: func.func @create_complex 9// CHECK-SAME: (%[[RE:.+]]: f32, %[[IM:.+]]: f32) 10// CHECK: %[[CC:.+]] = spirv.CompositeConstruct %[[RE]], %[[IM]] : (f32, f32) -> vector<2xf32> 11// CHECK: %[[CAST:.+]] = builtin.unrealized_conversion_cast %[[CC]] : vector<2xf32> to complex<f32> 12// CHECK: return %[[CAST]] : complex<f32> 13 14 15// ----- 16 17func.func @real_number(%arg: complex<f32>) -> f32 { 18 %real = complex.re %arg : complex<f32> 19 return %real : f32 20} 21 22// CHECK-LABEL: func.func @real_number 23// CHECK-SAME: %[[ARG:.+]]: complex<f32> 24// CHECK: %[[CAST:.+]] = builtin.unrealized_conversion_cast %[[ARG]] : complex<f32> to vector<2xf32> 25// CHECK: %[[RE:.+]] = spirv.CompositeExtract %[[CAST]][0 : i32] : vector<2xf32> 26// CHECK: return %[[RE]] : f32 27 28// ----- 29 30func.func @imaginary_number(%arg: complex<f32>) -> f32 { 31 %imaginary = complex.im %arg : complex<f32> 32 return %imaginary: f32 33} 34 35// CHECK-LABEL: func.func @imaginary_number 36// CHECK-SAME: %[[ARG:.+]]: complex<f32> 37// CHECK: %[[CAST:.+]] = builtin.unrealized_conversion_cast %[[ARG]] : complex<f32> to vector<2xf32> 38// CHECK: %[[IM:.+]] = spirv.CompositeExtract %[[CAST]][1 : i32] : vector<2xf32> 39// CHECK: return %[[IM]] : f32 40 41// ----- 42 43func.func @complex_const() -> complex<f32> { 44 %cst = complex.constant [0x7FC00000 : f32, 0.000000e+00 : f32] : complex<f32> 45 return %cst : complex<f32> 46} 47 48// CHECK-LABEL: func.func @complex_const() 49// CHECK: spirv.Constant dense<[0x7FC00000, 0.000000e+00]> : vector<2xf32> 50