From 81ebabd5911f2b5c6ae9f3d2fae24bbbb6328ee9 Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Wed, 25 Aug 2021 19:56:57 +0300 Subject: [PATCH] Map llvm.isnan on OpIsNan (#1179) Map llvm.isnan on OpIsNan Signed-off-by: Dmitry Sidorov --- lib/SPIRV/SPIRVWriter.cpp | 6 ++++++ test/transcoding/isnan.ll | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/transcoding/isnan.ll diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index 557b5fef65..64efa819f5 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -2467,6 +2467,7 @@ bool LLVMToSPIRVBase::isKnownIntrinsic(Intrinsic::ID Id) { case Intrinsic::dbg_label: case Intrinsic::trap: case Intrinsic::arithmetic_fence: + case Intrinsic::isnan: return true; default: // Unknown intrinsics' declarations should always be translated @@ -3099,6 +3100,11 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II, } return Op; } + case Intrinsic::isnan: { + SPIRVType *Ty = transType(II->getType()); + SPIRVValue *Op = transValue(II->getArgOperand(0), BB); + return BM->addUnaryInst(OpIsNan, Ty, Op, BB); + } default: if (BM->isUnknownIntrinsicAllowed(II)) return BM->addCallInst( diff --git a/test/transcoding/isnan.ll b/test/transcoding/isnan.ll new file mode 100644 index 0000000000..8c6ef94a2d --- /dev/null +++ b/test/transcoding/isnan.ll @@ -0,0 +1,35 @@ +; RUN: llvm-as %s -o %t.bc +; RUN: llvm-spirv %t.bc -o %t.spv +; RUN: llvm-spirv %t.spv --to-text -o %t.spt +; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV + +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc +; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-OCL +; RUN: llvm-spirv -r %t.spv -o %t.rev.bc --spirv-target-env=SPV-IR +; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-SPV + +; CHECK-SPIRV: IsNan +; CHECK-LLVM-OCL: call spir_func i32 @_Z5isnanf(float 1.200000e+01) +; CHECK-LLVM-SPV: call spir_func i32 @_Z13__spirv_IsNanf(float 1.200000e+01) + +; ModuleID = 'test.bc' +source_filename = "test.cpp" +target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" +target triple = "spir64-unknown-unknown-unknown" + +define spir_kernel void @test() { +entry: + %call = call i1 @llvm.isnan.f32(float 1.200000e+01) + ret void +} + +declare i1 @llvm.isnan.f32(float) + +!llvm.module.flags = !{!0, !1} +!opencl.spir.version = !{!2} +!spirv.Source = !{!3} + +!0 = !{i32 1, !"wchar_size", i32 4} +!1 = !{i32 7, !"frame-pointer", i32 2} +!2 = !{i32 1, i32 2} +!3 = !{i32 4, i32 100000}