[spirv] Add lowering for std.fdiv, std.frem, std.fsub

Closes tensorflow/mlir#313

COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/313 from denis0x0D:sandbox/lowering_std_farith 41715070a74d13bfa9401957478978c1bb8006c0
PiperOrigin-RevId: 285023586
This commit is contained in:
Denis Khalikov 2019-12-11 11:17:03 -08:00 committed by A. Unique TensorFlower
parent 508d4e672e
commit d968f9696d
2 changed files with 31 additions and 0 deletions

View File

@ -21,7 +21,10 @@ class BinaryOpPattern<Op src, Op tgt> :
(tgt $l, $r)>;
def : BinaryOpPattern<AddFOp, SPV_FAddOp>;
def : BinaryOpPattern<DivFOp, SPV_FDivOp>;
def : BinaryOpPattern<MulFOp, SPV_FMulOp>;
def : BinaryOpPattern<RemFOp, SPV_FRemOp>;
def : BinaryOpPattern<SubFOp, SPV_FSubOp>;
// Constant Op
// TODO(ravishankarm): Handle lowering other constant types.

View File

@ -13,6 +13,20 @@ func @add_sub(%arg0 : i32, %arg1 : i32) {
return
}
// CHECK-LABEL: @fadd_scalar
func @fadd_scalar(%arg: f32) -> f32 {
// CHECK: spv.FAdd
%0 = addf %arg, %arg : f32
return %0 : f32
}
// CHECK-LABEL: @fdiv_scalar
func @fdiv_scalar(%arg: f32) -> f32 {
// CHECK: spv.FDiv
%0 = divf %arg, %arg : f32
return %0 : f32
}
// CHECK-LABEL: @fmul_scalar
func @fmul_scalar(%arg: f32) -> f32 {
// CHECK: spv.FMul
@ -57,6 +71,20 @@ func @fmul_tensor(%arg: tensor<4xf32>) -> tensor<4xf32> {
return %0 : tensor<4xf32>
}
// CHECK-LABEL: @frem_scalar
func @frem_scalar(%arg: f32) -> f32 {
// CHECK: spv.FRem
%0 = remf %arg, %arg : f32
return %0 : f32
}
// CHECK-LABEL: @fsub_scalar
func @fsub_scalar(%arg: f32) -> f32 {
// CHECK: spv.FSub
%0 = subf %arg, %arg : f32
return %0 : f32
}
// CHECK-LABEL: @div_rem
func @div_rem(%arg0 : i32, %arg1 : i32) {
// CHECK: spv.SDiv