From 7c3439b74c2b31fccd03876a0e543d275fd37f81 Mon Sep 17 00:00:00 2001 From: Jeff Niu Date: Fri, 14 Oct 2022 09:00:01 -0700 Subject: [PATCH] [mlir][llvm] Add `llvm.intr.is.fpclass` This intrinsic allows testing for inf, nan, etc. on floating point values. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D135969 --- mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td | 5 +++++ mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td index 75e1050..fd748f7 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td @@ -44,6 +44,11 @@ def LLVM_AbsOp : LLVM_OneResultIntrOp<"abs", [], [0], [Pure]> { let arguments = (ins LLVM_Type:$in, I1:$is_int_min_poison); } +def LLVM_IsFPClass : LLVM_OneResultIntrOp<"is.fpclass", [], [0], + [NoSideEffect]> { + let arguments = (ins LLVM_Type:$in, I32:$bit); +} + def LLVM_CopySignOp : LLVM_BinarySameArgsIntrinsicOp<"copysign">; def LLVM_CosOp : LLVM_UnaryIntrinsicOp<"cos">; def LLVM_ExpOp : LLVM_UnaryIntrinsicOp<"exp">; diff --git a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir index a3b894d..78fc159 100644 --- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir +++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir @@ -18,6 +18,14 @@ llvm.func @intrinsics(%arg0: f32, %arg1: f32, %arg2: vector<8xf32>, %arg3: !llvm llvm.return } +// CHECK-LABEL: @fpclass_test +llvm.func @fpclass_test(%arg0: f32) -> i1 { + %checkNan = llvm.mlir.constant(0 : i32) : i32 + // CHECK: call i1 @llvm.is.fpclass + %0 = "llvm.intr.is.fpclass"(%arg0, %checkNan) : (f32, i32) -> i1 + llvm.return %0 : i1 +} + // CHECK-LABEL: @exp_test llvm.func @exp_test(%arg0: f32, %arg1: vector<8xf32>) { // CHECK: call float @llvm.exp.f32 -- 2.7.4