[mlir][spirv] Add lowering for std.fpext, std.fptrunc, std.sitofp.

Differential Revision: https://reviews.llvm.org/D72137
This commit is contained in:
Denis Khalikov 2020-01-07 22:11:59 -05:00 committed by Lei Zhang
parent dab2921f77
commit eac01f63a6
2 changed files with 41 additions and 0 deletions

View File

@ -20,6 +20,10 @@ class BinaryOpPattern<Type type, Op src, Op tgt> :
Pat<(src SPV_ScalarOrVectorOf<type>:$l, SPV_ScalarOrVectorOf<type>:$r),
(tgt $l, $r)>;
class UnaryOpPattern<Type type, Op src, Op tgt> :
Pat<(src type:$input),
(tgt $input)>;
def : BinaryOpPattern<SPV_Bool, AndOp, SPV_LogicalAndOp>;
def : BinaryOpPattern<SPV_Bool, OrOp, SPV_LogicalOrOp>;
def : BinaryOpPattern<SPV_Integer, AndOp, SPV_BitwiseAndOp>;
@ -36,6 +40,10 @@ def : BinaryOpPattern<SPV_Float, MulFOp, SPV_FMulOp>;
def : BinaryOpPattern<SPV_Float, RemFOp, SPV_FRemOp>;
def : BinaryOpPattern<SPV_Float, SubFOp, SPV_FSubOp>;
def : UnaryOpPattern<SPV_Integer, SIToFPOp, SPV_ConvertSToFOp>;
def : UnaryOpPattern<SPV_Float, FPExtOp, SPV_FConvertOp>;
def : UnaryOpPattern<SPV_Float, FPTruncOp, SPV_FConvertOp>;
// Constant Op
// TODO(ravishankarm): Handle lowering other constant types.
def : Pat<(ConstantOp:$result $valueAttr),

View File

@ -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
}