diff --git a/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td b/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td --- a/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td +++ b/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), diff --git a/mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir b/mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir --- a/mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir +++ b/mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir @@ -175,6 +175,28 @@ } //===----------------------------------------------------------------------===// +// 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 +}