Skip to content

Commit 739793e

Browse files
MrSidimsvmaksimo
authored andcommitted
Map llvm.isnan on OpIsNan
Signed-off-by: Dmitry Sidorov <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@81ebabd
1 parent 8c3583c commit 739793e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,6 +2484,7 @@ bool LLVMToSPIRVBase::isKnownIntrinsic(Intrinsic::ID Id) {
24842484
case Intrinsic::dbg_label:
24852485
case Intrinsic::trap:
24862486
case Intrinsic::arithmetic_fence:
2487+
case Intrinsic::isnan:
24872488
return true;
24882489
default:
24892490
// Unknown intrinsics' declarations should always be translated
@@ -3118,6 +3119,11 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
31183119
}
31193120
return Op;
31203121
}
3122+
case Intrinsic::isnan: {
3123+
SPIRVType *Ty = transType(II->getType());
3124+
SPIRVValue *Op = transValue(II->getArgOperand(0), BB);
3125+
return BM->addUnaryInst(OpIsNan, Ty, Op, BB);
3126+
}
31213127
default:
31223128
if (BM->isUnknownIntrinsicAllowed(II))
31233129
return BM->addCallInst(

llvm-spirv/test/transcoding/isnan.ll

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv %t.spv --to-text -o %t.spt
4+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
5+
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-OCL
8+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc --spirv-target-env=SPV-IR
9+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM-SPV
10+
11+
; CHECK-SPIRV: IsNan
12+
; CHECK-LLVM-OCL: call spir_func i32 @_Z5isnanf(float 1.200000e+01)
13+
; CHECK-LLVM-SPV: call spir_func i32 @_Z13__spirv_IsNanf(float 1.200000e+01)
14+
15+
; ModuleID = 'test.bc'
16+
source_filename = "test.cpp"
17+
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"
18+
target triple = "spir64-unknown-unknown-unknown"
19+
20+
define spir_kernel void @test() {
21+
entry:
22+
%call = call i1 @llvm.isnan.f32(float 1.200000e+01)
23+
ret void
24+
}
25+
26+
declare i1 @llvm.isnan.f32(float)
27+
28+
!llvm.module.flags = !{!0, !1}
29+
!opencl.spir.version = !{!2}
30+
!spirv.Source = !{!3}
31+
32+
!0 = !{i32 1, !"wchar_size", i32 4}
33+
!1 = !{i32 7, !"frame-pointer", i32 2}
34+
!2 = !{i32 1, i32 2}
35+
!3 = !{i32 4, i32 100000}

0 commit comments

Comments
 (0)