Index: mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td =================================================================== --- mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td +++ mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td @@ -20,6 +20,10 @@ Pat<(src SPV_ScalarOrVectorOf:$l, SPV_ScalarOrVectorOf:$r), (tgt $l, $r)>; +class UnaryOpPattern : + Pat<(src type:$input), + (tgt $input)>; + def : BinaryOpPattern; def : BinaryOpPattern; def : BinaryOpPattern; @@ -28,6 +32,10 @@ def : BinaryOpPattern; def : BinaryOpPattern; +def : UnaryOpPattern; +def : UnaryOpPattern; +def : UnaryOpPattern; + // Constant Op // TODO(ravishankarm): Handle lowering other constant types. def : Pat<(ConstantOp:$result $valueAttr), Index: mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir =================================================================== --- mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir +++ mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir @@ -174,6 +174,28 @@ return } +//===----------------------------------------------------------------------===// +// std.fpext +//===----------------------------------------------------------------------===// + +// CHECK-LABEL: @fpext +func @fpext(%arg0 : f32) { + // CHECK: spv.FConvert + %0 = std.fpext %arg0 : f32 to f64 + return +} + +//===----------------------------------------------------------------------===// +// std.fptrunc +//===----------------------------------------------------------------------===// + +// CHECK-LABEL: @fptrunc +func @fptrunc(%arg0 : f64) { + // CHECK: spv.FConvert + %0 = std.fptrunc %arg0 : f64 to f32 + return +} + //===----------------------------------------------------------------------===// // std.select //===----------------------------------------------------------------------===// @@ -185,3 +207,14 @@ %1 = select %0, %arg0, %arg1 : i32 return } + +//===----------------------------------------------------------------------===// +// std.sitofp +//===----------------------------------------------------------------------===// + +// CHECK-LABEL: @sitofp +func @sitofp(%arg0 : i32) { + // CHECK: spv.ConvertSToF + %0 = std.sitofp %arg0 : i32 to f32 + return +}