From eac01f63a6c99d6ffd03b7b7c88cf8e28d364e5c Mon Sep 17 00:00:00 2001 From: Denis Khalikov Date: Tue, 7 Jan 2020 22:11:59 -0500 Subject: [PATCH] [mlir][spirv] Add lowering for std.fpext, std.fptrunc, std.sitofp. Differential Revision: https://reviews.llvm.org/D72137 --- .../StandardToSPIRV/StandardToSPIRV.td | 8 +++++ .../StandardToSPIRV/std-to-spirv.mlir | 33 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td b/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td index 7ce895ab0a52..77f9305b4a93 100644 --- a/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td +++ b/mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.td @@ -20,6 +20,10 @@ class BinaryOpPattern : 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; @@ -36,6 +40,10 @@ def : BinaryOpPattern; 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 index 2c5b347286af..30b4c4a9324e 100644 --- a/mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir +++ b/mlir/test/Conversion/StandardToSPIRV/std-to-spirv.mlir @@ -245,6 +245,28 @@ func @logical_vector(%arg0 : vector<4xi1>, %arg1 : vector<4xi1>) { 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 //===----------------------------------------------------------------------===// @@ -256,3 +278,14 @@ func @select(%arg0 : i32, %arg1 : i32) { %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 +}