diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td --- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td +++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td @@ -1544,6 +1544,26 @@ } //===----------------------------------------------------------------------===// +// FPToSIOp +//===----------------------------------------------------------------------===// + +def FPToSIOp : CastOp<"fptosi">, Arguments<(ins AnyType:$in)> { + let summary = "cast from floating-point type to integer type"; + let description = [{ + Cast from a value interpreted as floating-point to the nearest (rounding + towards zero) signed integer value. + }]; + + let extraClassDeclaration = [{ + /// Return true if `a` and `b` are valid operand and result pairs for + /// the operation. + static bool areCastCompatible(Type a, Type b); + }]; + + let hasFolder = 0; +} + +//===----------------------------------------------------------------------===// // FPTruncOp //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp --- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp +++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp @@ -1662,6 +1662,14 @@ } //===----------------------------------------------------------------------===// +// FPToSIOp +//===----------------------------------------------------------------------===// + +bool FPToSIOp::areCastCompatible(Type a, Type b) { + return a.isa() && b.isSignlessInteger(); +} + +//===----------------------------------------------------------------------===// // FPTruncOp //===----------------------------------------------------------------------===// diff --git a/mlir/test/IR/core-ops.mlir b/mlir/test/IR/core-ops.mlir --- a/mlir/test/IR/core-ops.mlir +++ b/mlir/test/IR/core-ops.mlir @@ -545,6 +545,18 @@ // CHECK: %{{[0-9]+}} = sin %arg0 : tensor<4x4x?xf32> %149 = sin %t : tensor<4x4x?xf32> + // CHECK: = fptosi {{.*}} : f32 to i32 + %159 = fptosi %f : f32 to i32 + + // CHECK: = fptosi {{.*}} : f32 to i64 + %160 = fptosi %f : f32 to i64 + + // CHECK: = fptosi {{.*}} : f16 to i32 + %161 = fptosi %half : f16 to i32 + + // CHECK: = fptosi {{.*}} : f16 to i64 + %162 = fptosi %half : f16 to i64 + return }