[PATCH] D79373: [mlir] Add FPToSIOp to Standard dialect.
Han-Chung Wang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 4 16:41:46 PDT 2020
hanchung created this revision.
hanchung added reviewers: rriddle, mehdi_amini, antiagainst, mravishankar.
Herald added subscribers: llvm-commits, Kayjukh, frgossen, grosul1, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, shauheen, jpienaar.
Herald added a project: LLVM.
hanchung added a child revision: D79374: [mlir][StandardToSPIRV] Add support for lowering FPToSIOp to SPIR-V..
Cast from a value interpreted as floating-point to the corresponding signed
integer value. Similar to an element-wise `static_cast` in C++, performs an
element-wise conversion operation.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D79373
Files:
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/test/IR/core-ops.mlir
Index: mlir/test/IR/core-ops.mlir
===================================================================
--- mlir/test/IR/core-ops.mlir
+++ mlir/test/IR/core-ops.mlir
@@ -527,6 +527,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
}
Index: mlir/lib/Dialect/StandardOps/IR/Ops.cpp
===================================================================
--- mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -1611,6 +1611,14 @@
return false;
}
+//===----------------------------------------------------------------------===//
+// FPToSIOp
+//===----------------------------------------------------------------------===//
+
+bool FPToSIOp::areCastCompatible(Type a, Type b) {
+ return a.isa<FloatType>() && b.isSignlessInteger();
+}
+
//===----------------------------------------------------------------------===//
// FPTruncOp
//===----------------------------------------------------------------------===//
Index: mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
===================================================================
--- mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
+++ mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
@@ -1475,6 +1475,27 @@
let hasFolder = 0;
}
+//===----------------------------------------------------------------------===//
+// 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 corresponding
+ signed integer value. Similar to an element-wise `static_cast` in C++,
+ performs an element-wise conversion operation.
+ }];
+
+ 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
//===----------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79373.261957.patch
Type: text/x-patch
Size: 2548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200504/0a980673/attachment-0001.bin>
More information about the llvm-commits
mailing list