Skip to content

Commit

Permalink
Map llvm.isnan on OpIsNan (KhronosGroup#1179)
Browse files Browse the repository at this point in the history
Map llvm.isnan on OpIsNan

Signed-off-by: Dmitry Sidorov <[email protected]>
  • Loading branch information
MrSidims authored Aug 25, 2021
1 parent f572503 commit 81ebabd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
35 changes: 35 additions & 0 deletions test/transcoding/isnan.ll
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 81ebabd

Please sign in to comment.